exceptions: Bump submodule back to master
[ghc.git] / rts / Trace.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 2008-2009
4 *
5 * Support for fast binary event logging and user-space dtrace probes.
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #pragma once
10
11 #include "rts/EventLogFormat.h"
12 #include "sm/NonMovingCensus.h"
13 #include "Capability.h"
14
15 #if defined(DTRACE)
16 #include "RtsProbes.h"
17 #endif /* defined(DTRACE) */
18
19 #include "BeginPrivate.h"
20
21 // -----------------------------------------------------------------------------
22 // EventLog API
23 // -----------------------------------------------------------------------------
24
25 #if defined(TRACING)
26
27 void initTracing (void);
28 void endTracing (void);
29 void freeTracing (void);
30 void resetTracing (void);
31 void tracingAddCapapilities (uint32_t from, uint32_t to);
32
33 #endif /* TRACING */
34
35 typedef StgWord32 CapsetID;
36 typedef StgWord16 CapsetType;
37 enum CapsetType { CapsetTypeCustom = CAPSET_TYPE_CUSTOM,
38 CapsetTypeOsProcess = CAPSET_TYPE_OSPROCESS,
39 CapsetTypeClockdomain = CAPSET_TYPE_CLOCKDOMAIN };
40 #define CAPSET_OSPROCESS_DEFAULT ((CapsetID)0)
41 #define CAPSET_HEAP_DEFAULT ((CapsetID)0) /* reusing the same capset */
42 #define CAPSET_CLOCKDOMAIN_DEFAULT ((CapsetID)1)
43
44 // -----------------------------------------------------------------------------
45 // Message classes
46 // -----------------------------------------------------------------------------
47
48 // shorthand for RtsFlags.DebugFlags.<blah>, useful with debugTrace()
49 #define DEBUG_sched RtsFlags.DebugFlags.scheduler
50 #define DEBUG_interp RtsFlags.DebugFlags.interp
51 #define DEBUG_weak RtsFlags.DebugFlags.weak
52 #define DEBUG_gccafs RtsFlags.DebugFlags.gccafs
53 #define DEBUG_gc RtsFlags.DebugFlags.gc
54 #define DEBUG_nonmoving_gc RtsFlags.DebugFlags.nonmoving_gc
55 #define DEBUG_block_alloc RtsFlags.DebugFlags.alloc
56 #define DEBUG_sanity RtsFlags.DebugFlags.sanity
57 #define DEBUG_zero_on_gc RtsFlags.DebugFlags.zero_on_gc
58 #define DEBUG_stable RtsFlags.DebugFlags.stable
59 #define DEBUG_stm RtsFlags.DebugFlags.stm
60 #define DEBUG_prof RtsFlags.DebugFlags.prof
61 #define DEBUG_gran RtsFlags.DebugFlags.gran
62 #define DEBUG_par RtsFlags.DebugFlags.par
63 #define DEBUG_linker RtsFlags.DebugFlags.linker
64 #define DEBUG_squeeze RtsFlags.DebugFlags.squeeze
65 #define DEBUG_hpc RtsFlags.DebugFlags.hpc
66 #define DEBUG_sparks RtsFlags.DebugFlags.sparks
67 #define DEBUG_compact RtsFlags.DebugFlags.compact
68
69 // events
70 extern int TRACE_sched;
71 extern int TRACE_gc;
72 extern int TRACE_spark_sampled;
73 extern int TRACE_spark_full;
74 /* extern int TRACE_user; */ // only used in Trace.c
75 extern int TRACE_cap;
76 extern int TRACE_nonmoving_gc;
77
78 // -----------------------------------------------------------------------------
79 // Posting events
80 //
81 // We use macros rather than inline functions deliberately. We want
82 // the not-taken case to be as efficient as possible, a simple
83 // test-and-jump, and with inline functions gcc seemed to move some of
84 // the instructions from the branch up before the test.
85 //
86 // -----------------------------------------------------------------------------
87
88 #if defined(DEBUG)
89 void traceBegin (const char *str, ...);
90 void traceEnd (void);
91 #endif
92
93 #if defined(TRACING)
94
95 /*
96 * Record a scheduler event
97 */
98 #define traceSchedEvent(cap, tag, tso, other) \
99 if (RTS_UNLIKELY(TRACE_sched)) { \
100 traceSchedEvent_(cap, tag, tso, other, 0); \
101 }
102
103 #define traceSchedEvent2(cap, tag, tso, info1, info2) \
104 if (RTS_UNLIKELY(TRACE_sched)) { \
105 traceSchedEvent_(cap, tag, tso, info1, info2); \
106 }
107
108 void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
109 StgTSO *tso, StgWord info1, StgWord info2);
110
111 /*
112 * Record a GC event
113 */
114 #define traceGcEvent(cap, tag) \
115 if (RTS_UNLIKELY(TRACE_gc)) { \
116 traceGcEvent_(cap, tag); \
117 }
118
119 void traceGcEvent_ (Capability *cap, EventTypeNum tag);
120
121 /*
122 * Record a GC event at the explicitly given timestamp
123 */
124 #define traceGcEventAtT(cap, ts, tag) \
125 if (RTS_UNLIKELY(TRACE_gc)) { \
126 traceGcEventAtT_(cap, ts, tag); \
127 }
128
129 void traceGcEventAtT_ (Capability *cap, StgWord64 ts, EventTypeNum tag);
130
131 /*
132 * Record a heap event
133 */
134 #define traceHeapEvent(cap, tag, heap_capset, info1) \
135 if (RTS_UNLIKELY(TRACE_gc)) { \
136 traceHeapEvent_(cap, tag, heap_capset, info1); \
137 }
138 void traceHeapEvent_ (Capability *cap,
139 EventTypeNum tag,
140 CapsetID heap_capset,
141 W_ info1);
142
143 void traceEventHeapInfo_ (CapsetID heap_capset,
144 uint32_t gens,
145 W_ maxHeapSize,
146 W_ allocAreaSize,
147 W_ mblockSize,
148 W_ blockSize);
149
150 void traceEventGcStats_ (Capability *cap,
151 CapsetID heap_capset,
152 uint32_t gen,
153 W_ copied,
154 W_ slop,
155 W_ fragmentation,
156 uint32_t par_n_threads,
157 W_ par_max_copied,
158 W_ par_tot_copied,
159 W_ par_balanced_copied);
160
161 /*
162 * Record a spark event
163 */
164 #define traceSparkEvent(cap, tag) \
165 if (RTS_UNLIKELY(TRACE_spark_full)) { \
166 traceSparkEvent_(cap, tag, 0); \
167 }
168
169 #define traceSparkEvent2(cap, tag, other) \
170 if (RTS_UNLIKELY(TRACE_spark_full)) { \
171 traceSparkEvent_(cap, tag, other); \
172 }
173
174 void traceSparkEvent_ (Capability *cap, EventTypeNum tag, StgWord info1);
175
176 // variadic macros are C99, and supported by gcc. However, the
177 // ##__VA_ARGS syntax is a gcc extension, which allows the variable
178 // argument list to be empty (see gcc docs for details).
179
180 /*
181 * Emit a trace message on a particular Capability
182 */
183 #define traceCap(class, cap, msg, ...) \
184 if (RTS_UNLIKELY(class)) { \
185 traceCap_(cap, msg, ##__VA_ARGS__); \
186 }
187
188 void traceCap_(Capability *cap, char *msg, ...);
189
190 /*
191 * Emit a trace message
192 */
193 #define trace(class, msg, ...) \
194 if (RTS_UNLIKELY(class)) { \
195 trace_(msg, ##__VA_ARGS__); \
196 }
197
198 void trace_(char *msg, ...);
199
200 /*
201 * A message or event emitted by the program
202 * Used by Debug.Trace.{traceEvent, traceEventIO}
203 */
204 void traceUserMsg(Capability *cap, char *msg);
205
206 /*
207 * A marker event emitted by the program
208 * Used by Debug.Trace.{traceMarker, traceMarkerIO}
209 */
210 void traceUserMarker(Capability *cap, char *msg);
211
212 /*
213 * A binary message or event emitted by the program
214 */
215 void traceUserBinaryMsg(Capability *cap, uint8_t *msg, size_t size);
216
217 /*
218 * An event to record a Haskell thread's label/name
219 * Used by GHC.Conc.labelThread
220 */
221 void traceThreadLabel_(Capability *cap,
222 StgTSO *tso,
223 char *label);
224
225 /*
226 * Emit a debug message (only when DEBUG is defined)
227 */
228 #if defined(DEBUG)
229 #define debugTrace(class, msg, ...) \
230 if (RTS_UNLIKELY(class)) { \
231 trace_(msg, ##__VA_ARGS__); \
232 }
233 #else
234 #define debugTrace(class, str, ...) /* nothing */
235 #endif
236
237 #if defined(DEBUG)
238 #define debugTraceCap(class, cap, msg, ...) \
239 if (RTS_UNLIKELY(class)) { \
240 traceCap_(cap, msg, ##__VA_ARGS__); \
241 }
242 #else
243 #define debugTraceCap(class, cap, str, ...) /* nothing */
244 #endif
245
246 /*
247 * Emit a message/event describing the state of a thread
248 */
249 #define traceThreadStatus(class, tso) \
250 if (RTS_UNLIKELY(class)) { \
251 traceThreadStatus_(tso); \
252 }
253
254 void traceThreadStatus_ (StgTSO *tso);
255
256 /*
257 * Events for describing capabilities and capability sets in the eventlog
258 */
259 #define traceCapEvent(cap, tag) \
260 if (RTS_UNLIKELY(TRACE_cap)) { \
261 traceCapEvent_(cap, tag); \
262 }
263
264 void traceCapEvent_ (Capability *cap,
265 EventTypeNum tag);
266
267 #define traceCapsetEvent(cap, capset, info) \
268 if (RTS_UNLIKELY(TRACE_cap)) { \
269 traceCapsetEvent_(cap, capset, info); \
270 }
271
272 void traceCapsetEvent_ (EventTypeNum tag,
273 CapsetID capset,
274 StgWord info);
275
276 void traceWallClockTime_(void);
277
278 void traceOSProcessInfo_ (void);
279
280 void traceSparkCounters_ (Capability *cap,
281 SparkCounters counters,
282 StgWord remaining);
283
284 void traceTaskCreate_ (Task *task,
285 Capability *cap);
286
287 void traceTaskMigrate_ (Task *task,
288 Capability *cap,
289 Capability *new_cap);
290
291 void traceTaskDelete_ (Task *task);
292
293 void traceHeapProfBegin(StgWord8 profile_id);
294 void traceHeapProfSampleBegin(StgInt era);
295 void traceHeapBioProfSampleBegin(StgInt era, StgWord64 time);
296 void traceHeapProfSampleEnd(StgInt era);
297 void traceHeapProfSampleString(StgWord8 profile_id,
298 const char *label, StgWord residency);
299 #if defined(PROFILING)
300 void traceHeapProfCostCentre(StgWord32 ccID,
301 const char *label,
302 const char *module,
303 const char *srcloc,
304 StgBool is_caf);
305 void traceHeapProfSampleCostCentre(StgWord8 profile_id,
306 CostCentreStack *stack, StgWord residency);
307
308 void traceProfSampleCostCentre(Capability *cap,
309 CostCentreStack *stack, StgWord ticks);
310 void traceProfBegin(void);
311 #endif /* PROFILING */
312
313 void traceConcMarkBegin(void);
314 void traceConcMarkEnd(StgWord32 marked_obj_count);
315 void traceConcSyncBegin(void);
316 void traceConcSyncEnd(void);
317 void traceConcSweepBegin(void);
318 void traceConcSweepEnd(void);
319 void traceConcUpdRemSetFlush(Capability *cap);
320 void traceNonmovingHeapCensus(uint32_t log_blk_size,
321 const struct NonmovingAllocCensus *census);
322
323 void flushTrace(void);
324
325 #else /* !TRACING */
326
327 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
328 #define traceSchedEvent2(cap, tag, tso, other, info) /* nothing */
329 #define traceGcEvent(cap, tag) /* nothing */
330 #define traceGcEventAtT(cap, ts, tag) /* nothing */
331 #define traceEventGcStats_(cap, heap_capset, gen, \
332 copied, slop, fragmentation, \
333 par_n_threads, par_max_copied, \
334 par_tot_copied, par_balanced_copied) /* nothing */
335 #define traceHeapEvent(cap, tag, heap_capset, info1) /* nothing */
336 #define traceEventHeapInfo_(heap_capset, gens, \
337 maxHeapSize, allocAreaSize, \
338 mblockSize, blockSize) /* nothing */
339 #define traceSparkEvent(cap, tag) /* nothing */
340 #define traceSparkEvent2(cap, tag, other) /* nothing */
341 #define traceCap(class, cap, msg, ...) /* nothing */
342 #define trace(class, msg, ...) /* nothing */
343 #define debugTrace(class, str, ...) /* nothing */
344 #define debugTraceCap(class, cap, str, ...) /* nothing */
345 #define traceThreadStatus(class, tso) /* nothing */
346 #define traceThreadLabel_(cap, tso, label) /* nothing */
347 #define traceCapEvent(cap, tag) /* nothing */
348 #define traceCapsetEvent(tag, capset, info) /* nothing */
349 #define traceWallClockTime_() /* nothing */
350 #define traceOSProcessInfo_() /* nothing */
351 #define traceSparkCounters_(cap, counters, remaining) /* nothing */
352 #define traceTaskCreate_(taskID, cap) /* nothing */
353 #define traceTaskMigrate_(taskID, cap, new_cap) /* nothing */
354 #define traceTaskDelete_(taskID) /* nothing */
355 #define traceHeapProfBegin(profile_id) /* nothing */
356 #define traceHeapProfCostCentre(ccID, label, module, srcloc, is_caf) /* nothing */
357 #define traceHeapProfSampleBegin(era) /* nothing */
358 #define traceHeapBioProfSampleBegin(era, time) /* nothing */
359 #define traceHeapProfSampleEnd(era) /* nothing */
360 #define traceHeapProfSampleCostCentre(profile_id, stack, residency) /* nothing */
361 #define traceHeapProfSampleString(profile_id, label, residency) /* nothing */
362
363 #define traceConcMarkBegin() /* nothing */
364 #define traceConcMarkEnd(marked_obj_count) /* nothing */
365 #define traceConcSyncBegin() /* nothing */
366 #define traceConcSyncEnd() /* nothing */
367 #define traceConcSweepBegin() /* nothing */
368 #define traceConcSweepEnd() /* nothing */
369 #define traceConcUpdRemSetFlush(cap) /* nothing */
370 #define traceNonmovingHeapCensus(blk_size, census) /* nothing */
371
372 #define flushTrace() /* nothing */
373
374 #endif /* TRACING */
375
376 // If DTRACE is enabled, but neither DEBUG nor TRACING, we need a C land
377 // wrapper for the user-msg probe (as we can't expand that in PrimOps.cmm)
378 //
379 #if !defined(DEBUG) && !defined(TRACING) && defined(DTRACE)
380
381 void dtraceUserMsgWrapper(Capability *cap, char *msg);
382 void dtraceUserMarkerWrapper(Capability *cap, char *msg);
383
384 #endif /* !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) */
385
386 // -----------------------------------------------------------------------------
387 // Aliases for static dtrace probes if dtrace is available
388 // -----------------------------------------------------------------------------
389
390 #if defined(DTRACE)
391
392 #define dtraceCreateThread(cap, tid) \
393 HASKELLEVENT_CREATE_THREAD(cap, tid)
394 #define dtraceRunThread(cap, tid) \
395 HASKELLEVENT_RUN_THREAD(cap, tid)
396 #define dtraceStopThread(cap, tid, status, info) \
397 HASKELLEVENT_STOP_THREAD(cap, tid, status, info)
398 #define dtraceThreadRunnable(cap, tid) \
399 HASKELLEVENT_THREAD_RUNNABLE(cap, tid)
400 #define dtraceMigrateThread(cap, tid, new_cap) \
401 HASKELLEVENT_MIGRATE_THREAD(cap, tid, new_cap)
402 #define dtraceThreadWakeup(cap, tid, other_cap) \
403 HASKELLEVENT_THREAD_WAKEUP(cap, tid, other_cap)
404 #define dtraceGcStart(cap) \
405 HASKELLEVENT_GC_START(cap)
406 #define dtraceGcEnd(cap) \
407 HASKELLEVENT_GC_END(cap)
408 #define dtraceRequestSeqGc(cap) \
409 HASKELLEVENT_REQUEST_SEQ_GC(cap)
410 #define dtraceRequestParGc(cap) \
411 HASKELLEVENT_REQUEST_PAR_GC(cap)
412 #define dtraceCreateSparkThread(cap, spark_tid) \
413 HASKELLEVENT_CREATE_SPARK_THREAD(cap, spark_tid)
414 #define dtraceThreadLabel(cap, tso, label) \
415 HASKELLEVENT_THREAD_LABEL(cap, tso, label)
416 #define dtraceCapCreate(cap) \
417 HASKELLEVENT_CAP_CREATE(cap)
418 #define dtraceCapDelete(cap) \
419 HASKELLEVENT_CAP_DELETE(cap)
420 #define dtraceCapEnable(cap) \
421 HASKELLEVENT_CAP_ENABLE(cap)
422 #define dtraceCapDisable(cap) \
423 HASKELLEVENT_CAP_DISABLE(cap)
424 #define dtraceUserMsg(cap, msg) \
425 HASKELLEVENT_USER_MSG(cap, msg)
426 #define dtraceUserMarker(cap, msg) \
427 HASKELLEVENT_USER_MARKER(cap, msg)
428 #define dtraceGcIdle(cap) \
429 HASKELLEVENT_GC_IDLE(cap)
430 #define dtraceGcWork(cap) \
431 HASKELLEVENT_GC_WORK(cap)
432 #define dtraceGcDone(cap) \
433 HASKELLEVENT_GC_DONE(cap)
434 #define dtraceGcGlobalSync(cap) \
435 HASKELLEVENT_GC_GLOBAL_SYNC(cap)
436 #define dtraceEventGcStats(heap_capset, gens, \
437 copies, slop, fragmentation, \
438 par_n_threads, \
439 par_max_copied, \
440 par_tot_copied, \
441 par_balanced_copied) \
442 HASKELLEVENT_GC_STATS(heap_capset, gens, \
443 copies, slop, fragmentation, \
444 par_n_threads, \
445 par_max_copied, \
446 par_balanced_copied, \
447 par_tot_copied)
448 #define dtraceHeapInfo(heap_capset, gens, \
449 maxHeapSize, allocAreaSize, \
450 mblockSize, blockSize) \
451 HASKELLEVENT_HEAP_INFO(heap_capset, gens, \
452 maxHeapSize, allocAreaSize, \
453 mblockSize, blockSize)
454 #define dtraceEventHeapAllocated(cap, heap_capset, \
455 allocated) \
456 HASKELLEVENT_HEAP_ALLOCATED(cap, heap_capset, \
457 allocated)
458 #define dtraceEventHeapSize(heap_capset, size) \
459 HASKELLEVENT_HEAP_SIZE(heap_capset, size)
460 #define dtraceEventHeapLive(heap_capset, live) \
461 HASKELLEVENT_HEAP_LIVE(heap_capset, live)
462 #define dtraceCapsetCreate(capset, capset_type) \
463 HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
464 #define dtraceCapsetDelete(capset) \
465 HASKELLEVENT_CAPSET_DELETE(capset)
466 #define dtraceCapsetAssignCap(capset, capno) \
467 HASKELLEVENT_CAPSET_ASSIGN_CAP(capset, capno)
468 #define dtraceCapsetRemoveCap(capset, capno) \
469 HASKELLEVENT_CAPSET_REMOVE_CAP(capset, capno)
470 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) \
471 HASKELLEVENT_SPARK_COUNTERS(cap, a, b, c, d, e, f, g)
472 #define dtraceSparkCreate(cap) \
473 HASKELLEVENT_SPARK_CREATE(cap)
474 #define dtraceSparkDud(cap) \
475 HASKELLEVENT_SPARK_DUD(cap)
476 #define dtraceSparkOverflow(cap) \
477 HASKELLEVENT_SPARK_OVERFLOW(cap)
478 #define dtraceSparkRun(cap) \
479 HASKELLEVENT_SPARK_RUN(cap)
480 #define dtraceSparkSteal(cap, victim_cap) \
481 HASKELLEVENT_SPARK_STEAL(cap, victim_cap)
482 #define dtraceSparkFizzle(cap) \
483 HASKELLEVENT_SPARK_FIZZLE(cap)
484 #define dtraceSparkGc(cap) \
485 HASKELLEVENT_SPARK_GC(cap)
486 #define dtraceTaskCreate(taskID, cap, tid) \
487 HASKELLEVENT_TASK_CREATE(taskID, cap, tid)
488 #define dtraceTaskMigrate(taskID, cap, new_cap) \
489 HASKELLEVENT_TASK_MIGRATE(taskID, cap, new_cap)
490 #define dtraceTaskDelete(taskID) \
491 HASKELLEVENT_TASK_DELETE(taskID)
492
493 #else /* !defined(DTRACE) */
494
495 #define dtraceCreateThread(cap, tid) /* nothing */
496 #define dtraceRunThread(cap, tid) /* nothing */
497 #define dtraceStopThread(cap, tid, status, info) /* nothing */
498 #define dtraceThreadRunnable(cap, tid) /* nothing */
499 #define dtraceMigrateThread(cap, tid, new_cap) /* nothing */
500 #define dtraceThreadWakeup(cap, tid, other_cap) /* nothing */
501 #define dtraceGcStart(cap) /* nothing */
502 #define dtraceGcEnd(cap) /* nothing */
503 #define dtraceRequestSeqGc(cap) /* nothing */
504 #define dtraceRequestParGc(cap) /* nothing */
505 #define dtraceCreateSparkThread(cap, spark_tid) /* nothing */
506 #define dtraceThreadLabel(cap, tso, label) /* nothing */
507 #define dtraceUserMsg(cap, msg) /* nothing */
508 #define dtraceUserMarker(cap, msg) /* nothing */
509 #define dtraceGcIdle(cap) /* nothing */
510 #define dtraceGcWork(cap) /* nothing */
511 #define dtraceGcDone(cap) /* nothing */
512 #define dtraceGcGlobalSync(cap) /* nothing */
513 #define dtraceEventGcStats(heap_capset, gens, \
514 copies, slop, fragmentation, \
515 par_n_threads, \
516 par_max_copied, \
517 par_tot_copied, \
518 par_balanced_copied) /* nothing */
519 #define dtraceHeapInfo(heap_capset, gens, \
520 maxHeapSize, allocAreaSize, \
521 mblockSize, blockSize) /* nothing */
522 #define dtraceEventHeapAllocated(cap, heap_capset, \
523 allocated) /* nothing */
524 #define dtraceEventHeapSize(heap_capset, size) /* nothing */
525 #define dtraceEventHeapLive(heap_capset, live) /* nothing */
526 #define dtraceCapCreate(cap) /* nothing */
527 #define dtraceCapDelete(cap) /* nothing */
528 #define dtraceCapEnable(cap) /* nothing */
529 #define dtraceCapDisable(cap) /* nothing */
530 #define dtraceCapsetCreate(capset, capset_type) /* nothing */
531 #define dtraceCapsetDelete(capset) /* nothing */
532 #define dtraceCapsetAssignCap(capset, capno) /* nothing */
533 #define dtraceCapsetRemoveCap(capset, capno) /* nothing */
534 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) /* nothing */
535 #define dtraceSparkCreate(cap) /* nothing */
536 #define dtraceSparkDud(cap) /* nothing */
537 #define dtraceSparkOverflow(cap) /* nothing */
538 #define dtraceSparkRun(cap) /* nothing */
539 #define dtraceSparkSteal(cap, victim_cap) /* nothing */
540 #define dtraceSparkFizzle(cap) /* nothing */
541 #define dtraceSparkGc(cap) /* nothing */
542 #define dtraceTaskCreate(taskID, cap, tid) /* nothing */
543 #define dtraceTaskMigrate(taskID, cap, new_cap) /* nothing */
544 #define dtraceTaskDelete(taskID) /* nothing */
545
546 #endif
547
548 // -----------------------------------------------------------------------------
549 // Trace probes dispatching to various tracing frameworks
550 //
551 // In order to avoid accumulating multiple calls to tracing calls at trace
552 // points, we define inline probe functions that contain the various
553 // invocations.
554 //
555 // Dtrace - dtrace probes are unconditionally added as probe activation is
556 // handled by the dtrace component of the kernel, and inactive probes are
557 // very cheap - usually, one no-op. Consequently, dtrace can be used with
558 // all flavours of the RTS. In addition, we still support logging events to
559 // a file, even in the presence of dtrace. This is, eg, useful when tracing
560 // on a server, but browsing trace information with ThreadScope on a local
561 // client.
562 //
563 // -----------------------------------------------------------------------------
564
565 INLINE_HEADER void traceEventCreateThread(Capability *cap STG_UNUSED,
566 StgTSO *tso STG_UNUSED)
567 {
568 traceSchedEvent(cap, EVENT_CREATE_THREAD, tso, tso->stackobj->stack_size);
569 dtraceCreateThread((EventCapNo)cap->no, (EventThreadID)tso->id);
570 }
571
572 INLINE_HEADER void traceEventRunThread(Capability *cap STG_UNUSED,
573 StgTSO *tso STG_UNUSED)
574 {
575 traceSchedEvent(cap, EVENT_RUN_THREAD, tso, tso->what_next);
576 dtraceRunThread((EventCapNo)cap->no, (EventThreadID)tso->id);
577 }
578
579 INLINE_HEADER void traceEventStopThread(Capability *cap STG_UNUSED,
580 StgTSO *tso STG_UNUSED,
581 StgThreadReturnCode status STG_UNUSED,
582 StgWord32 info STG_UNUSED)
583 {
584 traceSchedEvent2(cap, EVENT_STOP_THREAD, tso, status, info);
585 dtraceStopThread((EventCapNo)cap->no, (EventThreadID)tso->id,
586 (EventThreadStatus)status, (EventThreadID)info);
587 }
588
589 INLINE_HEADER void traceEventMigrateThread(Capability *cap STG_UNUSED,
590 StgTSO *tso STG_UNUSED,
591 uint32_t new_cap STG_UNUSED)
592 {
593 traceSchedEvent(cap, EVENT_MIGRATE_THREAD, tso, new_cap);
594 dtraceMigrateThread((EventCapNo)cap->no, (EventThreadID)tso->id,
595 (EventCapNo)new_cap);
596 }
597
598 INLINE_HEADER void traceCapCreate(Capability *cap STG_UNUSED)
599 {
600 traceCapEvent(cap, EVENT_CAP_CREATE);
601 dtraceCapCreate((EventCapNo)cap->no);
602 }
603
604 INLINE_HEADER void traceCapDelete(Capability *cap STG_UNUSED)
605 {
606 traceCapEvent(cap, EVENT_CAP_DELETE);
607 dtraceCapDelete((EventCapNo)cap->no);
608 }
609
610 INLINE_HEADER void traceCapEnable(Capability *cap STG_UNUSED)
611 {
612 traceCapEvent(cap, EVENT_CAP_ENABLE);
613 dtraceCapEnable((EventCapNo)cap->no);
614 }
615
616 INLINE_HEADER void traceCapDisable(Capability *cap STG_UNUSED)
617 {
618 traceCapEvent(cap, EVENT_CAP_DISABLE);
619 dtraceCapDisable((EventCapNo)cap->no);
620 }
621
622 INLINE_HEADER void traceEventThreadWakeup(Capability *cap STG_UNUSED,
623 StgTSO *tso STG_UNUSED,
624 uint32_t other_cap STG_UNUSED)
625 {
626 traceSchedEvent(cap, EVENT_THREAD_WAKEUP, tso, other_cap);
627 dtraceThreadWakeup((EventCapNo)cap->no, (EventThreadID)tso->id,
628 (EventCapNo)other_cap);
629 }
630
631 INLINE_HEADER void traceThreadLabel(Capability *cap STG_UNUSED,
632 StgTSO *tso STG_UNUSED,
633 char *label STG_UNUSED)
634 {
635 if (RTS_UNLIKELY(TRACE_sched)) {
636 traceThreadLabel_(cap, tso, label);
637 }
638 dtraceThreadLabel((EventCapNo)cap->no, (EventThreadID)tso->id, label);
639 }
640
641 INLINE_HEADER void traceEventGcStart(Capability *cap STG_UNUSED)
642 {
643 traceGcEvent(cap, EVENT_GC_START);
644 dtraceGcStart((EventCapNo)cap->no);
645 }
646
647 INLINE_HEADER void traceEventGcStartAtT(Capability *cap STG_UNUSED,
648 StgWord64 ts STG_UNUSED)
649 {
650 traceGcEventAtT(cap, ts, EVENT_GC_START);
651 dtraceGcStart((EventCapNo)cap->no);
652 }
653
654 INLINE_HEADER void traceEventGcEnd(Capability *cap STG_UNUSED)
655 {
656 traceGcEvent(cap, EVENT_GC_END);
657 dtraceGcEnd((EventCapNo)cap->no);
658 }
659
660 INLINE_HEADER void traceEventGcEndAtT(Capability *cap STG_UNUSED,
661 StgWord64 ts STG_UNUSED)
662 {
663 traceGcEventAtT(cap, ts, EVENT_GC_END);
664 dtraceGcEnd((EventCapNo)cap->no);
665 }
666
667 INLINE_HEADER void traceEventRequestSeqGc(Capability *cap STG_UNUSED)
668 {
669 traceGcEvent(cap, EVENT_REQUEST_SEQ_GC);
670 dtraceRequestSeqGc((EventCapNo)cap->no);
671 }
672
673 INLINE_HEADER void traceEventRequestParGc(Capability *cap STG_UNUSED)
674 {
675 traceGcEvent(cap, EVENT_REQUEST_PAR_GC);
676 dtraceRequestParGc((EventCapNo)cap->no);
677 }
678
679 INLINE_HEADER void traceEventGcIdle(Capability *cap STG_UNUSED)
680 {
681 traceGcEvent(cap, EVENT_GC_IDLE);
682 dtraceGcIdle((EventCapNo)cap->no);
683 }
684
685 INLINE_HEADER void traceEventGcWork(Capability *cap STG_UNUSED)
686 {
687 traceGcEvent(cap, EVENT_GC_WORK);
688 dtraceGcWork((EventCapNo)cap->no);
689 }
690
691 INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
692 {
693 traceGcEvent(cap, EVENT_GC_DONE);
694 dtraceGcDone((EventCapNo)cap->no);
695 }
696
697 INLINE_HEADER void traceEventGcGlobalSync(Capability *cap STG_UNUSED)
698 {
699 traceGcEvent(cap, EVENT_GC_GLOBAL_SYNC);
700 dtraceGcGlobalSync((EventCapNo)cap->no);
701 }
702
703 INLINE_HEADER void traceEventGcStats(Capability *cap STG_UNUSED,
704 CapsetID heap_capset STG_UNUSED,
705 uint32_t gen STG_UNUSED,
706 W_ copied STG_UNUSED,
707 W_ slop STG_UNUSED,
708 W_ fragmentation STG_UNUSED,
709 uint32_t par_n_threads STG_UNUSED,
710 W_ par_max_copied STG_UNUSED,
711 W_ par_tot_copied STG_UNUSED,
712 W_ par_balanced_copied STG_UNUSED)
713 {
714 if (RTS_UNLIKELY(TRACE_gc)) {
715 traceEventGcStats_(cap, heap_capset, gen,
716 copied, slop, fragmentation,
717 par_n_threads, par_max_copied,
718 par_tot_copied, par_balanced_copied);
719 }
720 dtraceEventGcStats(heap_capset, gen,
721 copied, slop, fragmentation,
722 par_n_threads, par_max_copied,
723 par_tot_copied, par_balanced_copied);
724 }
725
726 INLINE_HEADER void traceEventHeapInfo(CapsetID heap_capset STG_UNUSED,
727 uint32_t gens STG_UNUSED,
728 W_ maxHeapSize STG_UNUSED,
729 W_ allocAreaSize STG_UNUSED,
730 W_ mblockSize STG_UNUSED,
731 W_ blockSize STG_UNUSED)
732 {
733 if (RTS_UNLIKELY(TRACE_gc)) {
734 traceEventHeapInfo_(heap_capset, gens,
735 maxHeapSize, allocAreaSize,
736 mblockSize, blockSize);
737 }
738 dtraceHeapInfo(heap_capset, gens,
739 maxHeapSize, allocAreaSize,
740 mblockSize, blockSize);
741 }
742
743 INLINE_HEADER void traceEventHeapAllocated(Capability *cap STG_UNUSED,
744 CapsetID heap_capset STG_UNUSED,
745 W_ allocated STG_UNUSED)
746 {
747 traceHeapEvent(cap, EVENT_HEAP_ALLOCATED, heap_capset, allocated);
748 dtraceEventHeapAllocated((EventCapNo)cap->no, heap_capset, allocated);
749 }
750
751 INLINE_HEADER void traceEventHeapSize(Capability *cap STG_UNUSED,
752 CapsetID heap_capset STG_UNUSED,
753 W_ heap_size STG_UNUSED)
754 {
755 traceHeapEvent(cap, EVENT_HEAP_SIZE, heap_capset, heap_size);
756 dtraceEventHeapSize(heap_capset, heap_size);
757 }
758
759 INLINE_HEADER void traceEventHeapLive(Capability *cap STG_UNUSED,
760 CapsetID heap_capset STG_UNUSED,
761 W_ heap_live STG_UNUSED)
762 {
763 traceHeapEvent(cap, EVENT_HEAP_LIVE, heap_capset, heap_live);
764 dtraceEventHeapLive(heap_capset, heap_live);
765 }
766
767 INLINE_HEADER void traceCapsetCreate(CapsetID capset STG_UNUSED,
768 CapsetType capset_type STG_UNUSED)
769 {
770 traceCapsetEvent(EVENT_CAPSET_CREATE, capset, capset_type);
771 dtraceCapsetCreate(capset, capset_type);
772 }
773
774 INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
775 {
776 traceCapsetEvent(EVENT_CAPSET_DELETE, capset, 0);
777 dtraceCapsetDelete(capset);
778 }
779
780 INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
781 uint32_t capno STG_UNUSED)
782 {
783 traceCapsetEvent(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
784 dtraceCapsetAssignCap(capset, capno);
785 }
786
787 INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
788 uint32_t capno STG_UNUSED)
789 {
790 traceCapsetEvent(EVENT_CAPSET_REMOVE_CAP, capset, capno);
791 dtraceCapsetRemoveCap(capset, capno);
792 }
793
794 INLINE_HEADER void traceWallClockTime(void)
795 {
796 traceWallClockTime_();
797 /* Note: no DTrace equivalent because it is available to DTrace directly */
798 }
799
800 INLINE_HEADER void traceOSProcessInfo(void)
801 {
802 traceOSProcessInfo_();
803 /* Note: no DTrace equivalent because all this OS process info
804 * is available to DTrace directly */
805 }
806
807 INLINE_HEADER void traceEventCreateSparkThread(Capability *cap STG_UNUSED,
808 StgThreadID spark_tid STG_UNUSED)
809 {
810 traceSparkEvent2(cap, EVENT_CREATE_SPARK_THREAD, spark_tid);
811 dtraceCreateSparkThread((EventCapNo)cap->no, (EventThreadID)spark_tid);
812 }
813
814 INLINE_HEADER void traceSparkCounters(Capability *cap STG_UNUSED)
815 {
816 #if defined(THREADED_RTS)
817 if (RTS_UNLIKELY(TRACE_spark_sampled)) {
818 traceSparkCounters_(cap, cap->spark_stats, sparkPoolSize(cap->sparks));
819 }
820 dtraceSparkCounters((EventCapNo)cap->no,
821 cap->spark_stats.created,
822 cap->spark_stats.dud,
823 cap->spark_stats.overflowed,
824 cap->spark_stats.converted,
825 cap->spark_stats.gcd,
826 cap->spark_stats.fizzled,
827 sparkPoolSize(cap->sparks));
828 #endif
829 }
830
831 INLINE_HEADER void traceEventSparkCreate(Capability *cap STG_UNUSED)
832 {
833 traceSparkEvent(cap, EVENT_SPARK_CREATE);
834 dtraceSparkCreate((EventCapNo)cap->no);
835 }
836
837 INLINE_HEADER void traceEventSparkDud(Capability *cap STG_UNUSED)
838 {
839 traceSparkEvent(cap, EVENT_SPARK_DUD);
840 dtraceSparkDud((EventCapNo)cap->no);
841 }
842
843 INLINE_HEADER void traceEventSparkOverflow(Capability *cap STG_UNUSED)
844 {
845 traceSparkEvent(cap, EVENT_SPARK_OVERFLOW);
846 dtraceSparkOverflow((EventCapNo)cap->no);
847 }
848
849 INLINE_HEADER void traceEventSparkRun(Capability *cap STG_UNUSED)
850 {
851 traceSparkEvent(cap, EVENT_SPARK_RUN);
852 dtraceSparkRun((EventCapNo)cap->no);
853 }
854
855 INLINE_HEADER void traceEventSparkSteal(Capability *cap STG_UNUSED,
856 uint32_t victim_cap STG_UNUSED)
857 {
858 traceSparkEvent2(cap, EVENT_SPARK_STEAL, victim_cap);
859 dtraceSparkSteal((EventCapNo)cap->no, (EventCapNo)victim_cap);
860 }
861
862 INLINE_HEADER void traceEventSparkFizzle(Capability *cap STG_UNUSED)
863 {
864 traceSparkEvent(cap, EVENT_SPARK_FIZZLE);
865 dtraceSparkFizzle((EventCapNo)cap->no);
866 }
867
868 INLINE_HEADER void traceEventSparkGC(Capability *cap STG_UNUSED)
869 {
870 traceSparkEvent(cap, EVENT_SPARK_GC);
871 dtraceSparkGc((EventCapNo)cap->no);
872 }
873
874 INLINE_HEADER void traceTaskCreate(Task *task STG_UNUSED,
875 Capability *cap STG_UNUSED)
876 {
877 ASSERT(task->cap == cap);
878 // TODO: asserting task->cap == NULL would be much stronger
879 // (the intention being that the task structure is just created and empty)
880 // but would require large changes of traceTaskCreate calls.
881 ASSERT(cap != NULL);
882 // A new task gets associated with a cap. We also record
883 // the kernel thread id of the task, which should never change.
884 if (RTS_UNLIKELY(TRACE_sched)) {
885 traceTaskCreate_(task, cap);
886 }
887 dtraceTaskCreate(serialisableTaskId(task),
888 (EventCapNo)cap->no,
889 kernelThreadId());
890 }
891
892 INLINE_HEADER void traceTaskMigrate(Task *task STG_UNUSED,
893 Capability *cap STG_UNUSED,
894 Capability *new_cap STG_UNUSED)
895 {
896 ASSERT(task->cap == cap);
897 ASSERT(cap != NULL);
898 ASSERT(cap != new_cap);
899 ASSERT(new_cap != NULL);
900 // A task migrates from a cap to another.
901 if (RTS_UNLIKELY(TRACE_sched)) {
902 traceTaskMigrate_(task, cap, new_cap);
903 }
904 dtraceTaskMigrate(serialisableTaskId(task), (EventCapNo)cap->no,
905 (EventCapNo)new_cap->no);
906 }
907
908 INLINE_HEADER void traceTaskDelete(Task *task STG_UNUSED)
909 {
910 ASSERT(task->cap != NULL);
911 if (RTS_UNLIKELY(TRACE_sched)) {
912 traceTaskDelete_(task);
913 }
914 dtraceTaskDelete(serialisableTaskId(task));
915 }
916
917 #include "EndPrivate.h"