Commit d8364df2 authored by Philip Trettner's avatar Philip Trettner

added function pretty print

parent 94ada7db
......@@ -18,6 +18,51 @@ void write_dir(const std::string &path)
write_summary_csv(path + "/trace.csv");
}
static std::string beautify_function_name(std::string const &name)
{
auto p = name.rfind(')');
if (p == std::string::npos) // no (..)
{
p = name.rfind(' ');
if (p == std::string::npos) // no space
return name;
return name.substr(p + 1); // "void foo" -> "foo"
}
int i = p;
int db = 0;
int da = 0;
int cc = 0;
while (i >= 0)
{
if (name[i] == ')')
++db;
if (name[i] == '>')
++da;
if (name[i] == '<')
--da;
if (name[i] == '(')
--db;
if (name[i] == ':' && da == 0 && db == 0)
{
++cc;
if (cc > 2)
break;
}
if (name[i] == ' ' && da == 0 && db == 0)
break;
--i;
}
if (i < 0)
return name;
return name.substr(i + 1);
}
void write_speedscope_json(std::string const &filename)
{
std::ofstream out(filename);
......@@ -109,7 +154,7 @@ void write_speedscope_json(std::string const &filename)
if (i > 0)
out << ",";
out << "{";
out << "\"name\":\"" << (std::string(loc->name).empty() ? loc->function : loc->name) << "\",";
out << "\"name\":\"" << (std::string(loc->name).empty() ? beautify_function_name(loc->function) : loc->name) << "\",";
out << "\"file\":\"" << loc->file << "\",";
out << "\"line\":" << loc->line << "";
out << "}";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment