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