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