diff --git a/src/cpu_profile.cc b/src/cpu_profile.cc index 87f7b34..c059c01 100644 --- a/src/cpu_profile.cc +++ b/src/cpu_profile.cc @@ -82,8 +82,8 @@ namespace nodex { profile->Set(NanNew("head"), head); #if (NODE_MODULE_VERSION > 0x000B) - Local start_time = NanNew(node->GetStartTime()/1000000); - Local end_time = NanNew(node->GetEndTime()/1000000); + Local start_time = NanNew((double)node->GetStartTime()/1000000.00); + Local end_time = NanNew((double)node->GetEndTime()/1000000.00); Local samples = NanNew(); uint32_t count = node->GetSamplesCount(); diff --git a/test/cpu_cprofiler.js b/test/cpu_cprofiler.js index dd42c58..2c3dbc8 100644 --- a/test/cpu_cprofiler.js +++ b/test/cpu_cprofiler.js @@ -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() { diff --git a/v8-profiler.js b/v8-profiler.js index 63e6552..d7d5718 100644 --- a/v8-profiler.js +++ b/v8-profiler.js @@ -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;