Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Unified Diff: src/counters.h

Issue 2296243002: [RuntimeCallStats] Move tracing runtime instrumentation closer to the original version. (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler.cc ('k') | src/counters.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/counters.h
diff --git a/src/counters.h b/src/counters.h
index 374f385f029519f424cd5d2c997f55072636e8f6..56f648c324cff0c36cdb63724a14330d278bd824 100644
--- a/src/counters.h
+++ b/src/counters.h
@@ -11,8 +11,10 @@
#include "src/base/platform/time.h"
#include "src/builtins/builtins.h"
#include "src/globals.h"
+#include "src/isolate.h"
#include "src/objects.h"
#include "src/runtime/runtime.h"
+#include "src/tracing/trace-event.h"
namespace v8 {
namespace internal {
@@ -770,67 +772,57 @@ class RuntimeCallStats {
// Starting measuring the time for a function. This will establish the
// connection to the parent counter for properly calculating the own times.
- static void Enter(Isolate* isolate, RuntimeCallTimer* timer,
+ static void Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
CounterId counter_id);
// Leave a scope for a measured runtime function. This will properly add
// the time delta to the current_counter and subtract the delta from its
// parent.
- static void Leave(Isolate* isolate, RuntimeCallTimer* timer);
+ static void Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer);
// Set counter id for the innermost measurement. It can be used to refine
// event kind when a runtime entry counter is too generic.
- static void CorrectCurrentCounterId(Isolate* isolate, CounterId counter_id);
+ static void CorrectCurrentCounterId(RuntimeCallStats* stats,
+ CounterId counter_id);
void Reset();
- void Print(std::ostream& os);
+ V8_NOINLINE void Print(std::ostream& os);
+ V8_NOINLINE const char* Dump();
+
+ RuntimeCallStats() {
+ Reset();
+ in_use_ = false;
+ }
- RuntimeCallStats() { Reset(); }
RuntimeCallTimer* current_timer() { return current_timer_; }
+ bool InUse() { return in_use_; }
private:
+ std::stringstream buffer_;
+ std::unique_ptr<char[]> buffer_c_str_;
+ size_t len_ = 0;
// Counter to track recursive time events.
RuntimeCallTimer* current_timer_ = NULL;
+ bool in_use_;
};
-#define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \
- do { \
- if (FLAG_runtime_call_stats) { \
- RuntimeCallStats::CorrectCurrentCounterId( \
- isolate, &RuntimeCallStats::counter_name); \
- } \
+#define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \
+ do { \
+ if (FLAG_runtime_call_stats) { \
+ RuntimeCallStats::CorrectCurrentCounterId( \
+ isolate->counters()->runtime_call_stats(), \
+ &RuntimeCallStats::counter_name); \
+ } \
+ if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) { \
+ RuntimeCallStats::CorrectCurrentCounterId( \
+ isolate->counters()->tracing_runtime_call_stats(), \
+ &RuntimeCallStats::counter_name); \
+ } \
} while (false)
#define TRACE_HANDLER_STATS(isolate, counter_name) \
TRACE_RUNTIME_CALL_STATS(isolate, Handler_##counter_name)
-// A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
-// the time of C++ scope.
-class RuntimeCallTimerScope {
- public:
- inline RuntimeCallTimerScope(Isolate* isolate,
- RuntimeCallStats::CounterId counter_id) {
- if (V8_UNLIKELY(FLAG_runtime_call_stats)) {
- isolate_ = isolate;
- RuntimeCallStats::Enter(isolate_, &timer_, counter_id);
- }
- }
- // This constructor is here just to avoid calling GetIsolate() when the
- // stats are disabled and the isolate is not directly available.
- inline RuntimeCallTimerScope(HeapObject* heap_object,
- RuntimeCallStats::CounterId counter_id);
-
- inline ~RuntimeCallTimerScope() {
- if (V8_UNLIKELY(FLAG_runtime_call_stats)) {
- RuntimeCallStats::Leave(isolate_, &timer_);
- }
- }
-
- private:
- Isolate* isolate_;
- RuntimeCallTimer timer_;
-};
-
#define HISTOGRAM_RANGE_LIST(HR) \
/* Generic range histograms */ \
HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
@@ -1173,6 +1165,9 @@ class Counters {
void ResetCounters();
void ResetHistograms();
RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; }
+ RuntimeCallStats* tracing_runtime_call_stats() {
+ return &tracing_runtime_call_stats_;
+ }
private:
#define HR(name, caption, min, max, num_buckets) Histogram name##_;
@@ -1235,6 +1230,7 @@ class Counters {
#undef SC
RuntimeCallStats runtime_call_stats_;
+ RuntimeCallStats tracing_runtime_call_stats_;
friend class Isolate;
@@ -1243,6 +1239,52 @@ class Counters {
DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
};
+// A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the
+// the time of C++ scope.
+class RuntimeCallTimerScope {
+ public:
+ inline RuntimeCallTimerScope(Isolate* isolate,
+ RuntimeCallStats::CounterId counter_id) {
+ if (V8_UNLIKELY(FLAG_runtime_call_stats)) {
+ isolate_ = isolate;
+ RuntimeCallStats::Enter(isolate_->counters()->runtime_call_stats(),
+ &timer_, counter_id);
+ }
+ if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) {
+ isolate_for_tracing_ = isolate;
+ RuntimeCallStats::Enter(
+ isolate_for_tracing_->counters()->tracing_runtime_call_stats(),
+ &trace_event_timer_, counter_id);
+ }
+ }
+ // This constructor is here just to avoid calling GetIsolate() when the
+ // stats are disabled and the isolate is not directly available.
+ inline RuntimeCallTimerScope(HeapObject* heap_object,
+ RuntimeCallStats::CounterId counter_id);
+
+ inline ~RuntimeCallTimerScope() {
+ if (V8_UNLIKELY(FLAG_runtime_call_stats)) {
+ RuntimeCallStats::Leave(isolate_->counters()->runtime_call_stats(),
+ &timer_);
+ }
+ if (V8_UNLIKELY(isolate_for_tracing_ != nullptr)) {
+ RuntimeCallStats::Leave(
+ isolate_for_tracing_->counters()->tracing_runtime_call_stats(),
+ &trace_event_timer_);
+ isolate_for_tracing_ = nullptr;
+ }
+ }
+
+ private:
+ Isolate* isolate_;
+ // TODO(lpy): --runtime-call-stats and tracing should be mutually exclusive
+ // with tracing taking precendence. We need to add checks, and use a single
+ // isolate reference and a timer for both.
+ Isolate* isolate_for_tracing_ = nullptr;
+ RuntimeCallTimer timer_;
+ RuntimeCallTimer trace_event_timer_;
+};
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler.cc ('k') | src/counters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698