-
Notifications
You must be signed in to change notification settings - Fork 0
/
uboo_zone.py
executable file
·116 lines (77 loc) · 2.65 KB
/
uboo_zone.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
# (C) [email protected]
import os
import sys
import re
from stat import *
from time import time, sleep, clock
from optparse import OptionParser, Option
from common import *
__cmdParser__ = OptionParser()
__cmdParser__.add_option("-i", metavar="FILE", \
dest="src", type = "string", \
help="input file")
__cmdParser__.add_option("-o", metavar="OUTNAME", \
dest="outname", type = "string", \
help="base name for output files")
__cmdParser__.add_option("-n", metavar="FNAME", \
dest="fname", type = "string", \
help="filename to watch")
__cmdParser__.add_option("-m", metavar="SECONDS", \
dest="min_pause", type = "int", default=0, \
help="skip delays between I/O below this value")
(__cmdLineOpts__, __cmdLineArgs__) = __cmdParser__.parse_args()
if not __cmdLineOpts__.src:
print """Please specify an input file (created using appdump)."""
sys.exit()
appdump_file = appdump_file(__cmdLineOpts__.src)
if not __cmdLineOpts__.fname:
print
print """Please specify a comma-separated list of file names to replay:"""
print
sys.exit()
if not __cmdLineOpts__.outname:
__cmdLineOpts__.outname = os.path.basename(__cmdLineOpts__.fname).split('.', 1)[0]
fp_r = open("%s_read_telemetry.txt" % __cmdLineOpts__.outname, "w")
fp_w = open("%s_write_telemetry.txt" % __cmdLineOpts__.outname, "w")
fds = []
pos = 0
r_time_old = None
w_time_old = None
for op in appdump_file.walk_ops():
if op.optype != OP_TYPE_OPEN and not op.fd in fds:
continue
if op.optype == OP_TYPE_OPEN:
if op.fname == __cmdLineOpts__.fname:
fds.append(op.retcode)
else:
continue
elif op.optype in [ OP_TYPE_DUP, OP_TYPE_DUP2 ]:
fds.append(op.retcode)
elif op.optype == OP_TYPE_LSEEK:
if op.whence == 0: pos = op.block
elif op.whence == 1: pos = pos + op.block
elif op.whence == 2: raise "Not_Implemented"
elif op.optype == OP_TYPE_CLOSE:
del fds[fds.index(op.fd)]
elif op.optype == OP_TYPE_READ:
if not r_time_old: delay = 0
else: delay = (op.tstamp - r_time_old) * 1000
print "read %d bytes at position %d after %d msecs" % (op.size, pos, delay)
fp_r.write("%d %d %d\n" % (pos, op.size, delay))
pos += op.retcode
r_time_old = op.time_finished()
elif op.optype == OP_TYPE_WRITE:
if not w_time_old: delay = 0
else: delay = (op.tstamp - w_time_old) * 1000
delay = 5000
print "write %d bytes at position %d after %d msecs" % (op.size, pos, delay)
fp_w.write("%d %d %d\n" % (pos, op.size, delay))
pos += op.retcode
w_time_old = op.time_finished()
else:
print "Not implemented", op
raise "Not_Implemented"
fp_r.close()
fp_w.close()
#print """iozone usage example: iozone -r %s -w %s -w /tmp/sasa"""