-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathYCSBResultParser.py
63 lines (56 loc) · 1.98 KB
/
YCSBResultParser.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import re
from collections import namedtuple
import hashlib
def parse(s):
pattern = '\[Thread-(.*)\].*(UPDATE|READ).*key=(.*),\svalue=(Good|Mismatched)*(.*),\sst=(.*),\sen=(.*)'
m = re.match(pattern, s)
if m:
threadID, op, key, readStatus, value, st, en = m.groups()
threadID, st, en = int(threadID), int(st), int(en)
isRead = op == 'READ'
IsGoodRead = readStatus == 'Good'
value = hashlib.md5(value).hexdigest()
return threadID, isRead, key, value, IsGoodRead, st, en
else:
return None
def main(filename):
Read = namedtuple("Read", ["Value", "Timestamp", "IsGood", "ThreadID"])
Write = namedtuple("Write" , ["Value", "Timestamp", "ThreadID"])
with open(filename) as f:
content = f.readlines()
reads, writes = {}, {}
for line in content:
parsed = parse(line)
if parsed:
threadID, isRead, key, value, IsGoodRead, st, en = parse(line)
if isRead:
if key not in reads:
reads[key] = []
reads[key].append( Read(value, st, IsGoodRead, threadID) )
else:
if key not in writes:
writes[key] = []
writes[key].append( Write(value, st, threadID) )
else:
print "ERROR parsing: %s" % line
return 1
reads = {k : sorted(reads[k], key=lambda x: x.Timestamp) for k in reads}
writes = {k : sorted(writes[k], key=lambda x: x.Timestamp) for k in writes}
for key in reads:
readList, writeList = reads[key], writes.get(key, [])
writeMap = {w.Value: w for w in writeList}
lastestResponses = {}
staleRead = 0
for read in readList:
write = writeMap.get(read.Value, None)
latestWrite = lastestResponses.get(read.ThreadID, None)
if (latestWrite and write
and write.Timestamp < latestWrite.Timestamp):
staleRead += 1
else:
lastestResponses[read.ThreadID] = write
print "staleRead=%s/%s, totalWrite=%s" % (staleRead, len(readList), len(writeList))
if __name__ == '__main__':
filename = sys.argv[1]
main(filename)