Skip to content

Commit

Permalink
WIP net graph
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Oct 18, 2024
1 parent 71be44d commit e402232
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
11 changes: 9 additions & 2 deletions runners/s3-benchrunner-rust/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from graph import PerfTimer
import graph.allspans
import graph.http

PARSER = argparse.ArgumentParser(description="Graph a benchmark run")

Expand Down Expand Up @@ -32,8 +33,14 @@
with open(args.TRACE_JSON) as f:
traces_data = json.load(f)

with PerfTimer('Graph all spans'):
fig = graph.allspans.draw(traces_data)
# clean data (simplify attributes, etc)
graph.clean_traces_data(traces_data)

# with PerfTimer('Graph all spans'):
# fig = graph.allspans.draw(traces_data)

with PerfTimer("Graph HTTP requests"):
fig = graph.http.draw(traces_data)

html_path = Path(args.TRACE_JSON).with_suffix('.html')
with PerfTimer(f'Write {html_path}'):
Expand Down
44 changes: 44 additions & 0 deletions runners/s3-benchrunner-rust/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,47 @@ def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
end = time.perf_counter()
print(f"{self.name}: {end - self.start:.3f} sec")


def clean_traces_data(data):
_simplify_attributes_recursive(data)


# Recurse through contents of json data, replacing all "attributes" lists with simple dicts
def _simplify_attributes_recursive(data):
if isinstance(data, dict):
for (k, v) in data.items():
if k == 'attributes' and type(v) == list:
data[k] = _simplify_attributes(v)
else:
_simplify_attributes_recursive(v)
elif isinstance(data, list):
for i in data:
_simplify_attributes_recursive(i)


# Transform attributes from like:
# [
# {"key": "code.namespace", "value": {"stringValue": "s3_benchrunner_rust::transfer_manager"}},
# {"key": "code.lineno", "value": {"intValue": 136}}
# ]
# To like:
# {
# "code.namespace": "s3_benchrunner_rust::transfer_manager",
# "code.lineno": 136,
# }
def _simplify_attributes(attributes_list):
simple_dict = {}
for attr in attributes_list:
key = attr['key']
# extract actual value, ignoring value's key which looks like "intValue"
value = next(iter(attr['value'].values()))

# trim down long filepaths by omitting everything before "src/"
if key == 'code.filepath':
if (src_idx := value.find("src/")) > 0:
value = value[src_idx:]

simple_dict[key] = value

return simple_dict
30 changes: 0 additions & 30 deletions runners/s3-benchrunner-rust/graph/allspans.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ def draw(data):
for scope_span in resource_span['scopeSpans']:
spans.extend(scope_span['spans'])

# simplify attributes of each span to be simple dict
for span in spans:
span['attributes'] = _simplify_attributes(span['attributes'])

# sort spans according to parent-child hierarchy
spans = _sort_spans_by_hierarchy(spans)

Expand Down Expand Up @@ -132,29 +128,3 @@ def _sort_spans_by_hierarchy(spans):

return sorted_spans


# Transform attributes from like:
# [
# {"key": "code.namespace", "value": {"stringValue": "s3_benchrunner_rust::transfer_manager"}},
# {"key": "code.lineno", "value": {"intValue": 136}}
# ]
# To like:
# {
# "code.namespace": "s3_benchrunner_rust::transfer_manager",
# "code.lineno": 136,
# }
def _simplify_attributes(attributes_list):
simple_dict = {}
for attr in attributes_list:
key = attr['key']
# extract actual value, ignoring value's key which looks like "intValue"
value = next(iter(attr['value'].values()))

# trim down long filepaths by omitting everything before "src/"
if key == 'code.filepath':
if (src_idx := value.find("src/")) > 0:
value = value[src_idx:]

simple_dict[key] = value

return simple_dict
5 changes: 5 additions & 0 deletions runners/s3-benchrunner-rust/graph/http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import plotly
import plotly.graph_objs

def draw(data) -> plotly.graph_objs.Figure:
pass

0 comments on commit e402232

Please sign in to comment.