Revision: 16142
Author:   [email protected]
Date:     Fri Aug  9 13:55:58 2013
Log:      Merged r16039, r16067 into trunk branch.

Add start and end profiling time to v8::CpuProfile

Return start/end profiling time in microseconds instead of milliseconds

BUG=267595,v8:2824
[email protected]

Review URL: https://codereview.chromium.org/22634010
http://code.google.com/p/v8/source/detail?r=16142

Modified:
 /trunk/include/v8-profiler.h
 /trunk/src/api.cc
 /trunk/src/profile-generator.cc
 /trunk/src/profile-generator.h
 /trunk/src/version.cc
 /trunk/test/cctest/test-cpu-profiler.cc

=======================================
--- /trunk/include/v8-profiler.h        Fri Aug  9 13:02:11 2013
+++ /trunk/include/v8-profiler.h        Fri Aug  9 13:55:58 2013
@@ -148,6 +148,18 @@
     */
   const CpuProfileNode* GetSample(int index) const;

+  /**
+    * Returns time when the profile recording started (in microseconds
+    * since the Epoch).
+    */
+  int64_t GetStartTime() const;
+
+  /**
+    * Returns time when the profile recording was stopped (in microseconds
+    * since the Epoch).
+    */
+  int64_t GetEndTime() const;
+
   /**
    * Deletes the profile and removes it from CpuProfiler's list.
    * All pointers to nodes previously returned become invalid.
=======================================
--- /trunk/src/api.cc   Fri Aug  9 13:02:11 2013
+++ /trunk/src/api.cc   Fri Aug  9 13:55:58 2013
@@ -7565,6 +7565,18 @@
const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   return reinterpret_cast<const CpuProfileNode*>(profile->sample(index));
 }
+
+
+int64_t CpuProfile::GetStartTime() const {
+ const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
+  return profile->start_time_us();
+}
+
+
+int64_t CpuProfile::GetEndTime() const {
+ const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
+  return profile->end_time_us();
+}


 int CpuProfile::GetSamplesCount() const {
=======================================
--- /trunk/src/profile-generator.cc     Fri Aug  9 13:02:11 2013
+++ /trunk/src/profile-generator.cc     Fri Aug  9 13:55:58 2013
@@ -376,8 +376,8 @@
     : title_(title),
       uid_(uid),
       record_samples_(record_samples),
-      start_time_ms_(OS::TimeCurrentMillis()),
-      end_time_ms_(0) {
+      start_time_us_(OS::Ticks()),
+      end_time_us_(0) {
 }


@@ -388,13 +388,13 @@


 void CpuProfile::CalculateTotalTicksAndSamplingRate() {
-  end_time_ms_ = OS::TimeCurrentMillis();
+  end_time_us_ = OS::Ticks();
   top_down_.CalculateTotalTicks();

-  double duration = end_time_ms_ - start_time_ms_;
-  if (duration < 1) duration = 1;
+  double duration_ms = (end_time_us_ - start_time_us_) / 1000.;
+  if (duration_ms < 1) duration_ms = 1;
   unsigned ticks = top_down_.root()->total_ticks();
-  double rate = ticks / duration;
+  double rate = ticks / duration_ms;
   top_down_.SetTickRatePerMs(rate);
 }

=======================================
--- /trunk/src/profile-generator.h      Fri Aug  9 13:02:11 2013
+++ /trunk/src/profile-generator.h      Fri Aug  9 13:55:58 2013
@@ -209,12 +209,15 @@
   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); }
+
+  int64_t start_time_us() const { return start_time_us_; }
+  int64_t end_time_us() const { return end_time_us_; }

   void UpdateTicksScale();

@@ -225,8 +228,8 @@
   const char* title_;
   unsigned uid_;
   bool record_samples_;
-  double start_time_ms_;
-  double end_time_ms_;
+  int64_t start_time_us_;
+  int64_t end_time_us_;
   List<ProfileNode*> samples_;
   ProfileTree top_down_;

=======================================
--- /trunk/src/version.cc       Fri Aug  9 13:02:11 2013
+++ /trunk/src/version.cc       Fri Aug  9 13:55:58 2013
@@ -35,7 +35,7 @@
 #define MAJOR_VERSION     3
 #define MINOR_VERSION     20
 #define BUILD_NUMBER      15
-#define PATCH_LEVEL       0
+#define PATCH_LEVEL       1
 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
 #define IS_CANDIDATE_VERSION 0
=======================================
--- /trunk/test/cctest/test-cpu-profiler.cc     Fri Aug  9 13:02:11 2013
+++ /trunk/test/cctest/test-cpu-profiler.cc     Fri Aug  9 13:55:58 2013
@@ -408,6 +408,21 @@
   isolate->Dispose();
   CHECK_EQ(NULL, isolate->GetCpuProfiler());
 }
+
+
+TEST(ProfileStartEndTime) {
+  LocalContext env;
+  v8::HandleScope scope(env->GetIsolate());
+  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
+
+  int64_t time_before_profiling = i::OS::Ticks();
+  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::Ticks());
+}


 static const v8::CpuProfile* RunProfiler(

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