Commit f77aa8d0 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[cpu-profiler] Make tracing-based CPU profile ids unique

Using CpuProfile pointer is not safe for id as the profile objects
can be recreated on the same memory address.
Use sequential numbers instead.

Change-Id: I7253605819055bc3396b797f9ce27669e8c2584d
Reviewed-on: https://chromium-review.googlesource.com/1123325Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54180}
parent 1ba5d5ba
......@@ -386,6 +386,8 @@ void ProfileTree::TraverseDepthFirst(Callback* callback) {
using v8::tracing::TracedValue;
std::atomic<uint32_t> CpuProfile::last_id_;
CpuProfile::CpuProfile(CpuProfiler* profiler, const char* title,
bool record_samples, ProfilingMode mode)
: title_(title),
......@@ -394,12 +396,13 @@ CpuProfile::CpuProfile(CpuProfiler* profiler, const char* title,
start_time_(base::TimeTicks::HighResolutionNow()),
top_down_(profiler->isolate()),
profiler_(profiler),
streaming_next_sample_(0) {
streaming_next_sample_(0),
id_(++last_id_) {
auto value = TracedValue::Create();
value->SetDouble("startTime",
(start_time_ - base::TimeTicks()).InMicroseconds());
TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"),
"Profile", this, "data", std::move(value));
"Profile", id_, "data", std::move(value));
}
void CpuProfile::AddPath(base::TimeTicks timestamp,
......@@ -491,7 +494,7 @@ void CpuProfile::StreamPendingTraceEvents() {
}
TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"),
"ProfileChunk", this, "data", std::move(value));
"ProfileChunk", id_, "data", std::move(value));
}
void CpuProfile::FinishProfile() {
......@@ -500,7 +503,7 @@ void CpuProfile::FinishProfile() {
auto value = TracedValue::Create();
value->SetDouble("endTime", (end_time_ - base::TimeTicks()).InMicroseconds());
TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"),
"ProfileChunk", this, "data", std::move(value));
"ProfileChunk", id_, "data", std::move(value));
}
void CpuProfile::Print() {
......
......@@ -5,6 +5,7 @@
#ifndef V8_PROFILER_PROFILE_GENERATOR_H_
#define V8_PROFILER_PROFILE_GENERATOR_H_
#include <atomic>
#include <deque>
#include <limits>
#include <map>
......@@ -261,7 +262,6 @@ class ProfileNode {
DISALLOW_COPY_AND_ASSIGN(ProfileNode);
};
class ProfileTree {
public:
explicit ProfileTree(Isolate* isolate);
......@@ -354,6 +354,9 @@ class CpuProfile {
ProfileTree top_down_;
CpuProfiler* const profiler_;
size_t streaming_next_sample_;
uint32_t id_;
static std::atomic<uint32_t> last_id_;
DISALLOW_COPY_AND_ASSIGN(CpuProfile);
};
......
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