Commit aaaaf67b authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add an RTS eventlog tracing class for user messages

Enables people to turn them on/off. Defaults to on.
parent 6f5b798b
...@@ -131,6 +131,7 @@ struct TRACE_FLAGS { ...@@ -131,6 +131,7 @@ struct TRACE_FLAGS {
rtsBool gc; /* trace GC events */ rtsBool gc; /* trace GC events */
rtsBool sparks_sampled; /* trace spark events by a sampled method */ rtsBool sparks_sampled; /* trace spark events by a sampled method */
rtsBool sparks_full; /* trace spark events 100% accurately */ rtsBool sparks_full; /* trace spark events 100% accurately */
rtsBool user; /* trace user events (emitted from Haskell code) */
}; };
struct CONCURRENT_FLAGS { struct CONCURRENT_FLAGS {
......
...@@ -166,6 +166,7 @@ void initRtsFlagsDefaults(void) ...@@ -166,6 +166,7 @@ void initRtsFlagsDefaults(void)
RtsFlags.TraceFlags.gc = rtsFalse; RtsFlags.TraceFlags.gc = rtsFalse;
RtsFlags.TraceFlags.sparks_sampled= rtsFalse; RtsFlags.TraceFlags.sparks_sampled= rtsFalse;
RtsFlags.TraceFlags.sparks_full = rtsFalse; RtsFlags.TraceFlags.sparks_full = rtsFalse;
RtsFlags.TraceFlags.user = rtsFalse;
#endif #endif
RtsFlags.MiscFlags.tickInterval = 20; /* In milliseconds */ RtsFlags.MiscFlags.tickInterval = 20; /* In milliseconds */
...@@ -295,12 +296,13 @@ usage_text[] = { ...@@ -295,12 +296,13 @@ usage_text[] = {
" g GC events", " g GC events",
" p par spark events (sampled)", " p par spark events (sampled)",
" f par spark events (full detail)", " f par spark events (full detail)",
" u user events (emitted from Haskell code)",
" a all event classes above",
# ifdef DEBUG # ifdef DEBUG
" t add time stamps (only useful with -v)", " t add time stamps (only useful with -v)",
# endif # endif
" a all event classes above",
" -x disable an event class, for any flag above", " -x disable an event class, for any flag above",
" the initial enabled event classes are 'sgp'", " the initial enabled event classes are 'sgpu'",
#endif #endif
#if !defined(PROFILING) #if !defined(PROFILING)
...@@ -1466,6 +1468,7 @@ static void read_trace_flags(char *arg) ...@@ -1466,6 +1468,7 @@ static void read_trace_flags(char *arg)
RtsFlags.TraceFlags.scheduler = rtsTrue; RtsFlags.TraceFlags.scheduler = rtsTrue;
RtsFlags.TraceFlags.gc = rtsTrue; RtsFlags.TraceFlags.gc = rtsTrue;
RtsFlags.TraceFlags.sparks_sampled = rtsTrue; RtsFlags.TraceFlags.sparks_sampled = rtsTrue;
RtsFlags.TraceFlags.user = rtsTrue;
for (c = arg; *c != '\0'; c++) { for (c = arg; *c != '\0'; c++) {
switch(*c) { switch(*c) {
...@@ -1479,6 +1482,7 @@ static void read_trace_flags(char *arg) ...@@ -1479,6 +1482,7 @@ static void read_trace_flags(char *arg)
RtsFlags.TraceFlags.gc = enabled; RtsFlags.TraceFlags.gc = enabled;
RtsFlags.TraceFlags.sparks_sampled = enabled; RtsFlags.TraceFlags.sparks_sampled = enabled;
RtsFlags.TraceFlags.sparks_full = enabled; RtsFlags.TraceFlags.sparks_full = enabled;
RtsFlags.TraceFlags.user = enabled;
enabled = rtsTrue; enabled = rtsTrue;
break; break;
...@@ -1502,6 +1506,10 @@ static void read_trace_flags(char *arg) ...@@ -1502,6 +1506,10 @@ static void read_trace_flags(char *arg)
RtsFlags.TraceFlags.gc = enabled; RtsFlags.TraceFlags.gc = enabled;
enabled = rtsTrue; enabled = rtsTrue;
break; break;
case 'u':
RtsFlags.TraceFlags.user = enabled;
enabled = rtsTrue;
break;
default: default:
errorBelch("unknown trace option: %c",*c); errorBelch("unknown trace option: %c",*c);
break; break;
......
...@@ -50,6 +50,7 @@ int TRACE_sched; ...@@ -50,6 +50,7 @@ int TRACE_sched;
int TRACE_gc; int TRACE_gc;
int TRACE_spark_sampled; int TRACE_spark_sampled;
int TRACE_spark_full; int TRACE_spark_full;
int TRACE_user;
#ifdef THREADED_RTS #ifdef THREADED_RTS
static Mutex trace_utx; static Mutex trace_utx;
...@@ -106,9 +107,12 @@ void initTracing (void) ...@@ -106,9 +107,12 @@ void initTracing (void)
RtsFlags.TraceFlags.sparks_full || RtsFlags.TraceFlags.sparks_full ||
RtsFlags.DebugFlags.sparks; RtsFlags.DebugFlags.sparks;
TRACE_user =
RtsFlags.TraceFlags.user;
eventlog_enabled = RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG; eventlog_enabled = RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG;
/* Note: we can have TRACE_sched or TRACE_spark turned on even when /* Note: we can have any of the TRACE_* flags turned on even when
eventlog_enabled is off. In the DEBUG way we may be tracing to stderr. eventlog_enabled is off. In the DEBUG way we may be tracing to stderr.
*/ */
...@@ -521,13 +525,17 @@ static void traceFormatUserMsg(Capability *cap, char *msg, ...) ...@@ -521,13 +525,17 @@ static void traceFormatUserMsg(Capability *cap, char *msg, ...)
va_list ap; va_list ap;
va_start(ap,msg); va_start(ap,msg);
/* Note: normally we don't check the TRACE_* flags here as they're checked
by the wrappers in Trace.h. But traceUserMsg is special since it has no
wrapper (it's called from cmm code), so we check TRACE_user here
*/
#ifdef DEBUG #ifdef DEBUG
if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) { if (RtsFlags.TraceFlags.tracing == TRACE_STDERR && TRACE_user) {
traceCap_stderr(cap, msg, ap); traceCap_stderr(cap, msg, ap);
} else } else
#endif #endif
{ {
if (eventlog_enabled) { if (eventlog_enabled && TRACE_user) {
postUserMsg(cap, msg, ap); postUserMsg(cap, msg, ap);
} }
} }
......
...@@ -66,6 +66,7 @@ extern int TRACE_sched; ...@@ -66,6 +66,7 @@ extern int TRACE_sched;
extern int TRACE_gc; extern int TRACE_gc;
extern int TRACE_spark_sampled; extern int TRACE_spark_sampled;
extern int TRACE_spark_full; extern int TRACE_spark_full;
/* extern int TRACE_user; */ // only used in Trace.c
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Posting events // Posting events
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment