Commit 411d21b2 authored by yurys@chromium.org's avatar yurys@chromium.org

Add start and end profiling time to v8::CpuProfile

I'm going to change CPU profiler API and deprecate GetSelfTime, GetTotalTime and GetTotalSamplesCount on CpuProfileNode as all of those values are derived from self samples count and sampling rate. The sampling rate in turn is calculate based on the profiling duration so having start/end time and total sample count is enough for calculating smpling rate.

BUG=267595
R=alph@chromium.org, bmeurer@chromium.org

Review URL: https://codereview.chromium.org/21918002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16039 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e544f130
...@@ -148,6 +148,18 @@ class V8EXPORT CpuProfile { ...@@ -148,6 +148,18 @@ class V8EXPORT CpuProfile {
*/ */
const CpuProfileNode* GetSample(int index) const; const CpuProfileNode* GetSample(int index) const;
/**
* Returns time when the profile recording started (in milliseconds
* since the Epoch).
*/
double GetStartTime() const;
/**
* Returns time when the profile recording was stopped (in milliseconds
* since the Epoch).
*/
double GetEndTime() const;
/** /**
* Deletes the profile and removes it from CpuProfiler's list. * Deletes the profile and removes it from CpuProfiler's list.
* All pointers to nodes previously returned become invalid. * All pointers to nodes previously returned become invalid.
......
...@@ -7567,6 +7567,18 @@ const CpuProfileNode* CpuProfile::GetSample(int index) const { ...@@ -7567,6 +7567,18 @@ const CpuProfileNode* CpuProfile::GetSample(int index) const {
} }
double CpuProfile::GetStartTime() const {
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
return profile->start_time_ms();
}
double CpuProfile::GetEndTime() const {
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
return profile->end_time_ms();
}
int CpuProfile::GetSamplesCount() const { int CpuProfile::GetSamplesCount() const {
return reinterpret_cast<const i::CpuProfile*>(this)->samples_count(); return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
} }
......
...@@ -209,12 +209,15 @@ class CpuProfile { ...@@ -209,12 +209,15 @@ class CpuProfile {
void AddPath(const Vector<CodeEntry*>& path); void AddPath(const Vector<CodeEntry*>& path);
void CalculateTotalTicksAndSamplingRate(); void CalculateTotalTicksAndSamplingRate();
INLINE(const char* title() const) { return title_; } const char* title() const { return title_; }
INLINE(unsigned uid() const) { return uid_; } unsigned uid() const { return uid_; }
INLINE(const ProfileTree* top_down() const) { return &top_down_; } const ProfileTree* top_down() const { return &top_down_; }
INLINE(int samples_count() const) { return samples_.length(); } int samples_count() const { return samples_.length(); }
INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); } ProfileNode* sample(int index) const { return samples_.at(index); }
double start_time_ms() const { return start_time_ms_; }
double end_time_ms() const { return end_time_ms_; }
void UpdateTicksScale(); void UpdateTicksScale();
......
...@@ -410,6 +410,21 @@ TEST(GetProfilerWhenIsolateIsNotInitialized) { ...@@ -410,6 +410,21 @@ TEST(GetProfilerWhenIsolateIsNotInitialized) {
} }
TEST(ProfileStartEndTime) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
double time_before_profiling = i::OS::TimeCurrentMillis();
v8::Local<v8::String> profile_name = v8::String::New("test");
cpu_profiler->StartCpuProfiling(profile_name);
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
CHECK(time_before_profiling <= profile->GetStartTime());
CHECK(profile->GetStartTime() <= profile->GetEndTime());
CHECK(profile->GetEndTime() <= i::OS::TimeCurrentMillis());
}
static const v8::CpuProfile* RunProfiler( static const v8::CpuProfile* RunProfiler(
LocalContext& env, v8::Handle<v8::Function> function, LocalContext& env, v8::Handle<v8::Function> function,
v8::Handle<v8::Value> argv[], int argc, v8::Handle<v8::Value> argv[], int argc,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment