Revision: 2574
Author: [email protected]
Date: Wed Jul 29 04:23:36 2009
Log: Add generic V8 API functions for controlling profiling aspects.

As we'll have several aspects of heap profiling, it is more handy to  
control them using binary flags than by individual functions. CPU profiling  
represent just a particular aspect to control, so {Pause,Resume}Profiler  
and IsProfilerPaused are only left for compatibility.

For now, PROFILER_FLAG_HEAP_STATS and PROFILER_FLAG_JS_CONSTRUCTOR are  
equivalent, but later will be split.

Review URL: http://codereview.chromium.org/159581
http://code.google.com/p/v8/source/detail?r=2574

Modified:
  /branches/bleeding_edge/include/v8.h
  /branches/bleeding_edge/src/api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Jul 28 01:43:51 2009
+++ /branches/bleeding_edge/include/v8.h        Wed Jul 29 04:23:36 2009
@@ -1966,6 +1966,20 @@
  typedef Persistent<Context> (*ContextGenerator)();


+/**
+ * Profiler modules.
+ *
+ * In V8, profiler consists of several modules: CPU profiler, and different
+ * kinds of heap profiling. Each can be turned on / off independently.
+ */
+enum ProfilerModules {
+  PROFILER_MODULE_NONE            = 0,
+  PROFILER_MODULE_CPU             = 1,
+  PROFILER_MODULE_HEAP_STATS      = 1 << 1,
+  PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2
+};
+
+
  /**
   * Container class for static utility functions.
   */
@@ -2119,6 +2133,32 @@
     */
    static bool IsProfilerPaused();

+  /**
+   * Resumes specified profiler modules.
+   * "ResumeProfiler" is equivalent  
to "ResumeProfilerEx(PROFILER_MODULE_CPU)".
+   * See ProfilerModules enum.
+   *
+   * \param flags Flags specifying profiler modules.
+   */
+  static void ResumeProfilerEx(int flags);
+
+  /**
+   * Pauses specified profiler modules.
+   * "PauseProfiler" is equivalent  
to "PauseProfilerEx(PROFILER_MODULE_CPU)".
+   * See ProfilerModules enum.
+   *
+   * \param flags Flags specifying profiler modules.
+   */
+  static void PauseProfilerEx(int flags);
+
+  /**
+   * Returns active (resumed) profiler modules.
+   * See ProfilerModules enum.
+   *
+   * \returns active profiler modules.
+   */
+  static int GetActiveProfilerModules();
+
    /**
     * If logging is performed into a memory buffer (via --logfile=*),  
allows to
     * retrieve previously written messages. This can be used for retrieving
=======================================
--- /branches/bleeding_edge/src/api.cc  Tue Jul 28 01:43:51 2009
+++ /branches/bleeding_edge/src/api.cc  Wed Jul 29 04:23:36 2009
@@ -3233,6 +3233,46 @@
    return true;
  #endif
  }
+
+
+void V8::ResumeProfilerEx(int flags) {
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  if (flags & PROFILER_MODULE_CPU) {
+    i::Logger::ResumeProfiler();
+  }
+  if (flags & (PROFILER_MODULE_HEAP_STATS |  
PROFILER_MODULE_JS_CONSTRUCTORS)) {
+    i::FLAG_log_gc = true;
+  }
+#endif
+}
+
+
+void V8::PauseProfilerEx(int flags) {
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  if (flags & PROFILER_MODULE_CPU) {
+    i::Logger::PauseProfiler();
+  }
+  if (flags & (PROFILER_MODULE_HEAP_STATS |  
PROFILER_MODULE_JS_CONSTRUCTORS)) {
+    i::FLAG_log_gc = false;
+  }
+#endif
+}
+
+
+int V8::GetActiveProfilerModules() {
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  int result = PROFILER_MODULE_NONE;
+  if (!i::Logger::IsProfilerPaused()) {
+    result |= PROFILER_MODULE_CPU;
+  }
+  if (i::FLAG_log_gc) {
+    result |= PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS;
+  }
+  return result;
+#else
+  return PROFILER_MODULE_NONE;
+#endif
+}


  int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to