Unverified Commit 263d5197 authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Change chrome trace to use string concat instead of streams (#4399)

* stringstream version

* string concat for faster performance

* cleanup
Co-authored-by: 's avatarScott Cyphers <diyessi@users.noreply.github.com>
parent 22d4285f
...@@ -65,26 +65,26 @@ void runtime::event::Duration::write() ...@@ -65,26 +65,26 @@ void runtime::event::Duration::write()
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::event::Manager::get_output_stream(); ofstream& out = runtime::event::Manager::get_output_stream();
string str;
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::event::Manager::open(); runtime::event::Manager::open();
} }
else else
{ {
Manager::get_output_stream() << ",\n"; str += ",\n";
} }
Manager::get_output_stream() << str +=
R"({"name":")" << m_name << R"(","cat":")" << m_category << R"(","ph":"X","pid":)" R"({"name":")" + m_name + R"(","cat":")" + m_category + R"(","ph":"X","pid":)" +
<< Manager::get_process_id() << R"(,"tid":)" Manager::get_process_id() + R"(,"tid":)" + Manager::get_thread_id() +
<< Manager::get_thread_id() << R"(,"ts":)" + to_string(m_start) + R"(,"dur":)" + to_string(stop_time - m_start);
R"(,"ts":)" << m_start << R"(,"dur":)" << (stop_time - m_start);
if (!m_args.empty()) if (!m_args.empty())
{ {
out << str += R"(,"args":)" + m_args;
R"(,"args":)" << m_args;
} }
out << "}"; str += "}";
out << str;
} }
} }
...@@ -97,23 +97,23 @@ runtime::event::Object::Object(const string& name, const string& args) ...@@ -97,23 +97,23 @@ runtime::event::Object::Object(const string& name, const string& args)
lock_guard<mutex> lock(Manager::get_mutex()); lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = runtime::event::Manager::get_output_stream(); ofstream& out = runtime::event::Manager::get_output_stream();
string str;
if (out.is_open() == false) if (out.is_open() == false)
{ {
runtime::event::Manager::open(); runtime::event::Manager::open();
} }
else else
{ {
Manager::get_output_stream() << ",\n"; str += ",\n";
} }
out << R"({"name":")" << m_name << R"(","ph":"N","id":")" << m_id << str += R"({"name":")" + m_name + R"(","ph":"N","id":")" + to_string(m_id) +
R"(","ts":)" << Manager::get_current_microseconds() << R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
R"(,"pid":)" << Manager::get_process_id() << R"(,"tid":)" << Manager::get_thread_id(); R"(,"pid":)" + Manager::get_process_id() + R"(,"tid":)" + Manager::get_thread_id();
if (!args.empty()) if (!args.empty())
{ {
out << str += R"(,"args":)" + args;
R"(,"args":)" << args;
} }
out << "}"; str += "}";
write_snapshot(out, args); write_snapshot(out, args);
} }
...@@ -140,15 +140,15 @@ void runtime::event::Object::snapshot(const string& args) ...@@ -140,15 +140,15 @@ void runtime::event::Object::snapshot(const string& args)
void runtime::event::Object::write_snapshot(ostream& out, const string& args) void runtime::event::Object::write_snapshot(ostream& out, const string& args)
{ {
out << R"({"name":")" << m_name << R"(","ph":"O","id":")" << m_id << string str = R"({"name":")" + m_name + R"(","ph":"O","id":")" + to_string(m_id) +
R"(","ts":)" << Manager::get_current_microseconds() << R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
R"(,"pid":)" << Manager::get_process_id() << R"(,"tid":)" << Manager::get_thread_id(); R"(,"pid":)" + Manager::get_process_id() + R"(,"tid":)" + Manager::get_thread_id();
if (!args.empty()) if (!args.empty())
{ {
out << str += R"(,"args":)" + args;
R"(,"args":)" << args;
} }
out << "}"; str += "}";
out << str;
} }
void runtime::event::Object::destroy() void runtime::event::Object::destroy()
...@@ -166,10 +166,10 @@ void runtime::event::Object::destroy() ...@@ -166,10 +166,10 @@ void runtime::event::Object::destroy()
{ {
Manager::get_output_stream() << ",\n"; Manager::get_output_stream() << ",\n";
} }
out << R"({"name":")" << m_name << R"(","ph":"D","id":")" << m_id << string str = R"({"name":")" + m_name + R"(","ph":"D","id":")" + to_string(m_id) +
R"(","ts":)" << Manager::get_current_microseconds() << R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
R"(,"pid":)" << Manager::get_process_id() << R"(,"tid":)" << Manager::get_thread_id() R"(,"pid":)" + Manager::get_process_id() + R"(,"tid":)" +
<< "}"; Manager::get_thread_id() + "}";
} }
} }
......
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