DevTools: Profiler domain refactoring: encode timestamps as deltas.
The CL makes CPUProfile encode sample timestamps as deltas, which makes the
representation more compact.
startTime and endTime are represented in microseconds rather than seconds.
BUG=635947
Review-Url: https://codereview.chromium.org/2262543002
Cr-Original-Commit-Position: refs/heads/master@{#413332}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 68666c0876081db75338384d7b76f0b5fb84473e
diff --git a/V8ProfilerAgentImpl.cpp b/V8ProfilerAgentImpl.cpp
index 0709eff..169573b 100644
--- a/V8ProfilerAgentImpl.cpp
+++ b/V8ProfilerAgentImpl.cpp
@@ -84,12 +84,16 @@
return array;
}
-std::unique_ptr<protocol::Array<double>> buildInspectorObjectForTimestamps(v8::CpuProfile* v8profile)
+std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(v8::CpuProfile* v8profile)
{
- std::unique_ptr<protocol::Array<double>> array = protocol::Array<double>::create();
+ std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create();
int count = v8profile->GetSamplesCount();
- for (int i = 0; i < count; i++)
- array->addItem(v8profile->GetSampleTimestamp(i));
+ uint64_t lastTime = v8profile->GetStartTime();
+ for (int i = 0; i < count; i++) {
+ uint64_t ts = v8profile->GetSampleTimestamp(i);
+ array->addItem(static_cast<int>(ts - lastTime));
+ lastTime = ts;
+ }
return array;
}
@@ -108,10 +112,10 @@
std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler::CPUProfile::create()
.setNodes(std::move(nodes))
- .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000)
- .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).build();
+ .setStartTime(static_cast<double>(v8profile->GetStartTime()))
+ .setEndTime(static_cast<double>(v8profile->GetEndTime())).build();
profile->setSamples(buildInspectorObjectForSamples(v8profile));
- profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile));
+ profile->setTimestampDeltas(buildInspectorObjectForTimestamps(v8profile));
return profile;
}
diff --git a/js_protocol.json b/js_protocol.json
index 5b2303e..40f7ed6 100644
--- a/js_protocol.json
+++ b/js_protocol.json
@@ -791,10 +791,10 @@
"description": "Profile.",
"properties": [
{ "name": "nodes", "type": "array", "items": { "$ref": "CPUProfileNode" }, "description": "The list of profile nodes. First item is the root node." },
- { "name": "startTime", "type": "number", "description": "Profiling start time in seconds." },
- { "name": "endTime", "type": "number", "description": "Profiling end time in seconds." },
+ { "name": "startTime", "type": "number", "description": "Profiling start timestamp in microseconds." },
+ { "name": "endTime", "type": "number", "description": "Profiling end timestamp in microseconds." },
{ "name": "samples", "optional": true, "type": "array", "items": { "type": "integer" }, "description": "Ids of samples top nodes." },
- { "name": "timestamps", "optional": true, "type": "array", "items": { "type": "number" }, "description": "Timestamps of the samples in microseconds." }
+ { "name": "timestampDeltas", "optional": true, "type": "array", "items": { "type": "integer" }, "description": "Deltas between adjacent sample timestamps in microseconds. The first delta is relative to the profile startTime." }
]
},
{