forked from sth1997/GraphSet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
75 lines (64 loc) · 2.24 KB
/
analyze.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
import json
if 0: # 输入格式:@warp_id,time_begin,time_end
with open('timing.txt', 'r') as f:
lines = f.readlines()
records = []
for line in lines:
if line.startswith('@'):
records.append(line[1:].strip().split(','))
warp_ids = set([int(r[0]) for r in records])
print("number of warps: %d" % len(warp_ids))
'''
time_points = []
for r in records:
time_points.append(int(r[1]))
time_points.append(int(r[2]))
time_points = sorted(time_points)
unique_time_points = [time_points[0]]
for i in range(1, len(time_points)):
if time_points[i] != time_points[i - 1]:
unique_time_points.append(time_points[i])
max_timestamp = unique_time_points[-1]
nr_intervals = 10000
interval_len = (max_timestamp + nr_intervals - 1) // nr_intervals
active_warps_count = [0.0] * nr_intervals
for r in records:
t1, t2 = int(r[1]), int(r[2])
left = t1 // interval_len
right = (t2 + interval_len - 1) // interval_len
for i in range(left, right):
begin = interval_len * i
end = begin + interval_len
active_warps_count[i] += (min(end, t2) - max(begin, t1)) / interval_len
'''
total_time_costs = {}
num_tasks = {}
time_costs = []
for r in records:
warp_id, t1, t2 = int(r[0]), int(r[1]), int(r[2])
time_costs.append(t2 - t1)
#
tot = total_time_costs.get(warp_id, 0)
tot += t2 - t1
total_time_costs[warp_id] = tot
#
num_tasks[warp_id] = num_tasks.get(warp_id, 0) + 1
with open('time_costs.json', 'w') as f:
json.dump({'task_time': time_costs, 'total_time': total_time_costs, 'num_tasks': num_tasks}, f)
if __name__ == '__main__':
# 输入格式:@smid:end_time
with open('timing.txt', 'r') as f:
lines = f.readlines()
data = []
timestamps = []
for line in lines:
if not line.startswith('@'):
continue
r = line[1:].strip().split(':')
data.append(tuple(map(int, r)))
timestamps.append(int(r[1]))
min_time = min(timestamps)
timestamps = [t - min_time for t in timestamps]
print(timestamps)
from IPython import embed
#embed()