Reviewers: alph, loislo, Benedikt Meurer,

Description:
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

Please review this at https://codereview.chromium.org/21918002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M include/v8-profiler.h
  M src/api.cc
  M src/profile-generator.h
  M test/cctest/test-cpu-profiler.cc


Index: include/v8-profiler.h
diff --git a/include/v8-profiler.h b/include/v8-profiler.h
index cf2834130053656f5ecd7d30d08d1f0627544d40..c4450599f096ba8d7baedff0ee4a51b8a4e490a8 100644
--- a/include/v8-profiler.h
+++ b/include/v8-profiler.h
@@ -149,6 +149,18 @@ class V8EXPORT CpuProfile {
   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.
    * All pointers to nodes previously returned become invalid.
    * Profiles with the same uid but obtained using different
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index d442126ebbb3c23babfa8cec218edf2fd630480c..60627a39710443b4aef0b17ab570af6a1cc6c4bd 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -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 {
   return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
 }
Index: src/profile-generator.h
diff --git a/src/profile-generator.h b/src/profile-generator.h
index 7861ccd81785f3670a3d609ede6321717e0d5eac..ce2dd307e3183f9ef55082da14a590429c740586 100644
--- a/src/profile-generator.h
+++ b/src/profile-generator.h
@@ -209,12 +209,15 @@ class CpuProfile {
   void AddPath(const Vector<CodeEntry*>& path);
   void CalculateTotalTicksAndSamplingRate();

-  INLINE(const char* title() const) { return title_; }
-  INLINE(unsigned uid() const) { return uid_; }
-  INLINE(const ProfileTree* top_down() const) { return &top_down_; }
+  const char* title() const { return title_; }
+  unsigned uid() const { return uid_; }
+  const ProfileTree* top_down() const { return &top_down_; }

-  INLINE(int samples_count() const) { return samples_.length(); }
- INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); }
+  int samples_count() const { return samples_.length(); }
+  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();

Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index d9ecc41a7499e39094fc644f2c79799c7d474b3c..3f0fb802b9772c57d4709c096f53e6fdc723e7f6 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -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(
     LocalContext& env, v8::Handle<v8::Function> function,
     v8::Handle<v8::Value> argv[], int argc,


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to