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