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