Fix #15038
[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 "Capability.h"
13
14 #if defined(DTRACE)
15 #include "RtsProbes.h"
16 #endif /* defined(DTRACE) */
17
18 #include "BeginPrivate.h"
19
20 // -----------------------------------------------------------------------------
21 // EventLog API
22 // -----------------------------------------------------------------------------
23
24 #if defined(TRACING)
25
26 void initTracing (void);
27 void endTracing (void);
28 void freeTracing (void);
29 void resetTracing (void);
30 void tracingAddCapapilities (uint32_t from, uint32_t to);
31
32 #endif /* TRACING */
33
34 typedef StgWord32 CapsetID;
35 typedef StgWord16 CapsetType;
36 enum CapsetType { CapsetTypeCustom = CAPSET_TYPE_CUSTOM,
37 CapsetTypeOsProcess = CAPSET_TYPE_OSPROCESS,
38 CapsetTypeClockdomain = CAPSET_TYPE_CLOCKDOMAIN };
39 #define CAPSET_OSPROCESS_DEFAULT ((CapsetID)0)
40 #define CAPSET_HEAP_DEFAULT ((CapsetID)0) /* reusing the same capset */
41 #define CAPSET_CLOCKDOMAIN_DEFAULT ((CapsetID)1)
42
43 // -----------------------------------------------------------------------------
44 // Message classes
45 // -----------------------------------------------------------------------------
46
47 // shorthand for RtsFlags.DebugFlags.<blah>, useful with debugTrace()
48 #define DEBUG_sched RtsFlags.DebugFlags.scheduler
49 #define DEBUG_interp RtsFlags.DebugFlags.interp
50 #define DEBUG_weak RtsFlags.DebugFlags.weak
51 #define DEBUG_gccafs RtsFlags.DebugFlags.gccafs
52 #define DEBUG_gc RtsFlags.DebugFlags.gc
53 #define DEBUG_block_alloc RtsFlags.DebugFlags.alloc
54 #define DEBUG_sanity RtsFlags.DebugFlags.sanity
55 #define DEBUG_stable RtsFlags.DebugFlags.stable
56 #define DEBUG_stm RtsFlags.DebugFlags.stm
57 #define DEBUG_prof RtsFlags.DebugFlags.prof
58 #define DEBUG_gran RtsFlags.DebugFlags.gran
59 #define DEBUG_par RtsFlags.DebugFlags.par
60 #define DEBUG_linker RtsFlags.DebugFlags.linker
61 #define DEBUG_squeeze RtsFlags.DebugFlags.squeeze
62 #define DEBUG_hpc RtsFlags.DebugFlags.hpc
63 #define DEBUG_sparks RtsFlags.DebugFlags.sparks
64 #define DEBUG_compact RtsFlags.DebugFlags.compact
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 extern int TRACE_cap;
73
74 // -----------------------------------------------------------------------------
75 // Posting events
76 //
77 // We use macros rather than inline functions deliberately. We want
78 // the not-taken case to be as efficient as possible, a simple
79 // test-and-jump, and with inline functions gcc seemed to move some of
80 // the instructions from the branch up before the test.
81 //
82 // -----------------------------------------------------------------------------
83
84 #if defined(DEBUG)
85 void traceBegin (const char *str, ...);
86 void traceEnd (void);
87 #endif
88
89 #if defined(TRACING)
90
91 /*
92 * Record a scheduler event
93 */
94 #define traceSchedEvent(cap, tag, tso, other) \
95 if (RTS_UNLIKELY(TRACE_sched)) { \
96 traceSchedEvent_(cap, tag, tso, other, 0); \
97 }
98
99 #define traceSchedEvent2(cap, tag, tso, info1, info2) \
100 if (RTS_UNLIKELY(TRACE_sched)) { \
101 traceSchedEvent_(cap, tag, tso, info1, info2); \
102 }
103
104 void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
105 StgTSO *tso, StgWord info1, StgWord info2);
106
107 /*
108 * Record a GC event
109 */
110 #define traceGcEvent(cap, tag) \
111 if (RTS_UNLIKELY(TRACE_gc)) { \
112 traceGcEvent_(cap, tag); \
113 }
114
115 void traceGcEvent_ (Capability *cap, EventTypeNum tag);
116
117 /*
118 * Record a GC event at the explicitly given timestamp
119 */
120 #define traceGcEventAtT(cap, ts, tag) \
121 if (RTS_UNLIKELY(TRACE_gc)) { \
122 traceGcEventAtT_(cap, ts, tag); \
123 }
124
125 void traceGcEventAtT_ (Capability *cap, StgWord64 ts, EventTypeNum tag);
126
127 /*
128 * Record a heap event
129 */
130 #define traceHeapEvent(cap, tag, heap_capset, info1) \
131 if (RTS_UNLIKELY(TRACE_gc)) { \
132 traceHeapEvent_(cap, tag, heap_capset, info1); \
133 }
134 void traceHeapEvent_ (Capability *cap,
135 EventTypeNum tag,
136 CapsetID heap_capset,
137 W_ info1);
138
139 void traceEventHeapInfo_ (CapsetID heap_capset,
140 uint32_t gens,
141 W_ maxHeapSize,
142 W_ allocAreaSize,
143 W_ mblockSize,
144 W_ blockSize);
145
146 void traceEventGcStats_ (Capability *cap,
147 CapsetID heap_capset,
148 uint32_t gen,
149 W_ copied,
150 W_ slop,
151 W_ fragmentation,
152 uint32_t par_n_threads,
153 W_ par_max_copied,
154 W_ par_tot_copied,
155 W_ par_balanced_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 #if defined(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 #if defined(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 #if defined(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, \
307 par_tot_copied, par_balanced_copied) /* nothing */
308 #define traceHeapEvent(cap, tag, heap_capset, info1) /* nothing */
309 #define traceEventHeapInfo_(heap_capset, gens, \
310 maxHeapSize, allocAreaSize, \
311 mblockSize, blockSize) /* nothing */
312 #define traceSparkEvent(cap, tag) /* nothing */
313 #define traceSparkEvent2(cap, tag, other) /* nothing */
314 #define traceCap(class, cap, msg, ...) /* nothing */
315 #define trace(class, msg, ...) /* nothing */
316 #define debugTrace(class, str, ...) /* nothing */
317 #define debugTraceCap(class, cap, str, ...) /* nothing */
318 #define traceThreadStatus(class, tso) /* nothing */
319 #define traceThreadLabel_(cap, tso, label) /* nothing */
320 #define traceCapEvent(cap, tag) /* nothing */
321 #define traceCapsetEvent(tag, capset, info) /* nothing */
322 #define traceWallClockTime_() /* nothing */
323 #define traceOSProcessInfo_() /* nothing */
324 #define traceSparkCounters_(cap, counters, remaining) /* nothing */
325 #define traceTaskCreate_(taskID, cap) /* nothing */
326 #define traceTaskMigrate_(taskID, cap, new_cap) /* nothing */
327 #define traceTaskDelete_(taskID) /* nothing */
328 #define traceHeapProfBegin(profile_id) /* nothing */
329 #define traceHeapProfCostCentre(ccID, label, module, srcloc, is_caf) /* nothing */
330 #define traceHeapProfSampleBegin(era) /* nothing */
331 #define traceHeapProfSampleCostCentre(profile_id, stack, residency) /* nothing */
332 #define traceHeapProfSampleString(profile_id, label, residency) /* nothing */
333
334 #endif /* TRACING */
335
336 // If DTRACE is enabled, but neither DEBUG nor TRACING, we need a C land
337 // wrapper for the user-msg probe (as we can't expand that in PrimOps.cmm)
338 //
339 #if !defined(DEBUG) && !defined(TRACING) && defined(DTRACE)
340
341 void dtraceUserMsgWrapper(Capability *cap, char *msg);
342 void dtraceUserMarkerWrapper(Capability *cap, char *msg);
343
344 #endif /* !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) */
345
346 // -----------------------------------------------------------------------------
347 // Aliases for static dtrace probes if dtrace is available
348 // -----------------------------------------------------------------------------
349
350 #if defined(DTRACE)
351
352 #define dtraceCreateThread(cap, tid) \
353 HASKELLEVENT_CREATE_THREAD(cap, tid)
354 #define dtraceRunThread(cap, tid) \
355 HASKELLEVENT_RUN_THREAD(cap, tid)
356 #define dtraceStopThread(cap, tid, status, info) \
357 HASKELLEVENT_STOP_THREAD(cap, tid, status, info)
358 #define dtraceThreadRunnable(cap, tid) \
359 HASKELLEVENT_THREAD_RUNNABLE(cap, tid)
360 #define dtraceMigrateThread(cap, tid, new_cap) \
361 HASKELLEVENT_MIGRATE_THREAD(cap, tid, new_cap)
362 #define dtraceThreadWakeup(cap, tid, other_cap) \
363 HASKELLEVENT_THREAD_WAKEUP(cap, tid, other_cap)
364 #define dtraceGcStart(cap) \
365 HASKELLEVENT_GC_START(cap)
366 #define dtraceGcEnd(cap) \
367 HASKELLEVENT_GC_END(cap)
368 #define dtraceRequestSeqGc(cap) \
369 HASKELLEVENT_REQUEST_SEQ_GC(cap)
370 #define dtraceRequestParGc(cap) \
371 HASKELLEVENT_REQUEST_PAR_GC(cap)
372 #define dtraceCreateSparkThread(cap, spark_tid) \
373 HASKELLEVENT_CREATE_SPARK_THREAD(cap, spark_tid)
374 #define dtraceThreadLabel(cap, tso, label) \
375 HASKELLEVENT_THREAD_LABEL(cap, tso, label)
376 #define dtraceCapCreate(cap) \
377 HASKELLEVENT_CAP_CREATE(cap)
378 #define dtraceCapDelete(cap) \
379 HASKELLEVENT_CAP_DELETE(cap)
380 #define dtraceCapEnable(cap) \
381 HASKELLEVENT_CAP_ENABLE(cap)
382 #define dtraceCapDisable(cap) \
383 HASKELLEVENT_CAP_DISABLE(cap)
384 #define dtraceUserMsg(cap, msg) \
385 HASKELLEVENT_USER_MSG(cap, msg)
386 #define dtraceUserMarker(cap, msg) \
387 HASKELLEVENT_USER_MARKER(cap, msg)
388 #define dtraceGcIdle(cap) \
389 HASKELLEVENT_GC_IDLE(cap)
390 #define dtraceGcWork(cap) \
391 HASKELLEVENT_GC_WORK(cap)
392 #define dtraceGcDone(cap) \
393 HASKELLEVENT_GC_DONE(cap)
394 #define dtraceGcGlobalSync(cap) \
395 HASKELLEVENT_GC_GLOBAL_SYNC(cap)
396 #define dtraceEventGcStats(heap_capset, gens, \
397 copies, slop, fragmentation, \
398 par_n_threads, \
399 par_max_copied, \
400 par_tot_copied, \
401 par_balanced_copied) \
402 HASKELLEVENT_GC_STATS(heap_capset, gens, \
403 copies, slop, fragmentation, \
404 par_n_threads, \
405 par_max_copied, \
406 par_balanced_copied, \
407 par_tot_copied)
408 #define dtraceHeapInfo(heap_capset, gens, \
409 maxHeapSize, allocAreaSize, \
410 mblockSize, blockSize) \
411 HASKELLEVENT_HEAP_INFO(heap_capset, gens, \
412 maxHeapSize, allocAreaSize, \
413 mblockSize, blockSize)
414 #define dtraceEventHeapAllocated(cap, heap_capset, \
415 allocated) \
416 HASKELLEVENT_HEAP_ALLOCATED(cap, heap_capset, \
417 allocated)
418 #define dtraceEventHeapSize(heap_capset, size) \
419 HASKELLEVENT_HEAP_SIZE(heap_capset, size)
420 #define dtraceEventHeapLive(heap_capset, live) \
421 HASKELLEVENT_HEAP_LIVE(heap_capset, live)
422 #define dtraceCapsetCreate(capset, capset_type) \
423 HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
424 #define dtraceCapsetDelete(capset) \
425 HASKELLEVENT_CAPSET_DELETE(capset)
426 #define dtraceCapsetAssignCap(capset, capno) \
427 HASKELLEVENT_CAPSET_ASSIGN_CAP(capset, capno)
428 #define dtraceCapsetRemoveCap(capset, capno) \
429 HASKELLEVENT_CAPSET_REMOVE_CAP(capset, capno)
430 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) \
431 HASKELLEVENT_SPARK_COUNTERS(cap, a, b, c, d, e, f, g)
432 #define dtraceSparkCreate(cap) \
433 HASKELLEVENT_SPARK_CREATE(cap)
434 #define dtraceSparkDud(cap) \
435 HASKELLEVENT_SPARK_DUD(cap)
436 #define dtraceSparkOverflow(cap) \
437 HASKELLEVENT_SPARK_OVERFLOW(cap)
438 #define dtraceSparkRun(cap) \
439 HASKELLEVENT_SPARK_RUN(cap)
440 #define dtraceSparkSteal(cap, victim_cap) \
441 HASKELLEVENT_SPARK_STEAL(cap, victim_cap)
442 #define dtraceSparkFizzle(cap) \
443 HASKELLEVENT_SPARK_FIZZLE(cap)
444 #define dtraceSparkGc(cap) \
445 HASKELLEVENT_SPARK_GC(cap)
446 #define dtraceTaskCreate(taskID, cap, tid) \
447 HASKELLEVENT_TASK_CREATE(taskID, cap, tid)
448 #define dtraceTaskMigrate(taskID, cap, new_cap) \
449 HASKELLEVENT_TASK_MIGRATE(taskID, cap, new_cap)
450 #define dtraceTaskDelete(taskID) \
451 HASKELLEVENT_TASK_DELETE(taskID)
452
453 #else /* !defined(DTRACE) */
454
455 #define dtraceCreateThread(cap, tid) /* nothing */
456 #define dtraceRunThread(cap, tid) /* nothing */
457 #define dtraceStopThread(cap, tid, status, info) /* nothing */
458 #define dtraceThreadRunnable(cap, tid) /* nothing */
459 #define dtraceMigrateThread(cap, tid, new_cap) /* nothing */
460 #define dtraceThreadWakeup(cap, tid, other_cap) /* nothing */
461 #define dtraceGcStart(cap) /* nothing */
462 #define dtraceGcEnd(cap) /* nothing */
463 #define dtraceRequestSeqGc(cap) /* nothing */
464 #define dtraceRequestParGc(cap) /* nothing */
465 #define dtraceCreateSparkThread(cap, spark_tid) /* nothing */
466 #define dtraceThreadLabel(cap, tso, label) /* nothing */
467 #define dtraceUserMsg(cap, msg) /* nothing */
468 #define dtraceUserMarker(cap, msg) /* nothing */
469 #define dtraceGcIdle(cap) /* nothing */
470 #define dtraceGcWork(cap) /* nothing */
471 #define dtraceGcDone(cap) /* nothing */
472 #define dtraceGcGlobalSync(cap) /* nothing */
473 #define dtraceEventGcStats(heap_capset, gens, \
474 copies, slop, fragmentation, \
475 par_n_threads, \
476 par_max_copied, \
477 par_tot_copied, \
478 par_balanced_copied) /* nothing */
479 #define dtraceHeapInfo(heap_capset, gens, \
480 maxHeapSize, allocAreaSize, \
481 mblockSize, blockSize) /* nothing */
482 #define dtraceEventHeapAllocated(cap, heap_capset, \
483 allocated) /* nothing */
484 #define dtraceEventHeapSize(heap_capset, size) /* nothing */
485 #define dtraceEventHeapLive(heap_capset, live) /* nothing */
486 #define dtraceCapCreate(cap) /* nothing */
487 #define dtraceCapDelete(cap) /* nothing */
488 #define dtraceCapEnable(cap) /* nothing */
489 #define dtraceCapDisable(cap) /* nothing */
490 #define dtraceCapsetCreate(capset, capset_type) /* nothing */
491 #define dtraceCapsetDelete(capset) /* nothing */
492 #define dtraceCapsetAssignCap(capset, capno) /* nothing */
493 #define dtraceCapsetRemoveCap(capset, capno) /* nothing */
494 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) /* nothing */
495 #define dtraceSparkCreate(cap) /* nothing */
496 #define dtraceSparkDud(cap) /* nothing */
497 #define dtraceSparkOverflow(cap) /* nothing */
498 #define dtraceSparkRun(cap) /* nothing */
499 #define dtraceSparkSteal(cap, victim_cap) /* nothing */
500 #define dtraceSparkFizzle(cap) /* nothing */
501 #define dtraceSparkGc(cap) /* nothing */
502 #define dtraceTaskCreate(taskID, cap, tid) /* nothing */
503 #define dtraceTaskMigrate(taskID, cap, new_cap) /* nothing */
504 #define dtraceTaskDelete(taskID) /* nothing */
505
506 #endif
507
508 // -----------------------------------------------------------------------------
509 // Trace probes dispatching to various tracing frameworks
510 //
511 // In order to avoid accumulating multiple calls to tracing calls at trace
512 // points, we define inline probe functions that contain the various
513 // invocations.
514 //
515 // Dtrace - dtrace probes are unconditionally added as probe activation is
516 // handled by the dtrace component of the kernel, and inactive probes are
517 // very cheap - usually, one no-op. Consequently, dtrace can be used with
518 // all flavours of the RTS. In addition, we still support logging events to
519 // a file, even in the presence of dtrace. This is, eg, useful when tracing
520 // on a server, but browsing trace information with ThreadScope on a local
521 // client.
522 //
523 // -----------------------------------------------------------------------------
524
525 INLINE_HEADER void traceEventCreateThread(Capability *cap STG_UNUSED,
526 StgTSO *tso STG_UNUSED)
527 {
528 traceSchedEvent(cap, EVENT_CREATE_THREAD, tso, tso->stackobj->stack_size);
529 dtraceCreateThread((EventCapNo)cap->no, (EventThreadID)tso->id);
530 }
531
532 INLINE_HEADER void traceEventRunThread(Capability *cap STG_UNUSED,
533 StgTSO *tso STG_UNUSED)
534 {
535 traceSchedEvent(cap, EVENT_RUN_THREAD, tso, tso->what_next);
536 dtraceRunThread((EventCapNo)cap->no, (EventThreadID)tso->id);
537 }
538
539 INLINE_HEADER void traceEventStopThread(Capability *cap STG_UNUSED,
540 StgTSO *tso STG_UNUSED,
541 StgThreadReturnCode status STG_UNUSED,
542 StgWord32 info STG_UNUSED)
543 {
544 traceSchedEvent2(cap, EVENT_STOP_THREAD, tso, status, info);
545 dtraceStopThread((EventCapNo)cap->no, (EventThreadID)tso->id,
546 (EventThreadStatus)status, (EventThreadID)info);
547 }
548
549 INLINE_HEADER void traceEventMigrateThread(Capability *cap STG_UNUSED,
550 StgTSO *tso STG_UNUSED,
551 uint32_t new_cap STG_UNUSED)
552 {
553 traceSchedEvent(cap, EVENT_MIGRATE_THREAD, tso, new_cap);
554 dtraceMigrateThread((EventCapNo)cap->no, (EventThreadID)tso->id,
555 (EventCapNo)new_cap);
556 }
557
558 INLINE_HEADER void traceCapCreate(Capability *cap STG_UNUSED)
559 {
560 traceCapEvent(cap, EVENT_CAP_CREATE);
561 dtraceCapCreate((EventCapNo)cap->no);
562 }
563
564 INLINE_HEADER void traceCapDelete(Capability *cap STG_UNUSED)
565 {
566 traceCapEvent(cap, EVENT_CAP_DELETE);
567 dtraceCapDelete((EventCapNo)cap->no);
568 }
569
570 INLINE_HEADER void traceCapEnable(Capability *cap STG_UNUSED)
571 {
572 traceCapEvent(cap, EVENT_CAP_ENABLE);
573 dtraceCapEnable((EventCapNo)cap->no);
574 }
575
576 INLINE_HEADER void traceCapDisable(Capability *cap STG_UNUSED)
577 {
578 traceCapEvent(cap, EVENT_CAP_DISABLE);
579 dtraceCapDisable((EventCapNo)cap->no);
580 }
581
582 INLINE_HEADER void traceEventThreadWakeup(Capability *cap STG_UNUSED,
583 StgTSO *tso STG_UNUSED,
584 uint32_t other_cap STG_UNUSED)
585 {
586 traceSchedEvent(cap, EVENT_THREAD_WAKEUP, tso, other_cap);
587 dtraceThreadWakeup((EventCapNo)cap->no, (EventThreadID)tso->id,
588 (EventCapNo)other_cap);
589 }
590
591 INLINE_HEADER void traceThreadLabel(Capability *cap STG_UNUSED,
592 StgTSO *tso STG_UNUSED,
593 char *label STG_UNUSED)
594 {
595 if (RTS_UNLIKELY(TRACE_sched)) {
596 traceThreadLabel_(cap, tso, label);
597 }
598 dtraceThreadLabel((EventCapNo)cap->no, (EventThreadID)tso->id, label);
599 }
600
601 INLINE_HEADER void traceEventGcStart(Capability *cap STG_UNUSED)
602 {
603 traceGcEvent(cap, EVENT_GC_START);
604 dtraceGcStart((EventCapNo)cap->no);
605 }
606
607 INLINE_HEADER void traceEventGcStartAtT(Capability *cap STG_UNUSED,
608 StgWord64 ts STG_UNUSED)
609 {
610 traceGcEventAtT(cap, ts, EVENT_GC_START);
611 dtraceGcStart((EventCapNo)cap->no);
612 }
613
614 INLINE_HEADER void traceEventGcEnd(Capability *cap STG_UNUSED)
615 {
616 traceGcEvent(cap, EVENT_GC_END);
617 dtraceGcEnd((EventCapNo)cap->no);
618 }
619
620 INLINE_HEADER void traceEventGcEndAtT(Capability *cap STG_UNUSED,
621 StgWord64 ts STG_UNUSED)
622 {
623 traceGcEventAtT(cap, ts, EVENT_GC_END);
624 dtraceGcEnd((EventCapNo)cap->no);
625 }
626
627 INLINE_HEADER void traceEventRequestSeqGc(Capability *cap STG_UNUSED)
628 {
629 traceGcEvent(cap, EVENT_REQUEST_SEQ_GC);
630 dtraceRequestSeqGc((EventCapNo)cap->no);
631 }
632
633 INLINE_HEADER void traceEventRequestParGc(Capability *cap STG_UNUSED)
634 {
635 traceGcEvent(cap, EVENT_REQUEST_PAR_GC);
636 dtraceRequestParGc((EventCapNo)cap->no);
637 }
638
639 INLINE_HEADER void traceEventGcIdle(Capability *cap STG_UNUSED)
640 {
641 traceGcEvent(cap, EVENT_GC_IDLE);
642 dtraceGcIdle((EventCapNo)cap->no);
643 }
644
645 INLINE_HEADER void traceEventGcWork(Capability *cap STG_UNUSED)
646 {
647 traceGcEvent(cap, EVENT_GC_WORK);
648 dtraceGcWork((EventCapNo)cap->no);
649 }
650
651 INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
652 {
653 traceGcEvent(cap, EVENT_GC_DONE);
654 dtraceGcDone((EventCapNo)cap->no);
655 }
656
657 INLINE_HEADER void traceEventGcGlobalSync(Capability *cap STG_UNUSED)
658 {
659 traceGcEvent(cap, EVENT_GC_GLOBAL_SYNC);
660 dtraceGcGlobalSync((EventCapNo)cap->no);
661 }
662
663 INLINE_HEADER void traceEventGcStats(Capability *cap STG_UNUSED,
664 CapsetID heap_capset STG_UNUSED,
665 uint32_t gen STG_UNUSED,
666 W_ copied STG_UNUSED,
667 W_ slop STG_UNUSED,
668 W_ fragmentation STG_UNUSED,
669 uint32_t par_n_threads STG_UNUSED,
670 W_ par_max_copied STG_UNUSED,
671 W_ par_tot_copied STG_UNUSED,
672 W_ par_balanced_copied STG_UNUSED)
673 {
674 if (RTS_UNLIKELY(TRACE_gc)) {
675 traceEventGcStats_(cap, heap_capset, gen,
676 copied, slop, fragmentation,
677 par_n_threads, par_max_copied,
678 par_tot_copied, par_balanced_copied);
679 }
680 dtraceEventGcStats(heap_capset, gen,
681 copied, slop, fragmentation,
682 par_n_threads, par_max_copied,
683 par_tot_copied, par_balanced_copied);
684 }
685
686 INLINE_HEADER void traceEventHeapInfo(CapsetID heap_capset STG_UNUSED,
687 uint32_t gens STG_UNUSED,
688 W_ maxHeapSize STG_UNUSED,
689 W_ allocAreaSize STG_UNUSED,
690 W_ mblockSize STG_UNUSED,
691 W_ blockSize STG_UNUSED)
692 {
693 if (RTS_UNLIKELY(TRACE_gc)) {
694 traceEventHeapInfo_(heap_capset, gens,
695 maxHeapSize, allocAreaSize,
696 mblockSize, blockSize);
697 }
698 dtraceHeapInfo(heap_capset, gens,
699 maxHeapSize, allocAreaSize,
700 mblockSize, blockSize);
701 }
702
703 INLINE_HEADER void traceEventHeapAllocated(Capability *cap STG_UNUSED,
704 CapsetID heap_capset STG_UNUSED,
705 W_ allocated STG_UNUSED)
706 {
707 traceHeapEvent(cap, EVENT_HEAP_ALLOCATED, heap_capset, allocated);
708 dtraceEventHeapAllocated((EventCapNo)cap->no, heap_capset, allocated);
709 }
710
711 INLINE_HEADER void traceEventHeapSize(Capability *cap STG_UNUSED,
712 CapsetID heap_capset STG_UNUSED,
713 W_ heap_size STG_UNUSED)
714 {
715 traceHeapEvent(cap, EVENT_HEAP_SIZE, heap_capset, heap_size);
716 dtraceEventHeapSize(heap_capset, heap_size);
717 }
718
719 INLINE_HEADER void traceEventHeapLive(Capability *cap STG_UNUSED,
720 CapsetID heap_capset STG_UNUSED,
721 W_ heap_live STG_UNUSED)
722 {
723 traceHeapEvent(cap, EVENT_HEAP_LIVE, heap_capset, heap_live);
724 dtraceEventHeapLive(heap_capset, heap_live);
725 }
726
727 INLINE_HEADER void traceCapsetCreate(CapsetID capset STG_UNUSED,
728 CapsetType capset_type STG_UNUSED)
729 {
730 traceCapsetEvent(EVENT_CAPSET_CREATE, capset, capset_type);
731 dtraceCapsetCreate(capset, capset_type);
732 }
733
734 INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
735 {
736 traceCapsetEvent(EVENT_CAPSET_DELETE, capset, 0);
737 dtraceCapsetDelete(capset);
738 }
739
740 INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
741 uint32_t capno STG_UNUSED)
742 {
743 traceCapsetEvent(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
744 dtraceCapsetAssignCap(capset, capno);
745 }
746
747 INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
748 uint32_t capno STG_UNUSED)
749 {
750 traceCapsetEvent(EVENT_CAPSET_REMOVE_CAP, capset, capno);
751 dtraceCapsetRemoveCap(capset, capno);
752 }
753
754 INLINE_HEADER void traceWallClockTime(void)
755 {
756 traceWallClockTime_();
757 /* Note: no DTrace equivalent because it is available to DTrace directly */
758 }
759
760 INLINE_HEADER void traceOSProcessInfo(void)
761 {
762 traceOSProcessInfo_();
763 /* Note: no DTrace equivalent because all this OS process info
764 * is available to DTrace directly */
765 }
766
767 INLINE_HEADER void traceEventCreateSparkThread(Capability *cap STG_UNUSED,
768 StgThreadID spark_tid STG_UNUSED)
769 {
770 traceSparkEvent2(cap, EVENT_CREATE_SPARK_THREAD, spark_tid);
771 dtraceCreateSparkThread((EventCapNo)cap->no, (EventThreadID)spark_tid);
772 }
773
774 INLINE_HEADER void traceSparkCounters(Capability *cap STG_UNUSED)
775 {
776 #if defined(THREADED_RTS)
777 if (RTS_UNLIKELY(TRACE_spark_sampled)) {
778 traceSparkCounters_(cap, cap->spark_stats, sparkPoolSize(cap->sparks));
779 }
780 dtraceSparkCounters((EventCapNo)cap->no,
781 cap->spark_stats.created,
782 cap->spark_stats.dud,
783 cap->spark_stats.overflowed,
784 cap->spark_stats.converted,
785 cap->spark_stats.gcd,
786 cap->spark_stats.fizzled,
787 sparkPoolSize(cap->sparks));
788 #endif
789 }
790
791 INLINE_HEADER void traceEventSparkCreate(Capability *cap STG_UNUSED)
792 {
793 traceSparkEvent(cap, EVENT_SPARK_CREATE);
794 dtraceSparkCreate((EventCapNo)cap->no);
795 }
796
797 INLINE_HEADER void traceEventSparkDud(Capability *cap STG_UNUSED)
798 {
799 traceSparkEvent(cap, EVENT_SPARK_DUD);
800 dtraceSparkDud((EventCapNo)cap->no);
801 }
802
803 INLINE_HEADER void traceEventSparkOverflow(Capability *cap STG_UNUSED)
804 {
805 traceSparkEvent(cap, EVENT_SPARK_OVERFLOW);
806 dtraceSparkOverflow((EventCapNo)cap->no);
807 }
808
809 INLINE_HEADER void traceEventSparkRun(Capability *cap STG_UNUSED)
810 {
811 traceSparkEvent(cap, EVENT_SPARK_RUN);
812 dtraceSparkRun((EventCapNo)cap->no);
813 }
814
815 INLINE_HEADER void traceEventSparkSteal(Capability *cap STG_UNUSED,
816 uint32_t victim_cap STG_UNUSED)
817 {
818 traceSparkEvent2(cap, EVENT_SPARK_STEAL, victim_cap);
819 dtraceSparkSteal((EventCapNo)cap->no, (EventCapNo)victim_cap);
820 }
821
822 INLINE_HEADER void traceEventSparkFizzle(Capability *cap STG_UNUSED)
823 {
824 traceSparkEvent(cap, EVENT_SPARK_FIZZLE);
825 dtraceSparkFizzle((EventCapNo)cap->no);
826 }
827
828 INLINE_HEADER void traceEventSparkGC(Capability *cap STG_UNUSED)
829 {
830 traceSparkEvent(cap, EVENT_SPARK_GC);
831 dtraceSparkGc((EventCapNo)cap->no);
832 }
833
834 INLINE_HEADER void traceTaskCreate(Task *task STG_UNUSED,
835 Capability *cap STG_UNUSED)
836 {
837 ASSERT(task->cap == cap);
838 // TODO: asserting task->cap == NULL would be much stronger
839 // (the intention being that the task structure is just created and empty)
840 // but would require large changes of traceTaskCreate calls.
841 ASSERT(cap != NULL);
842 // A new task gets associated with a cap. We also record
843 // the kernel thread id of the task, which should never change.
844 if (RTS_UNLIKELY(TRACE_sched)) {
845 traceTaskCreate_(task, cap);
846 }
847 dtraceTaskCreate(serialisableTaskId(task),
848 (EventCapNo)cap->no,
849 kernelThreadId());
850 }
851
852 INLINE_HEADER void traceTaskMigrate(Task *task STG_UNUSED,
853 Capability *cap STG_UNUSED,
854 Capability *new_cap STG_UNUSED)
855 {
856 ASSERT(task->cap == cap);
857 ASSERT(cap != NULL);
858 ASSERT(cap != new_cap);
859 ASSERT(new_cap != NULL);
860 // A task migrates from a cap to another.
861 if (RTS_UNLIKELY(TRACE_sched)) {
862 traceTaskMigrate_(task, cap, new_cap);
863 }
864 dtraceTaskMigrate(serialisableTaskId(task), (EventCapNo)cap->no,
865 (EventCapNo)new_cap->no);
866 }
867
868 INLINE_HEADER void traceTaskDelete(Task *task STG_UNUSED)
869 {
870 ASSERT(task->cap != NULL);
871 if (RTS_UNLIKELY(TRACE_sched)) {
872 traceTaskDelete_(task);
873 }
874 dtraceTaskDelete(serialisableTaskId(task));
875 }
876
877 #include "EndPrivate.h"