testsuite: attempt fixing fallout from 089b72f52
[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 // needs to be EXTERN_INLINE as it is used in another EXTERN_INLINE function
521 EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED,
522 StgTSO *tso STG_UNUSED);
523
524 EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED,
525 StgTSO *tso STG_UNUSED)
526 {
527 traceSchedEvent(cap, EVENT_THREAD_RUNNABLE, tso, 0);
528 dtraceThreadRunnable((EventCapNo)cap->no, (EventThreadID)tso->id);
529 }
530
531 INLINE_HEADER void traceEventMigrateThread(Capability *cap STG_UNUSED,
532 StgTSO *tso STG_UNUSED,
533 nat new_cap STG_UNUSED)
534 {
535 traceSchedEvent(cap, EVENT_MIGRATE_THREAD, tso, new_cap);
536 dtraceMigrateThread((EventCapNo)cap->no, (EventThreadID)tso->id,
537 (EventCapNo)new_cap);
538 }
539
540 INLINE_HEADER void traceCapCreate(Capability *cap STG_UNUSED)
541 {
542 traceCapEvent(cap, EVENT_CAP_CREATE);
543 dtraceCapCreate((EventCapNo)cap->no);
544 }
545
546 INLINE_HEADER void traceCapDelete(Capability *cap STG_UNUSED)
547 {
548 traceCapEvent(cap, EVENT_CAP_DELETE);
549 dtraceCapDelete((EventCapNo)cap->no);
550 }
551
552 INLINE_HEADER void traceCapEnable(Capability *cap STG_UNUSED)
553 {
554 traceCapEvent(cap, EVENT_CAP_ENABLE);
555 dtraceCapEnable((EventCapNo)cap->no);
556 }
557
558 INLINE_HEADER void traceCapDisable(Capability *cap STG_UNUSED)
559 {
560 traceCapEvent(cap, EVENT_CAP_DISABLE);
561 dtraceCapDisable((EventCapNo)cap->no);
562 }
563
564 INLINE_HEADER void traceEventThreadWakeup(Capability *cap STG_UNUSED,
565 StgTSO *tso STG_UNUSED,
566 nat other_cap STG_UNUSED)
567 {
568 traceSchedEvent(cap, EVENT_THREAD_WAKEUP, tso, other_cap);
569 dtraceThreadWakeup((EventCapNo)cap->no, (EventThreadID)tso->id,
570 (EventCapNo)other_cap);
571 }
572
573 INLINE_HEADER void traceThreadLabel(Capability *cap STG_UNUSED,
574 StgTSO *tso STG_UNUSED,
575 char *label STG_UNUSED)
576 {
577 if (RTS_UNLIKELY(TRACE_sched)) {
578 traceThreadLabel_(cap, tso, label);
579 }
580 dtraceThreadLabel((EventCapNo)cap->no, (EventThreadID)tso->id, label);
581 }
582
583 INLINE_HEADER void traceEventGcStart(Capability *cap STG_UNUSED)
584 {
585 traceGcEvent(cap, EVENT_GC_START);
586 dtraceGcStart((EventCapNo)cap->no);
587 }
588
589 INLINE_HEADER void traceEventGcStartAtT(Capability *cap STG_UNUSED,
590 StgWord64 ts STG_UNUSED)
591 {
592 traceGcEventAtT(cap, ts, EVENT_GC_START);
593 dtraceGcStart((EventCapNo)cap->no);
594 }
595
596 INLINE_HEADER void traceEventGcEnd(Capability *cap STG_UNUSED)
597 {
598 traceGcEvent(cap, EVENT_GC_END);
599 dtraceGcEnd((EventCapNo)cap->no);
600 }
601
602 INLINE_HEADER void traceEventGcEndAtT(Capability *cap STG_UNUSED,
603 StgWord64 ts STG_UNUSED)
604 {
605 traceGcEventAtT(cap, ts, EVENT_GC_END);
606 dtraceGcEnd((EventCapNo)cap->no);
607 }
608
609 INLINE_HEADER void traceEventRequestSeqGc(Capability *cap STG_UNUSED)
610 {
611 traceGcEvent(cap, EVENT_REQUEST_SEQ_GC);
612 dtraceRequestSeqGc((EventCapNo)cap->no);
613 }
614
615 INLINE_HEADER void traceEventRequestParGc(Capability *cap STG_UNUSED)
616 {
617 traceGcEvent(cap, EVENT_REQUEST_PAR_GC);
618 dtraceRequestParGc((EventCapNo)cap->no);
619 }
620
621 INLINE_HEADER void traceEventGcIdle(Capability *cap STG_UNUSED)
622 {
623 traceGcEvent(cap, EVENT_GC_IDLE);
624 dtraceGcIdle((EventCapNo)cap->no);
625 }
626
627 INLINE_HEADER void traceEventGcWork(Capability *cap STG_UNUSED)
628 {
629 traceGcEvent(cap, EVENT_GC_WORK);
630 dtraceGcWork((EventCapNo)cap->no);
631 }
632
633 INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
634 {
635 traceGcEvent(cap, EVENT_GC_DONE);
636 dtraceGcDone((EventCapNo)cap->no);
637 }
638
639 INLINE_HEADER void traceEventGcGlobalSync(Capability *cap STG_UNUSED)
640 {
641 traceGcEvent(cap, EVENT_GC_GLOBAL_SYNC);
642 dtraceGcGlobalSync((EventCapNo)cap->no);
643 }
644
645 INLINE_HEADER void traceEventGcStats(Capability *cap STG_UNUSED,
646 CapsetID heap_capset STG_UNUSED,
647 nat gen STG_UNUSED,
648 W_ copied STG_UNUSED,
649 W_ slop STG_UNUSED,
650 W_ fragmentation STG_UNUSED,
651 nat par_n_threads STG_UNUSED,
652 W_ par_max_copied STG_UNUSED,
653 W_ par_tot_copied STG_UNUSED)
654 {
655 if (RTS_UNLIKELY(TRACE_gc)) {
656 traceEventGcStats_(cap, heap_capset, gen,
657 copied, slop, fragmentation,
658 par_n_threads, par_max_copied, par_tot_copied);
659 }
660 dtraceEventGcStats(heap_capset, gen,
661 copied, slop, fragmentation,
662 par_n_threads, par_max_copied, par_tot_copied);
663 }
664
665 INLINE_HEADER void traceEventHeapInfo(CapsetID heap_capset STG_UNUSED,
666 nat gens STG_UNUSED,
667 W_ maxHeapSize STG_UNUSED,
668 W_ allocAreaSize STG_UNUSED,
669 W_ mblockSize STG_UNUSED,
670 W_ blockSize STG_UNUSED)
671 {
672 if (RTS_UNLIKELY(TRACE_gc)) {
673 traceEventHeapInfo_(heap_capset, gens,
674 maxHeapSize, allocAreaSize,
675 mblockSize, blockSize);
676 }
677 dtraceHeapInfo(heap_capset, gens,
678 maxHeapSize, allocAreaSize,
679 mblockSize, blockSize);
680 }
681
682 INLINE_HEADER void traceEventHeapAllocated(Capability *cap STG_UNUSED,
683 CapsetID heap_capset STG_UNUSED,
684 W_ allocated STG_UNUSED)
685 {
686 traceHeapEvent(cap, EVENT_HEAP_ALLOCATED, heap_capset, allocated);
687 dtraceEventHeapAllocated((EventCapNo)cap->no, heap_capset, allocated);
688 }
689
690 INLINE_HEADER void traceEventHeapSize(Capability *cap STG_UNUSED,
691 CapsetID heap_capset STG_UNUSED,
692 W_ heap_size STG_UNUSED)
693 {
694 traceHeapEvent(cap, EVENT_HEAP_SIZE, heap_capset, heap_size);
695 dtraceEventHeapSize(heap_capset, heap_size);
696 }
697
698 INLINE_HEADER void traceEventHeapLive(Capability *cap STG_UNUSED,
699 CapsetID heap_capset STG_UNUSED,
700 W_ heap_live STG_UNUSED)
701 {
702 traceHeapEvent(cap, EVENT_HEAP_LIVE, heap_capset, heap_live);
703 dtraceEventHeapLive(heap_capset, heap_live);
704 }
705
706 INLINE_HEADER void traceCapsetCreate(CapsetID capset STG_UNUSED,
707 CapsetType capset_type STG_UNUSED)
708 {
709 traceCapsetEvent(EVENT_CAPSET_CREATE, capset, capset_type);
710 dtraceCapsetCreate(capset, capset_type);
711 }
712
713 INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
714 {
715 traceCapsetEvent(EVENT_CAPSET_DELETE, capset, 0);
716 dtraceCapsetDelete(capset);
717 }
718
719 INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
720 nat capno STG_UNUSED)
721 {
722 traceCapsetEvent(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
723 dtraceCapsetAssignCap(capset, capno);
724 }
725
726 INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
727 nat capno STG_UNUSED)
728 {
729 traceCapsetEvent(EVENT_CAPSET_REMOVE_CAP, capset, capno);
730 dtraceCapsetRemoveCap(capset, capno);
731 }
732
733 INLINE_HEADER void traceWallClockTime(void)
734 {
735 traceWallClockTime_();
736 /* Note: no DTrace equivalent because it is available to DTrace directly */
737 }
738
739 INLINE_HEADER void traceOSProcessInfo(void)
740 {
741 traceOSProcessInfo_();
742 /* Note: no DTrace equivalent because all this OS process info
743 * is available to DTrace directly */
744 }
745
746 INLINE_HEADER void traceEventCreateSparkThread(Capability *cap STG_UNUSED,
747 StgThreadID spark_tid STG_UNUSED)
748 {
749 traceSparkEvent2(cap, EVENT_CREATE_SPARK_THREAD, spark_tid);
750 dtraceCreateSparkThread((EventCapNo)cap->no, (EventThreadID)spark_tid);
751 }
752
753 INLINE_HEADER void traceSparkCounters(Capability *cap STG_UNUSED)
754 {
755 #ifdef THREADED_RTS
756 if (RTS_UNLIKELY(TRACE_spark_sampled)) {
757 traceSparkCounters_(cap, cap->spark_stats, sparkPoolSize(cap->sparks));
758 }
759 dtraceSparkCounters((EventCapNo)cap->no,
760 cap->spark_stats.created,
761 cap->spark_stats.dud,
762 cap->spark_stats.overflowed,
763 cap->spark_stats.converted,
764 cap->spark_stats.gcd,
765 cap->spark_stats.fizzled,
766 sparkPoolSize(cap->sparks));
767 #endif
768 }
769
770 INLINE_HEADER void traceEventSparkCreate(Capability *cap STG_UNUSED)
771 {
772 traceSparkEvent(cap, EVENT_SPARK_CREATE);
773 dtraceSparkCreate((EventCapNo)cap->no);
774 }
775
776 INLINE_HEADER void traceEventSparkDud(Capability *cap STG_UNUSED)
777 {
778 traceSparkEvent(cap, EVENT_SPARK_DUD);
779 dtraceSparkDud((EventCapNo)cap->no);
780 }
781
782 INLINE_HEADER void traceEventSparkOverflow(Capability *cap STG_UNUSED)
783 {
784 traceSparkEvent(cap, EVENT_SPARK_OVERFLOW);
785 dtraceSparkOverflow((EventCapNo)cap->no);
786 }
787
788 INLINE_HEADER void traceEventSparkRun(Capability *cap STG_UNUSED)
789 {
790 traceSparkEvent(cap, EVENT_SPARK_RUN);
791 dtraceSparkRun((EventCapNo)cap->no);
792 }
793
794 INLINE_HEADER void traceEventSparkSteal(Capability *cap STG_UNUSED,
795 nat victim_cap STG_UNUSED)
796 {
797 traceSparkEvent2(cap, EVENT_SPARK_STEAL, victim_cap);
798 dtraceSparkSteal((EventCapNo)cap->no, (EventCapNo)victim_cap);
799 }
800
801 INLINE_HEADER void traceEventSparkFizzle(Capability *cap STG_UNUSED)
802 {
803 traceSparkEvent(cap, EVENT_SPARK_FIZZLE);
804 dtraceSparkFizzle((EventCapNo)cap->no);
805 }
806
807 INLINE_HEADER void traceEventSparkGC(Capability *cap STG_UNUSED)
808 {
809 traceSparkEvent(cap, EVENT_SPARK_GC);
810 dtraceSparkGc((EventCapNo)cap->no);
811 }
812
813 INLINE_HEADER void traceTaskCreate(Task *task STG_UNUSED,
814 Capability *cap STG_UNUSED)
815 {
816 ASSERT(task->cap == cap);
817 // TODO: asserting task->cap == NULL would be much stronger
818 // (the intention being that the task structure is just created and empty)
819 // but would require large changes of traceTaskCreate calls.
820 ASSERT(cap != NULL);
821 // A new task gets associated with a cap. We also record
822 // the kernel thread id of the task, which should never change.
823 if (RTS_UNLIKELY(TRACE_sched)) {
824 traceTaskCreate_(task, cap);
825 }
826 dtraceTaskCreate(serialisableTaskId(task),
827 (EventCapNo)cap->no,
828 kernelThreadId());
829 }
830
831 INLINE_HEADER void traceTaskMigrate(Task *task STG_UNUSED,
832 Capability *cap STG_UNUSED,
833 Capability *new_cap STG_UNUSED)
834 {
835 ASSERT(task->cap == cap);
836 ASSERT(cap != NULL);
837 ASSERT(cap != new_cap);
838 ASSERT(new_cap != NULL);
839 // A task migrates from a cap to another.
840 if (RTS_UNLIKELY(TRACE_sched)) {
841 traceTaskMigrate_(task, cap, new_cap);
842 }
843 dtraceTaskMigrate(serialisableTaskId(task), (EventCapNo)cap->no,
844 (EventCapNo)new_cap->no);
845 }
846
847 INLINE_HEADER void traceTaskDelete(Task *task STG_UNUSED)
848 {
849 ASSERT(task->cap != NULL);
850 if (RTS_UNLIKELY(TRACE_sched)) {
851 traceTaskDelete_(task);
852 }
853 dtraceTaskDelete(serialisableTaskId(task));
854 }
855
856 #include "EndPrivate.h"
857
858 #endif /* TRACE_H */