Merge branch 'master' of darcs.haskell.org:/srv/darcs//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 void traceTaskCreate_ (Task *task,
266 Capability *cap);
267
268 void traceTaskMigrate_ (Task *task,
269 Capability *cap,
270 Capability *new_cap);
271
272 void traceTaskDelete_ (Task *task);
273
274 #else /* !TRACING */
275
276 #define traceSchedEvent(cap, tag, tso, other) /* nothing */
277 #define traceSchedEvent2(cap, tag, tso, other, info) /* nothing */
278 #define traceGcEvent(cap, tag) /* nothing */
279 #define traceGcEventAtT(cap, ts, tag) /* nothing */
280 #define traceEventGcStats_(cap, heap_capset, gen, \
281 copied, slop, fragmentation, \
282 par_n_threads, par_max_copied, par_tot_copied) /* nothing */
283 #define traceHeapEvent(cap, tag, heap_capset, info1) /* nothing */
284 #define traceEventHeapInfo_(heap_capset, gens, \
285 maxHeapSize, allocAreaSize, \
286 mblockSize, blockSize) /* nothing */
287 #define traceSparkEvent(cap, tag) /* nothing */
288 #define traceSparkEvent2(cap, tag, other) /* nothing */
289 #define traceCap(class, cap, msg, ...) /* nothing */
290 #define trace(class, msg, ...) /* nothing */
291 #define debugTrace(class, str, ...) /* nothing */
292 #define debugTraceCap(class, cap, str, ...) /* nothing */
293 #define traceThreadStatus(class, tso) /* nothing */
294 #define traceThreadLabel_(cap, tso, label) /* nothing */
295 INLINE_HEADER void traceEventStartup_ (int n_caps STG_UNUSED) {};
296 #define traceCapEvent(cap, tag) /* nothing */
297 #define traceCapsetEvent(tag, capset, info) /* nothing */
298 #define traceWallClockTime_() /* nothing */
299 #define traceOSProcessInfo_() /* nothing */
300 #define traceSparkCounters_(cap, counters, remaining) /* nothing */
301 #define traceTaskCreate_(taskID, cap) /* nothing */
302 #define traceTaskMigrate_(taskID, cap, new_cap) /* nothing */
303 #define traceTaskDelete_(taskID) /* nothing */
304
305 #endif /* TRACING */
306
307 // If DTRACE is enabled, but neither DEBUG nor TRACING, we need a C land
308 // wrapper for the user-msg probe (as we can't expand that in PrimOps.cmm)
309 //
310 #if !defined(DEBUG) && !defined(TRACING) && defined(DTRACE)
311
312 void dtraceUserMsgWrapper(Capability *cap, char *msg);
313
314 #endif /* !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) */
315
316 // -----------------------------------------------------------------------------
317 // Aliases for static dtrace probes if dtrace is available
318 // -----------------------------------------------------------------------------
319
320 #if defined(DTRACE)
321
322 #define dtraceCreateThread(cap, tid) \
323 HASKELLEVENT_CREATE_THREAD(cap, tid)
324 #define dtraceRunThread(cap, tid) \
325 HASKELLEVENT_RUN_THREAD(cap, tid)
326 #define dtraceStopThread(cap, tid, status, info) \
327 HASKELLEVENT_STOP_THREAD(cap, tid, status, info)
328 #define dtraceThreadRunnable(cap, tid) \
329 HASKELLEVENT_THREAD_RUNNABLE(cap, tid)
330 #define dtraceMigrateThread(cap, tid, new_cap) \
331 HASKELLEVENT_MIGRATE_THREAD(cap, tid, new_cap)
332 #define dtraceThreadWakeup(cap, tid, other_cap) \
333 HASKELLEVENT_THREAD_WAKEUP(cap, tid, other_cap)
334 #define dtraceGcStart(cap) \
335 HASKELLEVENT_GC_START(cap)
336 #define dtraceGcEnd(cap) \
337 HASKELLEVENT_GC_END(cap)
338 #define dtraceRequestSeqGc(cap) \
339 HASKELLEVENT_REQUEST_SEQ_GC(cap)
340 #define dtraceRequestParGc(cap) \
341 HASKELLEVENT_REQUEST_PAR_GC(cap)
342 #define dtraceCreateSparkThread(cap, spark_tid) \
343 HASKELLEVENT_CREATE_SPARK_THREAD(cap, spark_tid)
344 #define dtraceThreadLabel(cap, tso, label) \
345 HASKELLEVENT_THREAD_LABEL(cap, tso, label)
346 INLINE_HEADER void dtraceStartup (int num_caps) {
347 HASKELLEVENT_STARTUP(num_caps);
348 }
349 #define dtraceCapCreate(cap) \
350 HASKELLEVENT_CAP_CREATE(cap)
351 #define dtraceCapDelete(cap) \
352 HASKELLEVENT_CAP_DELETE(cap)
353 #define dtraceCapEnable(cap) \
354 HASKELLEVENT_CAP_ENABLE(cap)
355 #define dtraceCapDisable(cap) \
356 HASKELLEVENT_CAP_DISABLE(cap)
357 #define dtraceUserMsg(cap, msg) \
358 HASKELLEVENT_USER_MSG(cap, msg)
359 #define dtraceGcIdle(cap) \
360 HASKELLEVENT_GC_IDLE(cap)
361 #define dtraceGcWork(cap) \
362 HASKELLEVENT_GC_WORK(cap)
363 #define dtraceGcDone(cap) \
364 HASKELLEVENT_GC_DONE(cap)
365 #define dtraceGcGlobalSync(cap) \
366 HASKELLEVENT_GC_GLOBAL_SYNC(cap)
367 #define dtraceEventGcStats(heap_capset, gens, \
368 copies, slop, fragmentation, \
369 par_n_threads, \
370 par_max_copied, \
371 par_tot_copied) \
372 HASKELLEVENT_GC_STATS(heap_capset, gens, \
373 copies, slop, fragmentation, \
374 par_n_threads, \
375 par_max_copied, \
376 par_tot_copied) \
377 #define dtraceHeapInfo(heap_capset, gens, \
378 maxHeapSize, allocAreaSize, \
379 mblockSize, blockSize) \
380 HASKELLEVENT_HEAP_INFO(heap_capset, gens, \
381 maxHeapSize, allocAreaSize, \
382 mblockSize, blockSize)
383 #define dtraceEventHeapAllocated(cap, heap_capset, \
384 allocated) \
385 HASKELLEVENT_HEAP_ALLOCATED(cap, heap_capset, \
386 allocated)
387 #define dtraceEventHeapSize(heap_capset, size) \
388 HASKELLEVENT_HEAP_SIZE(heap_capset, size)
389 #define dtraceEventHeapLive(heap_capset, live) \
390 HASKELLEVENT_HEAP_LIVE(heap_capset, live)
391 #define dtraceCapsetCreate(capset, capset_type) \
392 HASKELLEVENT_CAPSET_CREATE(capset, capset_type)
393 #define dtraceCapsetDelete(capset) \
394 HASKELLEVENT_CAPSET_DELETE(capset)
395 #define dtraceCapsetAssignCap(capset, capno) \
396 HASKELLEVENT_CAPSET_ASSIGN_CAP(capset, capno)
397 #define dtraceCapsetRemoveCap(capset, capno) \
398 HASKELLEVENT_CAPSET_REMOVE_CAP(capset, capno)
399 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) \
400 HASKELLEVENT_SPARK_COUNTERS(cap, a, b, c, d, e, f, g)
401 #define dtraceSparkCreate(cap) \
402 HASKELLEVENT_SPARK_CREATE(cap)
403 #define dtraceSparkDud(cap) \
404 HASKELLEVENT_SPARK_DUD(cap)
405 #define dtraceSparkOverflow(cap) \
406 HASKELLEVENT_SPARK_OVERFLOW(cap)
407 #define dtraceSparkRun(cap) \
408 HASKELLEVENT_SPARK_RUN(cap)
409 #define dtraceSparkSteal(cap, victim_cap) \
410 HASKELLEVENT_SPARK_STEAL(cap, victim_cap)
411 #define dtraceSparkFizzle(cap) \
412 HASKELLEVENT_SPARK_FIZZLE(cap)
413 #define dtraceSparkGc(cap) \
414 HASKELLEVENT_SPARK_GC(cap)
415 #define dtraceTaskCreate(taskID, cap) \
416 HASKELLEVENT_TASK_CREATE(taskID, cap)
417 #define dtraceTaskMigrate(taskID, cap, new_cap) \
418 HASKELLEVENT_TASK_MIGRATE(taskID, cap, new_cap)
419 #define dtraceTaskDelete(taskID) \
420 HASKELLEVENT_TASK_DELETE(taskID)
421
422 #else /* !defined(DTRACE) */
423
424 #define dtraceCreateThread(cap, tid) /* nothing */
425 #define dtraceRunThread(cap, tid) /* nothing */
426 #define dtraceStopThread(cap, tid, status, info) /* nothing */
427 #define dtraceThreadRunnable(cap, tid) /* nothing */
428 #define dtraceMigrateThread(cap, tid, new_cap) /* nothing */
429 #define dtraceThreadWakeup(cap, tid, other_cap) /* nothing */
430 #define dtraceGcStart(cap) /* nothing */
431 #define dtraceGcEnd(cap) /* nothing */
432 #define dtraceRequestSeqGc(cap) /* nothing */
433 #define dtraceRequestParGc(cap) /* nothing */
434 #define dtraceCreateSparkThread(cap, spark_tid) /* nothing */
435 #define dtraceThreadLabel(cap, tso, label) /* nothing */
436 INLINE_HEADER void dtraceStartup (int num_caps STG_UNUSED) {};
437 #define dtraceUserMsg(cap, msg) /* nothing */
438 #define dtraceGcIdle(cap) /* nothing */
439 #define dtraceGcWork(cap) /* nothing */
440 #define dtraceGcDone(cap) /* nothing */
441 #define dtraceGcGlobalSync(cap) /* nothing */
442 #define dtraceEventGcStats(heap_capset, gens, \
443 copies, slop, fragmentation, \
444 par_n_threads, \
445 par_max_copied, \
446 par_tot_copied) /* nothing */
447 #define dtraceHeapInfo(heap_capset, gens, \
448 maxHeapSize, allocAreaSize, \
449 mblockSize, blockSize) /* nothing */
450 #define dtraceEventHeapAllocated(cap, heap_capset, \
451 allocated) /* nothing */
452 #define dtraceEventHeapSize(heap_capset, size) /* nothing */
453 #define dtraceEventHeapLive(heap_capset, live) /* nothing */
454 #define dtraceCapCreate(cap) /* nothing */
455 #define dtraceCapDelete(cap) /* nothing */
456 #define dtraceCapEnable(cap) /* nothing */
457 #define dtraceCapDisable(cap) /* nothing */
458 #define dtraceCapsetCreate(capset, capset_type) /* nothing */
459 #define dtraceCapsetDelete(capset) /* nothing */
460 #define dtraceCapsetAssignCap(capset, capno) /* nothing */
461 #define dtraceCapsetRemoveCap(capset, capno) /* nothing */
462 #define dtraceSparkCounters(cap, a, b, c, d, e, f, g) /* nothing */
463 #define dtraceSparkCreate(cap) /* nothing */
464 #define dtraceSparkDud(cap) /* nothing */
465 #define dtraceSparkOverflow(cap) /* nothing */
466 #define dtraceSparkRun(cap) /* nothing */
467 #define dtraceSparkSteal(cap, victim_cap) /* nothing */
468 #define dtraceSparkFizzle(cap) /* nothing */
469 #define dtraceSparkGc(cap) /* nothing */
470 #define dtraceTaskCreate(taskID, cap) /* nothing */
471 #define dtraceTaskMigrate(taskID, cap, new_cap) /* nothing */
472 #define dtraceTaskDelete(taskID) /* nothing */
473
474 #endif
475
476 // -----------------------------------------------------------------------------
477 // Trace probes dispatching to various tracing frameworks
478 //
479 // In order to avoid accumulating multiple calls to tracing calls at trace
480 // points, we define inline probe functions that contain the various
481 // invocations.
482 //
483 // Dtrace - dtrace probes are unconditionally added as probe activation is
484 // handled by the dtrace component of the kernel, and inactive probes are
485 // very cheap — usually, one no-op. Consequently, dtrace can be used with
486 // all flavours of the RTS. In addition, we still support logging events to
487 // a file, even in the presence of dtrace. This is, eg, useful when tracing
488 // on a server, but browsing trace information with ThreadScope on a local
489 // client.
490 //
491 // -----------------------------------------------------------------------------
492
493 INLINE_HEADER void traceEventCreateThread(Capability *cap STG_UNUSED,
494 StgTSO *tso STG_UNUSED)
495 {
496 traceSchedEvent(cap, EVENT_CREATE_THREAD, tso, tso->stackobj->stack_size);
497 dtraceCreateThread((EventCapNo)cap->no, (EventThreadID)tso->id);
498 }
499
500 INLINE_HEADER void traceEventRunThread(Capability *cap STG_UNUSED,
501 StgTSO *tso STG_UNUSED)
502 {
503 traceSchedEvent(cap, EVENT_RUN_THREAD, tso, tso->what_next);
504 dtraceRunThread((EventCapNo)cap->no, (EventThreadID)tso->id);
505 }
506
507 INLINE_HEADER void traceEventStopThread(Capability *cap STG_UNUSED,
508 StgTSO *tso STG_UNUSED,
509 StgThreadReturnCode status STG_UNUSED,
510 StgWord32 info STG_UNUSED)
511 {
512 traceSchedEvent2(cap, EVENT_STOP_THREAD, tso, status, info);
513 dtraceStopThread((EventCapNo)cap->no, (EventThreadID)tso->id,
514 (EventThreadStatus)status, (EventThreadID)info);
515 }
516
517 // needs to be EXTERN_INLINE as it is used in another EXTERN_INLINE function
518 EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED,
519 StgTSO *tso STG_UNUSED);
520
521 EXTERN_INLINE void traceEventThreadRunnable(Capability *cap STG_UNUSED,
522 StgTSO *tso STG_UNUSED)
523 {
524 traceSchedEvent(cap, EVENT_THREAD_RUNNABLE, tso, 0);
525 dtraceThreadRunnable((EventCapNo)cap->no, (EventThreadID)tso->id);
526 }
527
528 INLINE_HEADER void traceEventMigrateThread(Capability *cap STG_UNUSED,
529 StgTSO *tso STG_UNUSED,
530 nat new_cap STG_UNUSED)
531 {
532 traceSchedEvent(cap, EVENT_MIGRATE_THREAD, tso, new_cap);
533 dtraceMigrateThread((EventCapNo)cap->no, (EventThreadID)tso->id,
534 (EventCapNo)new_cap);
535 }
536
537 INLINE_HEADER void traceCapCreate(Capability *cap STG_UNUSED)
538 {
539 traceCapEvent(cap, EVENT_CAP_CREATE);
540 dtraceCapCreate((EventCapNo)cap->no);
541 }
542
543 INLINE_HEADER void traceCapDelete(Capability *cap STG_UNUSED)
544 {
545 traceCapEvent(cap, EVENT_CAP_DELETE);
546 dtraceCapDelete((EventCapNo)cap->no);
547 }
548
549 INLINE_HEADER void traceCapEnable(Capability *cap STG_UNUSED)
550 {
551 traceCapEvent(cap, EVENT_CAP_ENABLE);
552 dtraceCapEnable((EventCapNo)cap->no);
553 }
554
555 INLINE_HEADER void traceCapDisable(Capability *cap STG_UNUSED)
556 {
557 traceCapEvent(cap, EVENT_CAP_DISABLE);
558 dtraceCapDisable((EventCapNo)cap->no);
559 }
560
561 INLINE_HEADER void traceEventThreadWakeup(Capability *cap STG_UNUSED,
562 StgTSO *tso STG_UNUSED,
563 nat other_cap STG_UNUSED)
564 {
565 traceSchedEvent(cap, EVENT_THREAD_WAKEUP, tso, other_cap);
566 dtraceThreadWakeup((EventCapNo)cap->no, (EventThreadID)tso->id,
567 (EventCapNo)other_cap);
568 }
569
570 INLINE_HEADER void traceThreadLabel(Capability *cap STG_UNUSED,
571 StgTSO *tso STG_UNUSED,
572 char *label STG_UNUSED)
573 {
574 if (RTS_UNLIKELY(TRACE_sched)) {
575 traceThreadLabel_(cap, tso, label);
576 }
577 dtraceThreadLabel((EventCapNo)cap->no, (EventThreadID)tso->id, label);
578 }
579
580 INLINE_HEADER void traceEventGcStart(Capability *cap STG_UNUSED)
581 {
582 traceGcEvent(cap, EVENT_GC_START);
583 dtraceGcStart((EventCapNo)cap->no);
584 }
585
586 INLINE_HEADER void traceEventGcStartAtT(Capability *cap STG_UNUSED,
587 StgWord64 ts STG_UNUSED)
588 {
589 traceGcEventAtT(cap, ts, EVENT_GC_START);
590 dtraceGcStart((EventCapNo)cap->no);
591 }
592
593 INLINE_HEADER void traceEventGcEnd(Capability *cap STG_UNUSED)
594 {
595 traceGcEvent(cap, EVENT_GC_END);
596 dtraceGcEnd((EventCapNo)cap->no);
597 }
598
599 INLINE_HEADER void traceEventGcEndAtT(Capability *cap STG_UNUSED,
600 StgWord64 ts STG_UNUSED)
601 {
602 traceGcEventAtT(cap, ts, EVENT_GC_END);
603 dtraceGcEnd((EventCapNo)cap->no);
604 }
605
606 INLINE_HEADER void traceEventRequestSeqGc(Capability *cap STG_UNUSED)
607 {
608 traceGcEvent(cap, EVENT_REQUEST_SEQ_GC);
609 dtraceRequestSeqGc((EventCapNo)cap->no);
610 }
611
612 INLINE_HEADER void traceEventRequestParGc(Capability *cap STG_UNUSED)
613 {
614 traceGcEvent(cap, EVENT_REQUEST_PAR_GC);
615 dtraceRequestParGc((EventCapNo)cap->no);
616 }
617
618 INLINE_HEADER void traceEventGcIdle(Capability *cap STG_UNUSED)
619 {
620 traceGcEvent(cap, EVENT_GC_IDLE);
621 dtraceGcIdle((EventCapNo)cap->no);
622 }
623
624 INLINE_HEADER void traceEventGcWork(Capability *cap STG_UNUSED)
625 {
626 traceGcEvent(cap, EVENT_GC_WORK);
627 dtraceGcWork((EventCapNo)cap->no);
628 }
629
630 INLINE_HEADER void traceEventGcDone(Capability *cap STG_UNUSED)
631 {
632 traceGcEvent(cap, EVENT_GC_DONE);
633 dtraceGcDone((EventCapNo)cap->no);
634 }
635
636 INLINE_HEADER void traceEventGcGlobalSync(Capability *cap STG_UNUSED)
637 {
638 traceGcEvent(cap, EVENT_GC_GLOBAL_SYNC);
639 dtraceGcGlobalSync((EventCapNo)cap->no);
640 }
641
642 INLINE_HEADER void traceEventGcStats(Capability *cap STG_UNUSED,
643 CapsetID heap_capset STG_UNUSED,
644 nat gen STG_UNUSED,
645 lnat copied STG_UNUSED,
646 lnat slop STG_UNUSED,
647 lnat fragmentation STG_UNUSED,
648 nat par_n_threads STG_UNUSED,
649 lnat par_max_copied STG_UNUSED,
650 lnat par_tot_copied STG_UNUSED)
651 {
652 if (RTS_UNLIKELY(TRACE_gc)) {
653 traceEventGcStats_(cap, heap_capset, gen,
654 copied, slop, fragmentation,
655 par_n_threads, par_max_copied, par_tot_copied);
656 }
657 dtraceEventGcStats(heap_capset, gens,
658 copies, slop, fragmentation,
659 par_n_threads, par_max_copied, par_tot_copied);
660 }
661
662 INLINE_HEADER void traceEventHeapInfo(CapsetID heap_capset STG_UNUSED,
663 nat gens STG_UNUSED,
664 lnat maxHeapSize STG_UNUSED,
665 lnat allocAreaSize STG_UNUSED,
666 lnat mblockSize STG_UNUSED,
667 lnat blockSize STG_UNUSED)
668 {
669 if (RTS_UNLIKELY(TRACE_gc)) {
670 traceEventHeapInfo_(heap_capset, gens,
671 maxHeapSize, allocAreaSize,
672 mblockSize, blockSize);
673 }
674 dtraceHeapInfo(heap_capset, gens,
675 maxHeapSize, allocAreaSize,
676 mblockSize, blockSize);
677 }
678
679 INLINE_HEADER void traceEventHeapAllocated(Capability *cap STG_UNUSED,
680 CapsetID heap_capset STG_UNUSED,
681 lnat allocated STG_UNUSED)
682 {
683 traceHeapEvent(cap, EVENT_HEAP_ALLOCATED, heap_capset, allocated);
684 dtraceEventHeapAllocated((EventCapNo)cap->no, heap_capset, allocated);
685 }
686
687 INLINE_HEADER void traceEventHeapSize(Capability *cap STG_UNUSED,
688 CapsetID heap_capset STG_UNUSED,
689 lnat heap_size STG_UNUSED)
690 {
691 traceHeapEvent(cap, EVENT_HEAP_SIZE, heap_capset, heap_size);
692 dtraceEventHeapSize(heap_capset, heap_size);
693 }
694
695 INLINE_HEADER void traceEventHeapLive(Capability *cap STG_UNUSED,
696 CapsetID heap_capset STG_UNUSED,
697 lnat heap_live STG_UNUSED)
698 {
699 traceHeapEvent(cap, EVENT_HEAP_LIVE, heap_capset, heap_live);
700 dtraceEventHeapLive(heap_capset, heap_live);
701 }
702
703 /* TODO: at some point we should remove this event, it's covered by
704 * the cap create/delete events.
705 */
706 INLINE_HEADER void traceEventStartup(void)
707 {
708 int n_caps;
709 #ifdef THREADED_RTS
710 // XXX n_capabilities hasn't been initialised yet
711 n_caps = RtsFlags.ParFlags.nNodes;
712 #else
713 n_caps = 1;
714 #endif
715
716 traceEventStartup_(n_caps);
717 dtraceStartup(n_caps);
718 }
719
720 INLINE_HEADER void traceCapsetCreate(CapsetID capset STG_UNUSED,
721 CapsetType capset_type STG_UNUSED)
722 {
723 traceCapsetEvent(EVENT_CAPSET_CREATE, capset, capset_type);
724 dtraceCapsetCreate(capset, capset_type);
725 }
726
727 INLINE_HEADER void traceCapsetDelete(CapsetID capset STG_UNUSED)
728 {
729 traceCapsetEvent(EVENT_CAPSET_DELETE, capset, 0);
730 dtraceCapsetDelete(capset);
731 }
732
733 INLINE_HEADER void traceCapsetAssignCap(CapsetID capset STG_UNUSED,
734 nat capno STG_UNUSED)
735 {
736 traceCapsetEvent(EVENT_CAPSET_ASSIGN_CAP, capset, capno);
737 dtraceCapsetAssignCap(capset, capno);
738 }
739
740 INLINE_HEADER void traceCapsetRemoveCap(CapsetID capset STG_UNUSED,
741 nat capno STG_UNUSED)
742 {
743 traceCapsetEvent(EVENT_CAPSET_REMOVE_CAP, capset, capno);
744 dtraceCapsetRemoveCap(capset, capno);
745 }
746
747 INLINE_HEADER void traceWallClockTime(void)
748 {
749 traceWallClockTime_();
750 /* Note: no DTrace equivalent because it is available to DTrace directly */
751 }
752
753 INLINE_HEADER void traceOSProcessInfo(void)
754 {
755 traceOSProcessInfo_();
756 /* Note: no DTrace equivalent because all this OS process info
757 * is available to DTrace directly */
758 }
759
760 INLINE_HEADER void traceEventCreateSparkThread(Capability *cap STG_UNUSED,
761 StgThreadID spark_tid STG_UNUSED)
762 {
763 traceSparkEvent2(cap, EVENT_CREATE_SPARK_THREAD, spark_tid);
764 dtraceCreateSparkThread((EventCapNo)cap->no, (EventThreadID)spark_tid);
765 }
766
767 INLINE_HEADER void traceSparkCounters(Capability *cap STG_UNUSED)
768 {
769 #ifdef THREADED_RTS
770 if (RTS_UNLIKELY(TRACE_spark_sampled)) {
771 traceSparkCounters_(cap, cap->spark_stats, sparkPoolSize(cap->sparks));
772 }
773 dtraceSparkCounters((EventCapNo)cap->no,
774 cap->spark_stats.created,
775 cap->spark_stats.dud,
776 cap->spark_stats.overflowed,
777 cap->spark_stats.converted,
778 cap->spark_stats.gcd,
779 cap->spark_stats.fizzled,
780 sparkPoolSize(cap->sparks));
781 #endif
782 }
783
784 INLINE_HEADER void traceEventSparkCreate(Capability *cap STG_UNUSED)
785 {
786 traceSparkEvent(cap, EVENT_SPARK_CREATE);
787 dtraceSparkCreate((EventCapNo)cap->no);
788 }
789
790 INLINE_HEADER void traceEventSparkDud(Capability *cap STG_UNUSED)
791 {
792 traceSparkEvent(cap, EVENT_SPARK_DUD);
793 dtraceSparkDud((EventCapNo)cap->no);
794 }
795
796 INLINE_HEADER void traceEventSparkOverflow(Capability *cap STG_UNUSED)
797 {
798 traceSparkEvent(cap, EVENT_SPARK_OVERFLOW);
799 dtraceSparkOverflow((EventCapNo)cap->no);
800 }
801
802 INLINE_HEADER void traceEventSparkRun(Capability *cap STG_UNUSED)
803 {
804 traceSparkEvent(cap, EVENT_SPARK_RUN);
805 dtraceSparkRun((EventCapNo)cap->no);
806 }
807
808 INLINE_HEADER void traceEventSparkSteal(Capability *cap STG_UNUSED,
809 nat victim_cap STG_UNUSED)
810 {
811 traceSparkEvent2(cap, EVENT_SPARK_STEAL, victim_cap);
812 dtraceSparkSteal((EventCapNo)cap->no, (EventCapNo)victim_cap);
813 }
814
815 INLINE_HEADER void traceEventSparkFizzle(Capability *cap STG_UNUSED)
816 {
817 traceSparkEvent(cap, EVENT_SPARK_FIZZLE);
818 dtraceSparkFizzle((EventCapNo)cap->no);
819 }
820
821 INLINE_HEADER void traceEventSparkGC(Capability *cap STG_UNUSED)
822 {
823 traceSparkEvent(cap, EVENT_SPARK_GC);
824 dtraceSparkGc((EventCapNo)cap->no);
825 }
826
827 INLINE_HEADER void traceTaskCreate(Task *task STG_UNUSED,
828 Capability *cap STG_UNUSED)
829 {
830 ASSERT(task->cap == cap);
831 // TODO: asserting task->cap == NULL would be much stronger
832 // (the intention being that the task structure is just created and empty)
833 // but would require large changes of traceTaskCreate calls.
834 ASSERT(cap != NULL);
835 // A new task gets associated with a cap. We also record
836 // the kernel thread id of the task, which should never change.
837 if (RTS_UNLIKELY(TRACE_sched)) {
838 traceTaskCreate_(task, cap);
839 }
840 dtraceTaskCreate(serialisableTaskId(task), (EventCapNo)cap->no);
841 }
842
843 INLINE_HEADER void traceTaskMigrate(Task *task STG_UNUSED,
844 Capability *cap STG_UNUSED,
845 Capability *new_cap STG_UNUSED)
846 {
847 ASSERT(task->cap == cap);
848 ASSERT(cap != NULL);
849 ASSERT(cap != new_cap);
850 ASSERT(new_cap != NULL);
851 // A task migrates from a cap to another.
852 if (RTS_UNLIKELY(TRACE_sched)) {
853 traceTaskMigrate_(task, cap, new_cap);
854 }
855 dtraceTaskMigrate(serialisableTaskId(task), (EventCapNo)cap->no,
856 (EventCapNo)new_cap->no);
857 }
858
859 INLINE_HEADER void traceTaskDelete(Task *task STG_UNUSED)
860 {
861 ASSERT(task->cap != NULL);
862 if (RTS_UNLIKELY(TRACE_sched)) {
863 traceTaskDelete_(task);
864 }
865 dtraceTaskDelete(serialisableTaskId(task));
866 }
867
868 #include "EndPrivate.h"
869
870 #endif /* TRACE_H */