Only trace cap/capset events if we're tracing anything else
authorSimon Marlow <marlowsd@gmail.com>
Tue, 2 Aug 2016 08:57:19 +0000 (09:57 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 3 Aug 2016 07:07:34 +0000 (08:07 +0100)
Summary:
I was getting annoyed by cap/capset messages when using +RTS -DS, which
doesn't cause any other trace messages to be emitted.  This makes it
possible to add --with-rtsopts=-DS when running tests, and not have all
the tests fail due to spurious trace messages.

Test Plan: validate

Reviewers: duncan, bgamari, ezyang, austin, erikd

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2438

rts/Trace.c
rts/Trace.h

index fdf8049..0dc05d5 100644 (file)
@@ -51,6 +51,7 @@ int TRACE_gc;
 int TRACE_spark_sampled;
 int TRACE_spark_full;
 int TRACE_user;
+int TRACE_cap;
 
 #ifdef THREADED_RTS
 static Mutex trace_utx;
@@ -114,6 +115,14 @@ void initTracing (void)
     TRACE_user =
         RtsFlags.TraceFlags.user;
 
+    // We trace cap events if we're tracing anything else
+    TRACE_cap =
+        TRACE_sched ||
+        TRACE_gc ||
+        TRACE_spark_sampled ||
+        TRACE_spark_full ||
+        TRACE_user;
+
     eventlog_enabled = RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG;
 
     /* Note: we can have any of the TRACE_* flags turned on even when
@@ -378,8 +387,8 @@ void traceEventGcStats_  (Capability *cap,
     }
 }
 
-void traceCapEvent (Capability   *cap,
-                    EventTypeNum  tag)
+void traceCapEvent_ (Capability   *cap,
+                     EventTypeNum  tag)
 {
 #ifdef DEBUG
     if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
@@ -410,9 +419,9 @@ void traceCapEvent (Capability   *cap,
     }
 }
 
-void traceCapsetEvent (EventTypeNum tag,
-                       CapsetID     capset,
-                       StgWord      info)
+void traceCapsetEvent_ (EventTypeNum tag,
+                        CapsetID     capset,
+                        StgWord      info)
 {
 #ifdef DEBUG
     if (RtsFlags.TraceFlags.tracing == TRACE_STDERR && TRACE_sched)
index ab79671..8b531f1 100644 (file)
@@ -69,6 +69,7 @@ extern int TRACE_gc;
 extern int TRACE_spark_sampled;
 extern int TRACE_spark_full;
 /* extern int TRACE_user; */  // only used in Trace.c
+extern int TRACE_cap;
 
 // -----------------------------------------------------------------------------
 // Posting events
@@ -244,19 +245,23 @@ void traceThreadStatus_ (StgTSO *tso);
 
 /*
  * Events for describing capabilities and capability sets in the eventlog
- *
- * Note: unlike other events, these are not conditional on TRACE_sched or
- * similar because capabilities and capability sets are important
- * context for other events. Since other events depend on these events
- * then for simplicity we always emit them, rather than working out if
- * they're necessary . They should be very low volume.
  */
-void traceCapEvent (Capability   *cap,
+#define traceCapEvent(cap, tag)                 \
+    if (RTS_UNLIKELY(TRACE_cap)) {              \
+        traceCapEvent_(cap, tag);               \
+    }
+
+void traceCapEvent_ (Capability   *cap,
                     EventTypeNum  tag);
 
-void traceCapsetEvent (EventTypeNum tag,
-                       CapsetID     capset,
-                       StgWord      info);
+#define traceCapsetEvent(cap, capset, info)     \
+    if (RTS_UNLIKELY(TRACE_cap)) {              \
+        traceCapsetEvent_(cap, capset, info);   \
+    }
+
+void traceCapsetEvent_ (EventTypeNum tag,
+                        CapsetID     capset,
+                        StgWord      info);
 
 void traceWallClockTime_(void);