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