Commit 65b3af46 authored by lpy's avatar lpy Committed by Commit bot

Use TracedValue in runtime statistics.

We introduced TracedValue into V8 tracing previously, this patch uses it to
build JSON string of runtime statistics instead of using stringstream as buffer.

BUG=v8:5089
LOG=N

Review-Url: https://chromiumcodereview.appspot.com/2418303002
Cr-Commit-Position: refs/heads/master@{#40443}
parent eafa9206
......@@ -277,9 +277,11 @@ void RuntimeCallCounter::Reset() {
time = base::TimeDelta();
}
void RuntimeCallCounter::Dump(std::stringstream& out) {
out << "\"" << name << "\":[" << count << "," << time.InMicroseconds()
<< "],";
void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) {
value->BeginArray(name);
value->AppendLongInteger(count);
value->AppendLongInteger(time.InMicroseconds());
value->EndArray();
}
// static
......@@ -365,37 +367,33 @@ void RuntimeCallStats::Reset() {
in_use_ = true;
}
std::string RuntimeCallStats::Dump() {
buffer_.str(std::string());
buffer_.clear();
buffer_ << "{";
void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) {
#define DUMP_COUNTER(name) \
if (this->name.count > 0) this->name.Dump(buffer_);
if (this->name.count > 0) this->name.Dump(value);
FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER)
#undef DUMP_COUNTER
#define DUMP_COUNTER(name, nargs, result_size) \
if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(buffer_);
if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(value);
FOR_EACH_INTRINSIC(DUMP_COUNTER)
#undef DUMP_COUNTER
#define DUMP_COUNTER(name) \
if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(buffer_);
if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(value);
BUILTIN_LIST_C(DUMP_COUNTER)
#undef DUMP_COUNTER
#define DUMP_COUNTER(name) \
if (this->API_##name.count > 0) this->API_##name.Dump(buffer_);
if (this->API_##name.count > 0) this->API_##name.Dump(value);
FOR_EACH_API_COUNTER(DUMP_COUNTER)
#undef DUMP_COUNTER
#define DUMP_COUNTER(name) \
if (this->Handler_##name.count > 0) this->Handler_##name.Dump(buffer_);
if (this->Handler_##name.count > 0) this->Handler_##name.Dump(value);
FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER)
#undef DUMP_COUNTER
buffer_ << "\"END\":[]}";
in_use_ = false;
return buffer_.str();
}
} // namespace internal
......
......@@ -15,6 +15,7 @@
#include "src/objects.h"
#include "src/runtime/runtime.h"
#include "src/tracing/trace-event.h"
#include "src/tracing/traced-value.h"
namespace v8 {
namespace internal {
......@@ -484,7 +485,7 @@ double AggregatedMemoryHistogram<Histogram>::Aggregate(double current_ms,
struct RuntimeCallCounter {
explicit RuntimeCallCounter(const char* name) : name(name) {}
V8_NOINLINE void Reset();
V8_NOINLINE void Dump(std::stringstream& out);
V8_NOINLINE void Dump(v8::tracing::TracedValue* value);
const char* name;
int64_t count = 0;
......@@ -799,7 +800,7 @@ class RuntimeCallStats {
void Reset();
void Print(std::ostream& os);
std::string Dump();
V8_NOINLINE void Dump(v8::tracing::TracedValue* value);
RuntimeCallStats() {
Reset();
......@@ -810,7 +811,6 @@ class RuntimeCallStats {
bool InUse() { return in_use_; }
private:
std::stringstream buffer_;
// Counter to track recursive time events.
RuntimeCallTimer* current_timer_ = NULL;
// Used to track nested tracing scopes.
......
......@@ -8,6 +8,7 @@
#include "src/counters.h"
#include "src/isolate.h"
#include "src/tracing/traced-value.h"
#include "src/v8.h"
namespace v8 {
......@@ -24,14 +25,13 @@ v8::Platform* TraceEventHelper::GetCurrentPlatform() {
void CallStatsScopedTracer::AddEndTraceEvent() {
if (!has_parent_scope_ && p_data_->isolate) {
auto value = v8::tracing::TracedValue::Create();
p_data_->isolate->counters()->runtime_call_stats()->Dump(value.get());
v8::internal::tracing::AddTraceEvent(
TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE,
"runtime-call-stats", TRACE_STR_COPY(p_data_->isolate->counters()
->runtime_call_stats()
->Dump()
.c_str()));
"runtime-call-stats", std::move(value));
} else {
v8::internal::tracing::AddTraceEvent(
TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
......
......@@ -121,6 +121,12 @@ void TracedValue::AppendInteger(int value) {
data_ += std::to_string(value);
}
void TracedValue::AppendLongInteger(int64_t value) {
DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray);
WriteComma();
data_ += std::to_string(value);
}
void TracedValue::AppendDouble(double value) {
DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray);
WriteComma();
......
......@@ -34,6 +34,7 @@ class TracedValue : public ConvertableToTraceFormat {
void BeginArray(const char* name);
void AppendInteger(int);
void AppendLongInteger(int64_t);
void AppendDouble(double);
void AppendBoolean(bool);
void AppendString(const std::string&);
......
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