Commit 06eaaac5 by Jamie Madill Committed by Commit Bot

Fix trace writing in angle_perftests.

We can use this to produce AGI-like reports in standalone desktop. Bug: b/172704839 Change-Id: Ifc510232e3da81210e22429b6cea9800e2723e06 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2524540Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a5e0a4bc
...@@ -249,7 +249,6 @@ template("angle_perftests_common") { ...@@ -249,7 +249,6 @@ template("angle_perftests_common") {
"test_utils/runner/HistogramWriter.h", "test_utils/runner/HistogramWriter.h",
"test_utils/runner/TestSuite.h", "test_utils/runner/TestSuite.h",
] ]
deps = [ "$angle_jsoncpp_dir:jsoncpp" ]
public_deps = [ public_deps = [
"$angle_root/third_party/rapidjson:rapidjson", "$angle_root/third_party/rapidjson:rapidjson",
"${invoker.test_utils}", "${invoker.test_utils}",
......
...@@ -26,13 +26,17 @@ ...@@ -26,13 +26,17 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <json/json.h> #include <rapidjson/document.h>
#include <rapidjson/filewritestream.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/prettywriter.h>
#if defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS) #if defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS)
# include "util/windows/WGLWindow.h" # include "util/windows/WGLWindow.h"
#endif // defined(ANGLE_USE_UTIL_LOADER) &&defined(ANGLE_PLATFORM_WINDOWS) #endif // defined(ANGLE_USE_UTIL_LOADER) &&defined(ANGLE_PLATFORM_WINDOWS)
using namespace angle; using namespace angle;
namespace js = rapidjson;
namespace namespace
{ {
...@@ -124,39 +128,66 @@ double MonotonicallyIncreasingTime(angle::PlatformMethods *platform) ...@@ -124,39 +128,66 @@ double MonotonicallyIncreasingTime(angle::PlatformMethods *platform)
return GetHostTimeSeconds(); return GetHostTimeSeconds();
} }
bool WriteJsonFile(const std::string &outputFile, js::Document *doc)
{
FILE *fp = fopen(outputFile.c_str(), "w");
if (!fp)
{
return false;
}
constexpr size_t kBufferSize = 0xFFFF;
std::vector<char> writeBuffer(kBufferSize);
js::FileWriteStream os(fp, writeBuffer.data(), kBufferSize);
js::PrettyWriter<js::FileWriteStream> writer(os);
if (!doc->Accept(writer))
{
fclose(fp);
return false;
}
fclose(fp);
return true;
}
void DumpTraceEventsToJSONFile(const std::vector<TraceEvent> &traceEvents, void DumpTraceEventsToJSONFile(const std::vector<TraceEvent> &traceEvents,
const char *outputFileName) const char *outputFileName)
{ {
Json::Value eventsValue(Json::arrayValue); js::Document doc(js::kObjectType);
js::Document::AllocatorType &allocator = doc.GetAllocator();
js::Value events(js::kArrayType);
for (const TraceEvent &traceEvent : traceEvents) for (const TraceEvent &traceEvent : traceEvents)
{ {
Json::Value value(Json::objectValue); js::Value value(js::kObjectType);
const auto microseconds = static_cast<Json::LargestInt>(traceEvent.timestamp) * 1000 * 1000;
value["name"] = traceEvent.name; const uint64_t microseconds = static_cast<uint64_t>(traceEvent.timestamp * 1000.0 * 1000.0);
value["cat"] = traceEvent.categoryName;
value["ph"] = std::string(1, traceEvent.phase);
value["ts"] = microseconds;
value["pid"] = strcmp(traceEvent.categoryName, "gpu.angle.gpu") == 0 ? "GPU" : "ANGLE";
value["tid"] = 1;
eventsValue.append(std::move(value)); js::Document::StringRefType eventName(traceEvent.name);
} js::Document::StringRefType categoryName(traceEvent.categoryName);
js::Document::StringRefType pidName(
strcmp(traceEvent.categoryName, "gpu.angle.gpu") == 0 ? "GPU" : "ANGLE");
Json::Value root(Json::objectValue); value.AddMember("name", eventName, allocator);
root["traceEvents"] = eventsValue; value.AddMember("cat", categoryName, allocator);
value.AddMember("ph", std::string(1, traceEvent.phase), allocator);
value.AddMember("ts", microseconds, allocator);
value.AddMember("pid", pidName, allocator);
value.AddMember("tid", 1, allocator);
std::ofstream outFile; events.PushBack(value, allocator);
outFile.open(outputFileName); }
Json::StreamWriterBuilder factory; doc.AddMember("traceEvents", events, allocator);
std::unique_ptr<Json::StreamWriter> const writer(factory.newStreamWriter());
std::ostringstream stream;
writer->write(root, &outFile);
outFile.close(); if (WriteJsonFile(outputFileName, &doc))
{
printf("Wrote trace file to %s\n", outputFileName);
}
else
{
printf("Error writing trace file to %s\n", outputFileName);
}
} }
} // anonymous namespace } // anonymous namespace
......
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