Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use doubles for startTime and endTime #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cpu_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace nodex {
profile->Set(NanNew<String>("head"), head);

#if (NODE_MODULE_VERSION > 0x000B)
Local<Value> start_time = NanNew<Number>(node->GetStartTime()/1000000);
Local<Value> end_time = NanNew<Number>(node->GetEndTime()/1000000);
Local<Value> start_time = NanNew<Number>((double)node->GetStartTime()/1000000.00);
Local<Value> end_time = NanNew<Number>((double)node->GetEndTime()/1000000.00);
Local<Array> samples = NanNew<Array>();

uint32_t count = node->GetSamplesCount();
Expand Down
10 changes: 10 additions & 0 deletions test/cpu_cprofiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ describe('CPU', function() {
expect(profile.samples.length > 0).to.equal(true);
});

it('should record startTime and endTime with subsecond precision', function(done) {
profiler.startProfiling('P');
var delayInMilliseconds = 150;
setTimeout(function() {
var profile = profiler.stopProfiling();
var elapsedTime = profile.endTime - profile.startTime;
expect(elapsedTime).to.be.at.least(delayInMilliseconds / 1000);
done();
}, delayInMilliseconds);
});
});

describe('Profile', function() {
Expand Down
4 changes: 2 additions & 2 deletions v8-profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ var profiler = {
get profiles() { return binding.cpu.profiles; },

startProfiling: function(name, recsamples) {
startTime = Date.now();
startTime = Date.now() / 1000;
binding.cpu.startProfiling(name, recsamples);
},

stopProfiling: function(name) {
var profile = binding.cpu.stopProfiling(name);
endTime = Date.now();
endTime = Date.now() / 1000;
profile.__proto__ = CpuProfile.prototype;
if (!profile.startTime) profile.startTime = startTime;
if (!profile.endTime) profile.endTime = endTime;
Expand Down