Commit aece1a2a authored by Pierre Langlois's avatar Pierre Langlois Committed by V8 LUCI CQ

[turbofan] Record pipeline statistics in traces.

The --turbo-stats and --turbo-stats-wasm flags are useful but they do
not work on Chromium on Android, given we cannot print on exit of the
renderer process.

To cover all scenarios, we can encode the statistics as a string
argument in the trace format. It's also helpful to see those statistics,
as well as the code kind and function name, when clicking on a slice in
chrome://tracing or perfetto.

As a drive-by cleanup, rename ESCAPE to QUOTE in the JSON serialization
code.

Change-Id: I86f03d0e020c9543feb869620164bf1aad3a2432
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3132966Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
Cr-Commit-Position: refs/heads/main@{#76629}
parent 97a5b366
......@@ -53,6 +53,7 @@ PipelineStatistics::PipelineStatistics(OptimizedCompilationInfo* info,
: outer_zone_(info->zone()),
zone_stats_(zone_stats),
compilation_stats_(compilation_stats),
code_kind_(info->code_kind()),
phase_kind_name_(nullptr),
phase_name_(nullptr) {
if (info->has_shared_info()) {
......@@ -61,7 +62,6 @@ PipelineStatistics::PipelineStatistics(OptimizedCompilationInfo* info,
total_stats_.Begin(this);
}
PipelineStatistics::~PipelineStatistics() {
if (InPhaseKind()) EndPhaseKind();
CompilationStatistics::BasicStats diff;
......@@ -73,7 +73,8 @@ PipelineStatistics::~PipelineStatistics() {
void PipelineStatistics::BeginPhaseKind(const char* phase_kind_name) {
DCHECK(!InPhase());
if (InPhaseKind()) EndPhaseKind();
TRACE_EVENT_BEGIN0(kTraceCategory, phase_kind_name);
TRACE_EVENT_BEGIN1(kTraceCategory, phase_kind_name, "kind",
CodeKindToString(code_kind_));
phase_kind_name_ = phase_kind_name;
phase_kind_stats_.Begin(this);
}
......@@ -83,11 +84,14 @@ void PipelineStatistics::EndPhaseKind() {
CompilationStatistics::BasicStats diff;
phase_kind_stats_.End(this, &diff);
compilation_stats_->RecordPhaseKindStats(phase_kind_name_, diff);
TRACE_EVENT_END0(kTraceCategory, phase_kind_name_);
TRACE_EVENT_END2(kTraceCategory, phase_kind_name_, "kind",
CodeKindToString(code_kind_), "stats",
TRACE_STR_COPY(diff.AsJSON().c_str()));
}
void PipelineStatistics::BeginPhase(const char* phase_name) {
TRACE_EVENT_BEGIN0(kTraceCategory, phase_name);
TRACE_EVENT_BEGIN1(kTraceCategory, phase_name, "kind",
CodeKindToString(code_kind_));
DCHECK(InPhaseKind());
phase_name_ = phase_name;
phase_stats_.Begin(this);
......@@ -98,7 +102,9 @@ void PipelineStatistics::EndPhase() {
CompilationStatistics::BasicStats diff;
phase_stats_.End(this, &diff);
compilation_stats_->RecordPhaseStats(phase_kind_name_, phase_name_, diff);
TRACE_EVENT_END0(kTraceCategory, phase_name_);
TRACE_EVENT_END2(kTraceCategory, phase_name_, "kind",
CodeKindToString(code_kind_), "stats",
TRACE_STR_COPY(diff.AsJSON().c_str()));
}
} // namespace compiler
......
......@@ -11,6 +11,7 @@
#include "src/base/platform/elapsed-timer.h"
#include "src/compiler/zone-stats.h"
#include "src/diagnostics/compilation-statistics.h"
#include "src/objects/code-kind.h"
#include "src/tracing/trace-event.h"
namespace v8 {
......@@ -67,6 +68,7 @@ class PipelineStatistics : public Malloced {
Zone* outer_zone_;
ZoneStats* zone_stats_;
CompilationStatistics* compilation_stats_;
CodeKind code_kind_;
std::string function_name_;
// Stats for the entire compilation.
......
......@@ -56,6 +56,29 @@ void CompilationStatistics::BasicStats::Accumulate(const BasicStats& stats) {
}
}
std::string CompilationStatistics::BasicStats::AsJSON() {
// clang-format off
#define DICT(s) "{" << s << "}"
#define QUOTE(s) "\"" << s << "\""
#define MEMBER(s) QUOTE(s) << ":"
DCHECK_EQ(function_name_.find("\""), std::string::npos);
std::stringstream stream;
stream << DICT(
MEMBER("function_name") << QUOTE(function_name_) << ","
MEMBER("total_allocated_bytes") << total_allocated_bytes_ << ","
MEMBER("max_allocated_bytes") << max_allocated_bytes_ << ","
MEMBER("absolute_max_allocated_bytes") << absolute_max_allocated_bytes_);
return stream.str();
#undef DICT
#undef QUOTE
#undef MEMBER
// clang-format on
}
static void WriteLine(std::ostream& os, bool machine_format, const char* name,
const CompilationStatistics::BasicStats& stats,
const CompilationStatistics::BasicStats& total_stats) {
......
......@@ -37,6 +37,8 @@ class CompilationStatistics final : public Malloced {
void Accumulate(const BasicStats& stats);
std::string AsJSON();
base::TimeDelta delta_;
size_t total_allocated_bytes_;
size_t max_allocated_bytes_;
......
......@@ -653,8 +653,8 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) {
// clang-format off
#define DICT(s) "{" << s << "}"
#define LIST(s) "[" << s << "]"
#define ESCAPE(s) "\"" << s << "\""
#define MEMBER(s) ESCAPE(s) << ":"
#define QUOTE(s) "\"" << s << "\""
#define MEMBER(s) QUOTE(s) << ":"
auto SpaceStatistics = [this](int space_index) {
HeapSpaceStatistics space_stats;
......@@ -663,7 +663,7 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) {
std::stringstream stream;
stream << DICT(
MEMBER("name")
<< ESCAPE(BaseSpace::GetSpaceName(
<< QUOTE(BaseSpace::GetSpaceName(
static_cast<AllocationSpace>(space_index)))
<< ","
MEMBER("size") << space_stats.space_size() << ","
......@@ -674,7 +674,7 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) {
};
stream << DICT(
MEMBER("isolate") << ESCAPE(reinterpret_cast<void*>(isolate())) << ","
MEMBER("isolate") << QUOTE(reinterpret_cast<void*>(isolate())) << ","
MEMBER("id") << gc_count() << ","
MEMBER("time_ms") << isolate()->time_millis_since_init() << ","
MEMBER("total_heap_size") << stats.total_heap_size() << ","
......@@ -699,7 +699,7 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) {
#undef DICT
#undef LIST
#undef ESCAPE
#undef QUOTE
#undef MEMBER
// clang-format on
}
......
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