Skip to content

Instantly share code, notes, and snippets.

@nickgnd
Created December 19, 2022 14:01
Show Gist options
  • Save nickgnd/c6d7cabc312ea22acc0922591c735743 to your computer and use it in GitHub Desktop.
Save nickgnd/c6d7cabc312ea22acc0922591c735743 to your computer and use it in GitHub Desktop.
Parse eprof result and create a CSV out of it
# eprof_results is the output printed by the `eprof` profiler
# with the "extra" lines already stripped (e.g. "Profile done over XXX matching functions")
eprof_results
|> String.split("\n", trim: true)
|> Enum.map(fn
"anonymous fn" <> _rest = row ->
[anonymous_fn, rest] =
String.split(row, ~r{anonymous fn/\d+ in .*/\d+}, trim: true, include_captures: true)
[anonymous_fn] ++ String.split(rest, ~r/\s/, trim: true)
row ->
String.split(row, ~r/\s/, trim: true)
end)
|> Enum.map(& Enum.join(&1, ", "))
|> Enum.join("\n")
|> then(& File.write!("results.csv", &1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment