Skip to content

Commit

Permalink
fix: precision loss in (CpuProfileNode*) ptr->GetSampleTimestamp()
Browse files Browse the repository at this point in the history
PR-URL: #115
Reviewed-BY: hyj1991 <[email protected]>
  • Loading branch information
hyj1991 authored Dec 18, 2021
1 parent d363f1c commit 170052b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/commands/cpuprofiler/cpu_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ void Profile::Serialize(const CpuProfile *node, std::string filename) {
writer.json_keyvalue("endTime", node->GetEndTime());

// set samples
uint32_t count = node->GetSamplesCount();
int count = node->GetSamplesCount();
writer.json_arraystart("samples");
for (uint32_t index = 0; index < count; ++index) {
for (int index = 0; index < count; ++index) {
writer.json_element(node->GetSample(index)->GetNodeId());
}
writer.json_arrayend();

// set timestamps
writer.json_arraystart("timeDeltas");
for (uint32_t index = 0; index < count; ++index) {
uint32_t prev =
for (int index = 0; index < count; ++index) {
int64_t prev =
index == 0 ? node->GetStartTime() : node->GetSampleTimestamp(index - 1);
uint32_t delta = node->GetSampleTimestamp(index) - prev;
int64_t delta = node->GetSampleTimestamp(index) - prev;
writer.json_element(delta);
}
writer.json_arrayend();
Expand Down
6 changes: 3 additions & 3 deletions src/commands/cpuprofiler/cpu_profile_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ void ProfileNode::SerializeNode(const CpuProfileNode *node,
writer->json_objectend();

// set children
int32_t count = node->GetChildrenCount();
int count = node->GetChildrenCount();
writer->json_arraystart("children");
for (int32_t index = 0; index < count; index++) {
for (int index = 0; index < count; index++) {
writer->json_element(node->GetChild(index)->GetNodeId());
}
writer->json_arrayend();
writer->json_end();

for (int32_t index = 0; index < count; index++) {
for (int index = 0; index < count; index++) {
ProfileNode::SerializeNode(node->GetChild(index), writer);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const cpuprofile = {
functionName: /^([$.\w\s()-_]+|)$/,
scriptId: /^\d+$/,
bailoutReason: /^([\w\s]+|)$/,
url: /^([@.\w()/\\:_-]+|)$/,
url: /^([@.\w()/\\:_-\s]+|)$/,
lineNumber: /^\d+$/,
columnNumber: /^\d+$/,
},
Expand Down Expand Up @@ -98,7 +98,7 @@ const heapprofile = {
callFrame: {
functionName: /^([$.\w\s()-_]+|)$/,
scriptId: /^\d+$/,
url: /^([@.\w()/\\:_-]+|)$/,
url: /^([@.\w()/\\:_-\s]+|)$/,
lineNumber: /^\d+$/,
columnNumber: /^\d+$/
},
Expand Down

0 comments on commit 170052b

Please sign in to comment.