Updates qlog_plot to support frames attribute plotting
@@ -5,9 +5,23 @@ import matplotlib.pyplot as plt
if len(sys.argv) < 3:
print('Usage: %s trace_file metric_reference..' % sys.argv[0])
- print('Example: %s server.qlog.json CWIN_UPDATE.cwin[cc_path],BYTES_IN_TRANSIT_UPDATE.bytes_in_transit[path]' % sys.argv[0])
+ print('Example: %s server.qlog.json metrics_updated.congestion_window[cc_path] metrics_updated.bytes_in_flight[cc_path] packet_received.header.packet_number[header:dcid]' % sys.argv[0])
exit(-1)
+def deep_get(d, keys):
+ for i, k in enumerate(keys):
+ if type(d) is list:
+ for e in d:
+ yield from deep_get(e, keys[i:])
+ return
+ else:
+ d = d.get(k, {})
+
+ if type(d) is dict and not len(d):
+ yield None
+ else:
+ yield d
+
trace_filename = sys.argv[1]
with open(trace_filename) as f:
@@ -21,26 +35,35 @@ for e in t['events']:
metrics_data = []
for metric_ref in sys.argv[2:]:
- metric_type, attribute = metric_ref.split('.')
+ metric_type, *attributes = metric_ref.split('.')
+
context = None
- if '[' in attribute and ']' in attribute:
- attribute, context = attribute.split('[')
+ if '[' in attributes[-1] and ']' in attributes[-1]:
+ attributes[-1], context = attributes[-1].split('[')
context = context[:-1]
+ if ':' in context:
+ context = context.split(':')
+ else:
+ context = [context]
X = dict()
Y = dict()
for timestamp, _, ev_type, _, ctx, data in t['events']:
- if ev_type == metric_type and attribute in data:
- k = data.get(context, ctx.get(context))
+ values = deep_get(data, attributes)
+ for value in values:
+ if ev_type == metric_type and value is not None:
+ k = next(deep_get(data, context))
+ if k is None:
+ k = next(deep_get(ctx, context))
x = X.get(k, [])
y = Y.get(k, [])
x.append(timestamp/(1000.0 if t.get('configuration', {'time_units': 'us'})['time_units'] == 'us' else 1))
- y.append(data[attribute])
+ y.append(int(value)) # Some qlog integers are encoded as strings
X[k] = x
Y[k] = y
for (k, x) in X.items():
- metrics_data.append((x, Y[k], '{}.{}[{}={}]'.format(metric_type, attribute, context, k)))
+ metrics_data.append((x, Y[k], '{}.{}[{}={}]'.format(metric_type, '.'.join(attributes), '.'.join(context), k)))
n_sub = len(metrics_data)
fig, axes = plt.subplots(n_sub, 1, sharex=True, sharey=True)
