[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/1123325 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Alexei Filippov <alph@chromium.org> Cr-Commit-Position: refs/heads/master@{#54180}
This commit is contained in:
parent
1ba5d5ba76
commit
f77aa8d035
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user