Fix the timestamps in GC_START and GC_END events on the GC-initiating cap
[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 dtraceEventGcStats(heap_capset, gens, \
354 copies, slop, fragmentation, \
355 par_n_threads, \
356 par_max_copied, \
357 par_tot_copied) \
358 HASKELLEVENT_GC_STATS(heap_capset, gens, \
359 copies, slop, fragmentation, \
360 par_n_threads, \
361 par_max_copied, \
362 par_tot_copied) \
363 #define dtraceHeapInfo(heap_capset, gens, \
364 maxHeapSize, allocAreaSize, \
365 mblockSize, blockSize) \
366 HASKELLEVENT_HEAP_INFO(heap_capset, gens, \
367 maxHeapSize, allocAreaSize, \
368 mblockSize, blockSize)
369 #define dtraceEventHeapAllocated(cap, heap_capset, \
370 allocated) \
371 HASKELLEVENT_HEAP_ALLOCATED(cap, heap_capset, \
372 allocated)
373 #define dtraceEventHeapSize(heap_capset, size) \
374 HASKELLEVENT_HEAP_LIVE(heap_capset, size)
375 #define dtraceEventHeapLive(heap_capset, live) \
376 HASKELLEVENT_HEAP_LIVE(heap_capset, live)
377
378 #define dtraceCapsetCreate(capset, capset_type) \
379 HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
380 #define dtraceCapsetDelete(capset) \
381 HASKELLEVENT_CAPSET_DELETE(capset)
382 #define dtraceCapsetAssignCap(capset, capno) \
383 HASKELLEVENT_CAPSET_ASSIGN_CAP(capset, capno)
384 #define dtraceCapsetRemoveCap(capset, capno) \
385 HASKELLEVENT_CAPSET_REMOVE_CAP(capset, capno)
386 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) \
387 HASKELLEVENT_SPARK_COUNTERS(cap, a, b, c, d, e, f, g)
388 #define dtraceSparkCreate(cap) \
389 HASKELLEVENT_SPARK_CREATE(cap)
390 #define dtraceSparkDud(cap) \
391 HASKELLEVENT_SPARK_DUD(cap)
392 #define dtraceSparkOverflow(cap) \
393 HASKELLEVENT_SPARK_OVERFLOW(cap)
394 #define dtraceSparkRun(cap) \
395 HASKELLEVENT_SPARK_RUN(cap)
396 #define dtraceSparkSteal(cap, victim_cap) \
397 HASKELLEVENT_SPARK_STEAL(cap, victim_cap)
398 #define dtraceSparkFizzle(cap) \
399 HASKELLEVENT_SPARK_FIZZLE(cap)
400 #define dtraceSparkGc(cap) \
401 HASKELLEVENT_SPARK_GC(cap)
402
403 #else /* !defined(DTRACE) */
404
405 #define dtraceCreateThread(cap, tid) /* nothing */
406 #define dtraceRunThread(cap, tid) /* nothing */
407 #define dtraceStopThread(cap, tid, status, info) /* nothing */
408 #define dtraceThreadRunnable(cap, tid) /* nothing */
409 #define dtraceMigrateThread(cap, tid, new_cap) /* nothing */
410 #define dtraceThreadWakeup(cap, tid, other_cap) /* nothing */
411 #define dtraceGcStart(cap) /* nothing */
412 #define dtraceGcEnd(cap) /* nothing */
413 #define dtraceRequestSeqGc(cap) /* nothing */
414 #define dtraceRequestParGc(cap) /* nothing */
415 #define dtraceCreateSparkThread(cap, spark_tid) /* nothing */
416 #define dtraceThreadLabel(cap, tso, label) /* nothing */
417 INLINE_HEADER void dtraceStartup (int num_caps STG_UNUSED) {};
418 #define dtraceUserMsg(cap, msg) /* nothing */
419 #define dtraceGcIdle(cap) /* nothing */
420 #define dtraceGcWork(cap) /* nothing */
421 #define dtraceGcDone(cap) /* nothing */
422 #define dtraceEventGcStats(heap_capset, gens, \
423 copies, slop, fragmentation, \
424 par_n_threads, \
425 par_max_copied, \
426 par_tot_copied) /* nothing */
427 #define dtraceHeapInfo(heap_capset, gens, \
428 maxHeapSize, allocAreaSize, \
429 mblockSize, blockSize) /* nothing */
430 #define dtraceEventHeapAllocated(cap, heap_capset, \
431 allocated) /* nothing */
432 #define dtraceEventHeapSize(heap_capset, size) /* nothing */
433 #define dtraceEventHeapLive(heap_capset, live) /* nothing */
434 #define dtraceCapCreate(cap) /* nothing */
435 #define dtraceCapDelete(cap) /* nothing */
436 #define dtraceCapEnable(cap) /* nothing */
437 #define dtraceCapDisable(cap) /* nothing */
438 #define dtraceCapsetCreate(capset, capset_type) /* nothing */
439 #define dtraceCapsetDelete(capset) /* nothing */
440 #define dtraceCapsetAssignCap(capset, capno) /* nothing */
441 #define dtraceCapsetRemoveCap(capset, capno) /* nothing */
442 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) /* nothing */
443 #define dtraceSparkCreate(cap) /* nothing */
444 #define dtraceSparkDud(cap) /* nothing */
445 #define dtraceSparkOverflow(cap) /* nothing */
446 #define dtraceSparkRun(cap) /* nothing */
447 #define dtraceSparkSteal(cap, victim_cap) /* nothing */
448 #define dtraceSparkFizzle(cap) /* nothing */
449 #define dtraceSparkGc(cap) /* nothing */
450
451 #endif
452
453 // -----------------------------------------------------------------------------
454 // Trace probes dispatching to various tracing frameworks
455 //
456 // In order to avoid accumulating multiple calls to tracing calls at trace
457 // points, we define inline probe functions that contain the various
458 // invocations.
459 //
460 // Dtrace - dtrace probes are unconditionally added as probe activation is
461 // handled by the dtrace component of the kernel, and inactive probes are
462 // very cheap — usually, one no-op. Consequently, dtrace can be used with
463 // all flavours of the RTS. In addition, we still support logging events to
464 // a file, even in the presence of dtrace. This is, eg, useful when tracing
465 // on a server, but browsing trace information with ThreadScope on a local
466 // client.
467 //
468 // -----------------------------------------------------------------------------
469
470 INLINE_HEADER void traceEventCreateThread(Capability *cap STG_UNUSED,
471 StgTSO *tso STG_UNUSED)
472 {
473 traceSchedEvent(cap, EVENT_CREATE_THREAD, tso, tso->stackobj->stack_size);
474 dtraceCreateThread((EventCapNo)cap->no, (EventThreadID)tso->id);
475 }
476
477 INLINE_HEADER void traceEventRunThread(Capability *cap STG_UNUSED,
478 StgTSO *tso STG_UNUSED)
479 {
480 traceSchedEvent(cap, EVENT_RUN_THREAD, tso, tso->what_next);
481 dtraceRunThread((EventCapNo)cap->no, (EventThreadID)tso->id);
482 }
483
484 INLINE_HEADER void traceEventStopThread(Capability *cap STG_UNUSED,
485 StgTSO *tso STG_UNUSED,
486 StgThreadReturnCode status STG_UNUSED,
487 StgWord32 info STG_UNUSED)
488 {
489 traceSchedEvent2(cap, EVENT_STOP_THREAD, tso, status, info);
490 dtraceStopThread((EventCapNo)cap->no, (EventThreadID)tso->id,
491 (EventThreadStatus)status, (EventThreadID)info);
492 }
493
494 // needs to be EXTERN_INLINE as it is used in another EXTERN_INLINE function
495 EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED,
496 StgTSO *tso STG_UNUSED);
497
498 EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED,
499 StgTSO *tso STG_UNUSED)
500 {
501 traceSchedEvent(cap, EVENT_THREAD_RUNNABLE, tso, 0);
502 dtraceThreadRunnable((EventCapNo)cap->no, (EventThreadID)tso->id);
503 }
504
505 INLINE_HEADER void traceEventMigrateThread(Capability *cap STG_UNUSED,
506 StgTSO *tso STG_UNUSED,
507 nat new_cap STG_UNUSED)
508 {
509 traceSchedEvent(cap, EVENT_MIGRATE_THREAD, tso, new_cap);
510 dtraceMigrateThread((EventCapNo)cap->no, (EventThreadID)tso->id,
511 (EventCapNo)new_cap);
512 }
513
514 INLINE_HEADER void traceCapCreate(Capability *cap STG_UNUSED)
515 {
516 traceCapEvent(cap, EVENT_CAP_CREATE);
517 dtraceCapCreate((EventCapNo)cap->no);
518 }
519
520 INLINE_HEADER void traceCapDelete(Capability *cap STG_UNUSED)
521 {
522 traceCapEvent(cap, EVENT_CAP_DELETE);
523 dtraceCapDelete((EventCapNo)cap->no);
524 }
525
526 INLINE_HEADER void traceCapEnable(Capability *cap STG_UNUSED)
527 {
528 traceCapEvent(cap, EVENT_CAP_ENABLE);
529 dtraceCapEnable((EventCapNo)cap->no);
530 }
531
532 INLINE_HEADER void traceCapDisable(Capability *cap STG_UNUSED)
533 {
534 traceCapEvent(cap, EVENT_CAP_DISABLE);
535 dtraceCapDisable((EventCapNo)cap->no);
536 }
537
538 INLINE_HEADER void traceEventThreadWakeup(Capability *cap STG_UNUSED,
539 StgTSO *tso STG_UNUSED,
540 nat other_cap STG_UNUSED)
541 {
542 traceSchedEvent(cap, EVENT_THREAD_WAKEUP, tso, other_cap);
543 dtraceThreadWakeup((EventCapNo)cap->no, (EventThreadID)tso->id,
544 (EventCapNo)other_cap);
545 }
546
547 INLINE_HEADER void traceThreadLabel(Capability *cap STG_UNUSED,
548 StgTSO *tso STG_UNUSED,
549 char *label STG_UNUSED)
550 {
551 if (RTS_UNLIKELY(TRACE_sched)) {
552 traceThreadLabel_(cap, tso, label);
553 }
554 dtraceThreadLabel((EventCapNo)cap->no, (EventThreadID)tso->id, label);
555 }
556
557 INLINE_HEADER void traceEventGcStart(Capability *cap STG_UNUSED)
558 {
559 traceGcEvent(cap, EVENT_GC_START);
560 dtraceGcStart((EventCapNo)cap->no);
561 }
562
563 INLINE_HEADER void traceEventGcStartAtT(Capability *cap STG_UNUSED,
564 StgWord64 ts STG_UNUSED)
565 {
566 traceGcEventAtT(cap, ts, EVENT_GC_START);
567 dtraceGcStart((EventCapNo)cap->no);
568 }
569
570 INLINE_HEADER void traceEventGcEnd(Capability *cap STG_UNUSED)
571 {
572 traceGcEvent(cap, EVENT_GC_END);
573 dtraceGcEnd((EventCapNo)cap->no);
574 }
575
576 INLINE_HEADER void traceEventGcEndAtT(Capability *cap STG_UNUSED,
577 StgWord64 ts STG_UNUSED)
578 {
579 traceGcEventAtT(cap, ts, EVENT_GC_END);
580 dtraceGcEnd((EventCapNo)cap->no);
581 }
582
583 INLINE_HEADER void traceEventRequestSeqGc(Capability *cap STG_UNUSED)
584 {
585 traceGcEvent(cap, EVENT_REQUEST_SEQ_GC);
586 dtraceRequestSeqGc((EventCapNo)cap->no);
587 }
588
589 INLINE_HEADER void traceEventRequestParGc(Capability *cap STG_UNUSED)
590 {
591 traceGcEvent(cap, EVENT_REQUEST_PAR_GC);
592 dtraceRequestParGc((EventCapNo)cap->no);
593 }
594
595 INLINE_HEADER void traceEventGcIdle(Capability *cap STG_UNUSED)
596 {
597 traceGcEvent(cap, EVENT_GC_IDLE);
598 dtraceGcIdle((EventCapNo)cap->no);
599 }
600
601 INLINE_HEADER void traceEventGcWork(Capability *cap STG_UNUSED)
602 {
603 traceGcEvent(cap, EVENT_GC_WORK);
604 dtraceGcWork((EventCapNo)cap->no);
605 }
606
607 INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
608 {
609 traceGcEvent(cap, EVENT_GC_DONE);
610 dtraceGcDone((EventCapNo)cap->no);
611 }
612
613 INLINE_HEADER void traceEventGcStats(Capability *cap STG_UNUSED,
614 CapsetID heap_capset STG_UNUSED,
615 nat gen STG_UNUSED,
616 lnat copied STG_UNUSED,
617 lnat slop STG_UNUSED,
618 lnat fragmentation STG_UNUSED,
619 nat par_n_threads STG_UNUSED,
620 lnat par_max_copied STG_UNUSED,
621 lnat par_tot_copied STG_UNUSED)
622 {
623 if (RTS_UNLIKELY(TRACE_gc)) {
624 traceEventGcStats_(cap, heap_capset, gen,
625 copied, slop, fragmentation,
626 par_n_threads, par_max_copied, par_tot_copied);
627 }
628 dtraceEventGcStats(heap_capset, gens,
629 copies, slop, fragmentation,
630 par_n_threads, par_max_copied, par_tot_copied);
631 }
632
633 INLINE_HEADER void traceEventHeapInfo(CapsetID heap_capset STG_UNUSED,
634 nat gens STG_UNUSED,
635 lnat maxHeapSize STG_UNUSED,
636 lnat allocAreaSize STG_UNUSED,
637 lnat mblockSize STG_UNUSED,
638 lnat blockSize STG_UNUSED)
639 {
640 if (RTS_UNLIKELY(TRACE_gc)) {
641 traceEventHeapInfo_(heap_capset, gens,
642 maxHeapSize, allocAreaSize,
643 mblockSize, blockSize);
644 }
645 dtraceHeapInfo(heap_capset, gens,
646 maxHeapSize, allocAreaSize,
647 mblockSize, blockSize);
648 }
649
650 INLINE_HEADER void traceEventHeapAllocated(Capability *cap STG_UNUSED,
651 CapsetID heap_capset STG_UNUSED,
652 lnat allocated STG_UNUSED)
653 {
654 traceHeapEvent(cap, EVENT_HEAP_ALLOCATED, heap_capset, allocated);
655 dtraceEventHeapAllocated((EventCapNo)cap->no, heap_capset, allocated);
656 }
657
658 INLINE_HEADER void traceEventHeapSize(Capability *cap STG_UNUSED,
659 CapsetID heap_capset STG_UNUSED,
660 lnat heap_size STG_UNUSED)
661 {
662 traceHeapEvent(cap, EVENT_HEAP_SIZE, heap_capset, heap_size);
663 dtraceEventHeapSize(heap_capset, heap_size);
664 }
665
666 INLINE_HEADER void traceEventHeapLive(Capability *cap STG_UNUSED,
667 CapsetID heap_capset STG_UNUSED,
668 lnat heap_live STG_UNUSED)
669 {
670 traceHeapEvent(cap, EVENT_HEAP_LIVE, heap_capset, heap_live);
671 dtraceEventHeapLive(heap_capset, heap_live);
672 }
673
674 /* TODO: at some point we should remove this event, it's covered by
675 * the cap create/delete events.
676 */
677 INLINE_HEADER void traceEventStartup(void)
678 {
679 int n_caps;
680 #ifdef THREADED_RTS
681 // XXX n_capabilities hasn't been initialised yet
682 n_caps = RtsFlags.ParFlags.nNodes;
683 #else
684 n_caps = 1;
685 #endif
686
687 traceEventStartup_(n_caps);
688 dtraceStartup(n_caps);
689 }
690
691 INLINE_HEADER void traceCapsetCreate(CapsetID capset STG_UNUSED,
692 CapsetType capset_type STG_UNUSED)
693 {
694 traceCapsetEvent(EVENT_CAPSET_CREATE, capset, capset_type);
695 dtraceCapsetCreate(capset, capset_type);
696 }
697
698 INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
699 {
700 traceCapsetEvent(EVENT_CAPSET_DELETE, capset, 0);
701 dtraceCapsetDelete(capset);
702 }
703
704 INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
705 nat capno STG_UNUSED)
706 {
707 traceCapsetEvent(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
708 dtraceCapsetAssignCap(capset, capno);
709 }
710
711 INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
712 nat capno STG_UNUSED)
713 {
714 traceCapsetEvent(EVENT_CAPSET_REMOVE_CAP, capset, capno);
715 dtraceCapsetRemoveCap(capset, capno);
716 }
717
718 INLINE_HEADER void traceWallClockTime(void)
719 {
720 traceWallClockTime_();
721 /* Note: no DTrace equivalent because it is available to DTrace directly */
722 }
723
724 INLINE_HEADER void traceOSProcessInfo(void)
725 {
726 traceOSProcessInfo_();
727 /* Note: no DTrace equivalent because all this OS process info
728 * is available to DTrace directly */
729 }
730
731 INLINE_HEADER void traceEventCreateSparkThread(Capability *cap STG_UNUSED,
732 StgThreadID spark_tid STG_UNUSED)
733 {
734 traceSparkEvent2(cap, EVENT_CREATE_SPARK_THREAD, spark_tid);
735 dtraceCreateSparkThread((EventCapNo)cap->no, (EventThreadID)spark_tid);
736 }
737
738 INLINE_HEADER void traceSparkCounters(Capability *cap STG_UNUSED)
739 {
740 #ifdef THREADED_RTS
741 if (RTS_UNLIKELY(TRACE_spark_sampled)) {
742 traceSparkCounters_(cap, cap->spark_stats, sparkPoolSize(cap->sparks));
743 }
744 dtraceSparkCounters((EventCapNo)cap->no,
745 cap->spark_stats.created,
746 cap->spark_stats.dud,
747 cap->spark_stats.overflowed,
748 cap->spark_stats.converted,
749 cap->spark_stats.gcd,
750 cap->spark_stats.fizzled,
751 sparkPoolSize(cap->sparks));
752 #endif
753 }
754
755 INLINE_HEADER void traceEventSparkCreate(Capability *cap STG_UNUSED)
756 {
757 traceSparkEvent(cap, EVENT_SPARK_CREATE);
758 dtraceSparkCreate((EventCapNo)cap->no);
759 }
760
761 INLINE_HEADER void traceEventSparkDud(Capability *cap STG_UNUSED)
762 {
763 traceSparkEvent(cap, EVENT_SPARK_DUD);
764 dtraceSparkDud((EventCapNo)cap->no);
765 }
766
767 INLINE_HEADER void traceEventSparkOverflow(Capability *cap STG_UNUSED)
768 {
769 traceSparkEvent(cap, EVENT_SPARK_OVERFLOW);
770 dtraceSparkOverflow((EventCapNo)cap->no);
771 }
772
773 INLINE_HEADER void traceEventSparkRun(Capability *cap STG_UNUSED)
774 {
775 traceSparkEvent(cap, EVENT_SPARK_RUN);
776 dtraceSparkRun((EventCapNo)cap->no);
777 }
778
779 INLINE_HEADER void traceEventSparkSteal(Capability *cap STG_UNUSED,
780 nat victim_cap STG_UNUSED)
781 {
782 traceSparkEvent2(cap, EVENT_SPARK_STEAL, victim_cap);
783 dtraceSparkSteal((EventCapNo)cap->no, (EventCapNo)victim_cap);
784 }
785
786 INLINE_HEADER void traceEventSparkFizzle(Capability *cap STG_UNUSED)
787 {
788 traceSparkEvent(cap, EVENT_SPARK_FIZZLE);
789 dtraceSparkFizzle((EventCapNo)cap->no);
790 }
791
792 INLINE_HEADER void traceEventSparkGC(Capability *cap STG_UNUSED)
793 {
794 traceSparkEvent(cap, EVENT_SPARK_GC);
795 dtraceSparkGc((EventCapNo)cap->no);
796 }
797
798 #include "EndPrivate.h"
799
800 #endif /* TRACE_H */