forked from asciipip/TopOSM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
27 lines (23 loc) · 869 Bytes
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
import lockfile
import os.path
import pickle
class StatsManager:
lock = lockfile.FileLock('stats')
def __init__(self):
with self.lock:
if not os.path.isfile('stats'):
with open('stats', 'w') as f:
pickle.dump({}, f)
def recordRender(self, zoom, totalTime, layerTimes):
with self.lock:
with open('stats', 'r') as f:
stats = pickle.load(f)
(c, t) = stats.setdefault(zoom, {}).setdefault('total', (0, 0))
stats[zoom]['total'] = (c + 1, t + totalTime)
for layer in layerTimes:
(c, t) = stats[zoom].setdefault(layer, (0, 0))
stats[zoom][layer] = (c + 1, t + layerTimes[layer])
with open('stats', 'w') as f:
pickle.dump(stats, f)
stats = StatsManager()