Skip to content

Instantly share code, notes, and snippets.

@robinp
Last active September 4, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinp/c71e34dc2ad50481506fb8957ca61d69 to your computer and use it in GitHub Desktop.
Save robinp/c71e34dc2ad50481506fb8957ca61d69 to your computer and use it in GitHub Desktop.
Extract callgraph edges with awk
gunzip -c all.nq.gz | grep 'node/kind" "package' > packages.nq
gunzip -c all.nq.gz | awk 'NR==FNR { a[$1]; next } /childof/{if ($3 in a) print $1}' packages.nq - > pkgchildren.txt
gunzip -c all.nq.gz | awk 'NR==FNR { a[$1]; next } /childof/{if ($3 in a) print $1" "$3}' pkgchildren.txt - | gzip - > topchildren.txt.gz
gunzip -c all.nq.gz | awk 'NR==FNR { a[$1]=$2; mx=FNR; next } (NR-mx==FNR) { b[$1] ; next } /kythe\/edge\/ref/{if (($1 in a) && ($3 in b)) print a[$1]" "$3}' <(gunzip -c topchildren.txt.gz) pkgchildren.txt - | uniq | gzip - > callgraph.txt.gz
@robinp
Copy link
Author

robinp commented Sep 4, 2017

sed 's/%3A/:/g' sorted-callgraph.txt | grep -v '.l?hs(-boot)?"' | sed 's/"//g' | awk -F'[: ]' '{print """$4"/"$5"/"$6"" -> ""$10"/"$11"/"$12"""}' > graph.dot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment