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