Skip to content

Instantly share code, notes, and snippets.

@Muratam
Last active January 12, 2020 18:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muratam/5016c5eb250c59108db39d8e3db2e02f to your computer and use it in GitHub Desktop.
Save Muratam/5016c5eb250c59108db39d8e3db2e02f to your computer and use it in GitHub Desktop.
profile_results.txt を flamegraph.pl 形式にするやつ
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])
# profile_results.txt を flamegraph.svg に
nim c -r flamegraph.nim profile_results.txt | perl flamegraph.pl > flamegraph.svg
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment