Reviewers: Dmitry Lomov (chromium),

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

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

SVN Base: https://v8.googlecode.com/svn/trunk

Affected files:
  M include/v8-profiler.h
  M src/api.cc
  M src/profile-generator.h
  M src/profile-generator.cc
  M src/version.cc
  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..7898fef1967f0c86df5fd6d94fde20d3575eb423 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 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.
    * Profiles with the same uid but obtained using different
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index b80d1be8d2ebb46b1e660fad25c5b71d5793a78c..bf630cb3af0bd5fff26060eab931da6e9b0dbfd1 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -7567,6 +7567,18 @@ const CpuProfileNode* CpuProfile::GetSample(int index) const {
 }


+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 {
   return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
 }
Index: src/profile-generator.cc
diff --git a/src/profile-generator.cc b/src/profile-generator.cc
index 4e2e38988a34a29b7f3331bd18532cf01c9bb131..e772a546471e029665960a62020399d5fe096aad 100644
--- a/src/profile-generator.cc
+++ b/src/profile-generator.cc
@@ -376,8 +376,8 @@ CpuProfile::CpuProfile(const char* title, unsigned uid, bool record_samples)
     : 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::AddPath(const Vector<CodeEntry*>& path) {


 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);
 }

Index: src/profile-generator.h
diff --git a/src/profile-generator.h b/src/profile-generator.h
index 7861ccd81785f3670a3d609ede6321717e0d5eac..0cc397ed9bf24583d5d12f69b078157b19176312 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); }
+
+  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 @@ class CpuProfile {
   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_;

Index: src/version.cc
diff --git a/src/version.cc b/src/version.cc
index 2acc01ce7e72017ffcf817d6839ee08e6831703b..a6cbeb8d6c72f890179fab5642a025d240306f5f 100644
--- a/src/version.cc
+++ b/src/version.cc
@@ -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
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..daf8db615142001fcebab78e6103e5137f427179 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();
+
+  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(
     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