Skip to content

Commit

Permalink
Record sample timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Chekhovskyi committed Aug 31, 2015
1 parent 372fb46 commit 49461b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/cpu_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ namespace nodex {
Local<Value> start_time = Nan::New<Number>(node->GetStartTime()/1000000);
Local<Value> end_time = Nan::New<Number>(node->GetEndTime()/1000000);
Local<Array> samples = Nan::New<Array>();
Local<Array> timestamps = Nan::New<Array>();

uint32_t count = node->GetSamplesCount();
for (uint32_t index = 0; index < count; ++index) {
samples->Set(index, Nan::New<Integer>(node->GetSample(index)->GetNodeId()));
timestamps->Set(index, Nan::New<Number>(static_cast<double>(node->GetSampleTimestamp(index))));
}

profile->Set(Nan::New<String>("startTime").ToLocalChecked(), start_time);
profile->Set(Nan::New<String>("endTime").ToLocalChecked(), end_time);
profile->Set(Nan::New<String>("samples").ToLocalChecked(), samples);
profile->Set(Nan::New<String>("startTime").ToLocalChecked(), start_time);
profile->Set(Nan::New<String>("endTime").ToLocalChecked(), end_time);
profile->Set(Nan::New<String>("samples").ToLocalChecked(), samples);
profile->Set(Nan::New<String>("timestamps").ToLocalChecked(), timestamps);
#endif

Local<Array> profiles = Nan::New<Array>(Profile::profiles);
Expand Down
2 changes: 1 addition & 1 deletion test/cpu_cprofiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('CPU', function() {
var profile = binding.cpu.stopProfiling();
var properties = NODE_V_10 ?
['delete', 'typeId', 'uid', 'title', 'head'] :
['delete', 'typeId', 'uid', 'title', 'head', 'startTime', 'endTime', 'samples'];
['delete', 'typeId', 'uid', 'title', 'head', 'startTime', 'endTime', 'samples', 'timestamps'];

properties.forEach(function(prop) {
expect(profile).to.have.property(prop);
Expand Down

0 comments on commit 49461b2

Please sign in to comment.