wsd: streamline TraceEvent strings
Change-Id: I56e5cf05d45914e71d96a0b0a583d413fd6bd79a Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
8800dea4c2
commit
0dfd863fd3
3 changed files with 35 additions and 28 deletions
|
@ -63,30 +63,36 @@ void ProfileZone::emitRecording()
|
|||
if (!recordingOn)
|
||||
return;
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
|
||||
// Generate a single "Complete Event" (type X)
|
||||
auto duration = now - _createTime;
|
||||
const auto duration = std::chrono::system_clock::now() - _createTime;
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "{"
|
||||
"\"name\":\""
|
||||
<< name()
|
||||
<< "\","
|
||||
"\"ph\":\"X\","
|
||||
"\"ts\":"
|
||||
<< std::chrono::duration_cast<std::chrono::microseconds>(_createTime.time_since_epoch())
|
||||
.count()
|
||||
<< ","
|
||||
"\"dur\":"
|
||||
<< std::chrono::duration_cast<std::chrono::microseconds>(duration).count()
|
||||
<< ","
|
||||
"\"pid\":"
|
||||
<< pid()
|
||||
<< ","
|
||||
"\"tid\":"
|
||||
<< getThreadId();
|
||||
|
||||
if (!args().empty())
|
||||
{
|
||||
oss << ",\"args\":" << args();
|
||||
}
|
||||
|
||||
oss << "},";
|
||||
std::string recordingData = oss.str();
|
||||
|
||||
std::string recordingData(
|
||||
"{"
|
||||
"\"name\":\"" +
|
||||
std::string(name()) +
|
||||
"\","
|
||||
"\"ph\":\"X\","
|
||||
"\"ts\":" +
|
||||
std::to_string(
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(_createTime.time_since_epoch())
|
||||
.count()) +
|
||||
","
|
||||
"\"dur\":" +
|
||||
std::to_string(std::chrono::duration_cast<std::chrono::microseconds>(duration).count()) +
|
||||
","
|
||||
"\"pid\":" +
|
||||
std::to_string(pid()) +
|
||||
","
|
||||
"\"tid\":" +
|
||||
std::to_string(getThreadId()) + (args().length() == 0 ? "" : ",\"args\":" + args()) + "},");
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
emitOneRecording(recordingData);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,10 @@ protected:
|
|||
if (!recordingOn)
|
||||
return "0";
|
||||
|
||||
std::string result = "{";
|
||||
std::string result;
|
||||
result.reserve(args.size() * 64);
|
||||
|
||||
result += '{';
|
||||
bool first = true;
|
||||
for (const auto& i : args)
|
||||
{
|
||||
|
|
|
@ -2149,20 +2149,18 @@ void flushTraceEventRecordings()
|
|||
if (r.empty())
|
||||
return;
|
||||
|
||||
std::size_t totalLength = 0;
|
||||
std::size_t totalLength = 32; // Provision for the command name.
|
||||
for (const auto& i: r)
|
||||
totalLength += i.length();
|
||||
|
||||
std::string recordings;
|
||||
recordings.reserve(totalLength);
|
||||
|
||||
recordings.append(n == 0 ? "forcetraceevent: \n" : "traceevent: \n");
|
||||
for (const auto& i: r)
|
||||
recordings += i;
|
||||
|
||||
std::string name = "forcetraceevent: \n";
|
||||
if (n == 1 )
|
||||
name = "traceevent: \n";
|
||||
singletonDocument->sendTextFrame(name + recordings);
|
||||
singletonDocument->sendTextFrame(recordings);
|
||||
r.clear();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue