Skip to content

Instantly share code, notes, and snippets.

@llllllllll
Created May 27, 2018 01:24
Show Gist options
  • Save llllllllll/8e2307dd50a8bc0e534ee0015d4d5588 to your computer and use it in GitHub Desktop.
Save llllllllll/8e2307dd50a8bc0e534ee0015d4d5588 to your computer and use it in GitHub Desktop.
import pandas as pd
import networkx
import toolz
df = pd.read_csv('/home/joe/downloads/debug.csv', escapechar='\\')
df.columns = ['stack', 'module', 'function', 'lineno', 'id', 'type', 'repr']
g = networkx.DiGraph()
for row in df[df.module == '__main__'].itertuples():
g.add_node('.'.join((row.module, row.function)), **{row.id: row.type})
for u, v in toolz.sliding_window(2, row.stack.split(';')):
u = u.split(':', 1)[0]
v = v.split(':', 1)[0]
g.add_edge(v, u)
def f(group):
stacks = [
[v.split(':', 1)[0] for v in stack]
for stack in group['stack'].str.split(';').tolist()
]
it = iter(stacks)
head = next(it)
for e in it:
if e[-len(head):] != head:
head = e
else:
print(
f'{group.iloc[0]["id"]}={group.iloc[0]["repr"]} {e}',
)
df.groupby('id').apply(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment