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