-
Notifications
You must be signed in to change notification settings - Fork 4
/
process_tshark.py
executable file
·71 lines (59 loc) · 2.06 KB
/
process_tshark.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
#!/usr/bin/env python3
# Script that creates the .dat file for trace-plot.tex
# Reads the output of `tshark -n -l -q -T fields -e frame.time_relative -e frame.len -e redis.value` as input
import sys
def hour(sec):
return float(sec) / 3600
def minute(sec):
return float(sec) / 60
timeres = 20
general_count = 0
write_count = 0
read_count = 0
redis_count = 0
cluster_count = 0
exists_count = 0
current_time = 0
last_print = 0
timestamp = 0.0
length = 0
time_bracket = 0
print("sec\tminute\thour\tgeneral\twrite\tread\tredis\tcluster\texists")
for line in sys.stdin:
try:
cols = line.split('\t')
if len(cols) < 3:
continue
timestamp = float(cols[0])
length = int(cols[1])
redis = cols[2]
if redis.strip() != '':
if redis.startswith('SET'):
write_count += length
elif redis.startswith('AA') or redis.startswith('GET'):
read_count += length
elif redis.startswith('cluster'):
cluster_count += length
elif redis.startswith('EXISTS') or redis == '1' or redis == '0':
exists_count += length
else:
redis_count += length
else:
general_count += length
time_bracket = int(timestamp // timeres) * timeres
if time_bracket > current_time:
for i in range(last_print + timeres, time_bracket - timeres, timeres):
print("{}\t{}\t{}\t0\t0\t0\t0\t0\t0".format(i, minute(i), hour(i)))
last_print = i
current_time = i + timeres
print("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(current_time, minute(current_time), hour(current_time), general_count, write_count, read_count, redis_count, cluster_count, exists_count))
last_print = current_time
current_time = time_bracket
general_count = 0
write_count = 0
read_count = 0
redis_count = 0
cluster_count = 0
exists_count = 0
except:
pass