Last active
January 12, 2020 18:56
-
-
Save Muratam/5016c5eb250c59108db39d8e3db2e02f to your computer and use it in GitHub Desktop.
profile_results.txt を flamegraph.pl 形式にするやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import system | |
import strutils | |
import sequtils | |
import algorithm | |
proc findCallCount(line:string) : string = | |
let args = line.split(" ") | |
for i,arg in args: | |
if not arg.startsWith("Call"): continue | |
return args[i+1].split("/")[0] | |
assert false,"cant find call count:\n[" & line & "]" | |
proc parseTree(lines:seq[string]): seq[seq[string]] = | |
result = @[] | |
var ignored = false | |
for line in lines: | |
if line == "" : continue | |
if line.startsWith(" "): | |
let flames = line.strip().split(" ") | |
let file = flames[0].replace(".nim","").replace(":","") | |
let fun = flames[1].replace(";","").replace(":","") | |
if file.startsWith(".") or fun.startsWith(".") : continue | |
if file == "nimprof" : ignored = true | |
if ignored : continue | |
result[^1] &= @[fun & "(" & file & ")"] | |
elif line.startsWith("Entry"): | |
ignored = false | |
result &= @[line.findCallCount()] | |
proc parse(fileName:string) : string = | |
result = "" | |
let lines = open(fileName,FileMode.fmRead).readAll().split("\n") | |
let tree = lines.parseTree | |
for t in tree: | |
result &= t[1..^1].reversed().join(";") & " " & t[0] & "\n" | |
if isMainModule: | |
echo parse(commandLineParams()[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# profile_results.txt を flamegraph.svg に | |
nim c -r flamegraph.nim profile_results.txt | perl flamegraph.pl > flamegraph.svg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment