Repository navigation
Expand file tree
/
Copy pathplot_length_cdf.py
More file actions
executable file
·118 lines (101 loc) · 3.18 KB
/
Copy pathplot_length_cdf.py
File metadata and controls
executable file
·118 lines (101 loc) · 3.18 KB
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
117
118
#!/usr/bin/python3
# Copyright (c) 2019-2020 Homa Developers
# SPDX-License-Identifier: BSD-1-Clause
# This script generates a plot showing the CDF of message lengths,
# gathered from one or more experiment runs.
#
# Usage: plot_length_dist.py name pattern name pattern ...
#
# Each "name" argument gives the name a workload, which will appear in the
# graph keys. Each "pattern" argument gives a glob string (such as
# ("logs/w1/loaded*.txt") describine one or more data files that measure
# the distribution.
import glob
import matplotlib.pyplot as plt
import numpy as np
import os
import string
import sys
# Keys are message lengths, values are number of messages of that length.
counts = {}
def read_rtts(file, column):
"""
Read file and add its data to the counts array. The "column" argument
indicates which argument of each line contains the message length.
"""
global counts
print("Reading %s" % file)
f = open(file, "r")
for line in f:
stripped = line.strip()
if stripped[0] == '#':
continue
words = stripped.split()
if (len(words) < (column+1)):
print("Line too short (no column %d): '%s'" % (line, column))
continue
size = int(words[column])
if size in counts:
counts[size] += 1
else:
counts[size] = 1
f.close()
if (len(sys.argv) < 3) or not (len(sys.argv) & 1):
print("Usage: %s name pattern name pattern ..." % (sys.argv[0]))
exit(1)
workloads = []
for i in range(1, len(sys.argv), 2):
info = {}
info["name"] = sys.argv[i]
pattern = sys.argv[i+1]
counts = {}
got_data = False
for f in glob.glob(pattern):
read_rtts(f, 0)
got_data = True
if not got_data:
print("Couldn't find any files corresponding to '%s'" % (pattern))
continue
info["total_msgs"] = 0.0
info["total_bytes"] = 0.0
for length in counts:
info["total_msgs"] += counts[length]
info["total_bytes"] += length*counts[length]
lengths = sorted(counts.keys())
messages = 0
bytes = 0
info["x"] = []
info["cum_msgs"] = []
info["cum_bytes"] = []
for l in lengths:
info["x"].append(l)
info["cum_msgs"].append(messages)
info["cum_bytes"].append(bytes)
messages += counts[l]/info["total_msgs"]
bytes += (l * counts[l])/info["total_bytes"]
info["x"].append(l)
info["cum_msgs"].append(messages)
info["cum_bytes"].append(bytes)
# print("Length %d, CF messages %.2f, CF bytes %.2f" % (
# l, messages, bytes))
workloads.append(info)
plt.subplot(211)
plt.axis([10, 1500000, 0, 1.0])
plt.xscale("log")
plt.xlabel("Message Length")
plt.ylabel("Cum. Frac. Messages")
plt.grid(which="major", axis="both")
for w in workloads:
plt.plot(w["x"], w["cum_msgs"], label=w["name"])
plt.legend()
plt.subplot(212)
plt.axis([10, 1500000, 0, 1.0])
plt.xscale("log")
plt.xlabel("Message Length")
plt.ylabel("Cum. Frac. Bytes")
plt.grid(which="major", axis="both")
for w in workloads:
print("Plotting workload %s" % (w["name"]))
plt.plot(w["x"], w["cum_bytes"], label=w["name"])
plt.legend()
plt.savefig('length.pdf')