rts: Fix C compiler warnings on Windows
[ghc.git] / rts / Trace.c
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 2006-2009
4 *
5 * Debug and performance tracing
6 *
7 * ---------------------------------------------------------------------------*/
8
9 // external headers
10 #include "Rts.h"
11
12 // internal headers
13 #include "Trace.h"
14
15 #ifdef TRACING
16
17 #include "GetTime.h"
18 #include "GetEnv.h"
19 #include "Stats.h"
20 #include "eventlog/EventLog.h"
21 #include "Threads.h"
22 #include "Printer.h"
23
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27
28 #ifdef DEBUG
29 // debugging flags, set with +RTS -D<something>
30 int DEBUG_sched;
31 int DEBUG_interp;
32 int DEBUG_weak;
33 int DEBUG_gccafs;
34 int DEBUG_gc;
35 int DEBUG_block_alloc;
36 int DEBUG_sanity;
37 int DEBUG_stable;
38 int DEBUG_stm;
39 int DEBUG_prof;
40 int DEBUG_gran;
41 int DEBUG_par;
42 int DEBUG_linker;
43 int DEBUG_squeeze;
44 int DEBUG_hpc;
45 int DEBUG_sparks;
46 #endif
47
48 // events
49 int TRACE_sched;
50 int TRACE_gc;
51 int TRACE_spark_sampled;
52 int TRACE_spark_full;
53 int TRACE_user;
54
55 #ifdef THREADED_RTS
56 static Mutex trace_utx;
57 #endif
58
59 static rtsBool eventlog_enabled;
60
61 /* ---------------------------------------------------------------------------
62 Starting up / shuttting down the tracing facilities
63 --------------------------------------------------------------------------- */
64
65 void initTracing (void)
66 {
67 #ifdef THREADED_RTS
68 initMutex(&trace_utx);
69 #endif
70
71 #ifdef DEBUG
72 #define DEBUG_FLAG(name, class) \
73 class = RtsFlags.DebugFlags.name ? 1 : 0;
74
75 DEBUG_FLAG(scheduler, DEBUG_sched);
76
77 DEBUG_FLAG(interpreter, DEBUG_interp);
78 DEBUG_FLAG(weak, DEBUG_weak);
79 DEBUG_FLAG(gccafs, DEBUG_gccafs);
80 DEBUG_FLAG(gc, DEBUG_gc);
81 DEBUG_FLAG(block_alloc, DEBUG_block_alloc);
82 DEBUG_FLAG(sanity, DEBUG_sanity);
83 DEBUG_FLAG(stable, DEBUG_stable);
84 DEBUG_FLAG(stm, DEBUG_stm);
85 DEBUG_FLAG(prof, DEBUG_prof);
86 DEBUG_FLAG(linker, DEBUG_linker);
87 DEBUG_FLAG(squeeze, DEBUG_squeeze);
88 DEBUG_FLAG(hpc, DEBUG_hpc);
89 DEBUG_FLAG(sparks, DEBUG_sparks);
90 #endif
91
92 // -Ds turns on scheduler tracing too
93 TRACE_sched =
94 RtsFlags.TraceFlags.scheduler ||
95 RtsFlags.DebugFlags.scheduler;
96
97 // -Dg turns on gc tracing too
98 TRACE_gc =
99 RtsFlags.TraceFlags.gc ||
100 RtsFlags.DebugFlags.gc ||
101 RtsFlags.DebugFlags.scheduler;
102 if (TRACE_gc && RtsFlags.GcFlags.giveStats == NO_GC_STATS) {
103 RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
104 }
105
106 TRACE_spark_sampled =
107 RtsFlags.TraceFlags.sparks_sampled;
108
109 // -Dr turns on full spark tracing
110 TRACE_spark_full =
111 RtsFlags.TraceFlags.sparks_full ||
112 RtsFlags.DebugFlags.sparks;
113
114 TRACE_user =
115 RtsFlags.TraceFlags.user;
116
117 eventlog_enabled = RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG;
118
119 /* Note: we can have any of the TRACE_* flags turned on even when
120 eventlog_enabled is off. In the DEBUG way we may be tracing to stderr.
121 */
122
123 if (eventlog_enabled) {
124 initEventLogging();
125 }
126 }
127
128 void endTracing (void)
129 {
130 if (eventlog_enabled) {
131 endEventLogging();
132 }
133 }
134
135 void freeTracing (void)
136 {
137 if (eventlog_enabled) {
138 freeEventLogging();
139 }
140 }
141
142 void resetTracing (void)
143 {
144 if (eventlog_enabled) {
145 abortEventLogging(); // abort eventlog inherited from parent
146 initEventLogging(); // child starts its own eventlog
147 }
148 }
149
150 void tracingAddCapapilities (uint32_t from, uint32_t to)
151 {
152 if (eventlog_enabled) {
153 moreCapEventBufs(from,to);
154 }
155 }
156
157 /* ---------------------------------------------------------------------------
158 Emitting trace messages/events
159 --------------------------------------------------------------------------- */
160
161 #ifdef DEBUG
162 static void tracePreface (void)
163 {
164 #ifdef THREADED_RTS
165 debugBelch("%12lx: ", (unsigned long)osThreadId());
166 #endif
167 if (RtsFlags.TraceFlags.timestamp) {
168 debugBelch("%9" FMT_Word64 ": ", stat_getElapsedTime());
169 }
170 }
171 #endif
172
173 #ifdef DEBUG
174 static char *thread_stop_reasons[] = {
175 [HeapOverflow] = "heap overflow",
176 [StackOverflow] = "stack overflow",
177 [ThreadYielding] = "yielding",
178 [ThreadBlocked] = "blocked",
179 [ThreadFinished] = "finished",
180 [THREAD_SUSPENDED_FOREIGN_CALL] = "suspended while making a foreign call",
181 [6 + BlockedOnMVar] = "blocked on an MVar",
182 [6 + BlockedOnMVarRead] = "blocked on an atomic MVar read",
183 [6 + BlockedOnBlackHole] = "blocked on a black hole",
184 [6 + BlockedOnRead] = "blocked on a read operation",
185 [6 + BlockedOnWrite] = "blocked on a write operation",
186 [6 + BlockedOnDelay] = "blocked on a delay operation",
187 [6 + BlockedOnSTM] = "blocked on STM",
188 [6 + BlockedOnDoProc] = "blocked on asyncDoProc",
189 [6 + BlockedOnCCall] = "blocked on a foreign call",
190 [6 + BlockedOnCCall_Interruptible] = "blocked on a foreign call (interruptible)",
191 [6 + BlockedOnMsgThrowTo] = "blocked on throwTo",
192 [6 + ThreadMigrating] = "migrating"
193 };
194 #endif
195
196 #ifdef DEBUG
197 static void traceSchedEvent_stderr (Capability *cap, EventTypeNum tag,
198 StgTSO *tso,
199 StgWord info1 STG_UNUSED,
200 StgWord info2 STG_UNUSED)
201 {
202 ACQUIRE_LOCK(&trace_utx);
203
204 tracePreface();
205 switch (tag) {
206 case EVENT_CREATE_THREAD: // (cap, thread)
207 debugBelch("cap %d: created thread %" FMT_Word "\n",
208 cap->no, (W_)tso->id);
209 break;
210 case EVENT_RUN_THREAD: // (cap, thread)
211 debugBelch("cap %d: running thread %" FMT_Word " (%s)\n",
212 cap->no, (W_)tso->id, what_next_strs[tso->what_next]);
213 break;
214 case EVENT_THREAD_RUNNABLE: // (cap, thread)
215 debugBelch("cap %d: thread %" FMT_Word " appended to run queue\n",
216 cap->no, (W_)tso->id);
217 break;
218 case EVENT_MIGRATE_THREAD: // (cap, thread, new_cap)
219 debugBelch("cap %d: thread %" FMT_Word " migrating to cap %d\n",
220 cap->no, (W_)tso->id, (int)info1);
221 break;
222 case EVENT_THREAD_WAKEUP: // (cap, thread, info1_cap)
223 debugBelch("cap %d: waking up thread %" FMT_Word " on cap %d\n",
224 cap->no, (W_)tso->id, (int)info1);
225 break;
226
227 case EVENT_STOP_THREAD: // (cap, thread, status)
228 if (info1 == 6 + BlockedOnBlackHole) {
229 debugBelch("cap %d: thread %" FMT_Word " stopped (blocked on black hole owned by thread %lu)\n",
230 cap->no, (W_)tso->id, (long)info2);
231 } else {
232 debugBelch("cap %d: thread %" FMT_Word " stopped (%s)\n",
233 cap->no, (W_)tso->id, thread_stop_reasons[info1]);
234 }
235 break;
236 default:
237 debugBelch("cap %d: thread %" FMT_Word ": event %d\n\n",
238 cap->no, (W_)tso->id, tag);
239 break;
240 }
241
242 RELEASE_LOCK(&trace_utx);
243 }
244 #endif
245
246 void traceSchedEvent_ (Capability *cap, EventTypeNum tag,
247 StgTSO *tso, StgWord info1, StgWord info2)
248 {
249 #ifdef DEBUG
250 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
251 traceSchedEvent_stderr(cap, tag, tso, info1, info2);
252 } else
253 #endif
254 {
255 postSchedEvent(cap,tag,tso ? tso->id : 0, info1, info2);
256 }
257 }
258
259 #ifdef DEBUG
260 static void traceGcEvent_stderr (Capability *cap, EventTypeNum tag)
261 {
262 ACQUIRE_LOCK(&trace_utx);
263
264 tracePreface();
265 switch (tag) {
266 case EVENT_REQUEST_SEQ_GC: // (cap)
267 debugBelch("cap %d: requesting sequential GC\n", cap->no);
268 break;
269 case EVENT_REQUEST_PAR_GC: // (cap)
270 debugBelch("cap %d: requesting parallel GC\n", cap->no);
271 break;
272 case EVENT_GC_START: // (cap)
273 debugBelch("cap %d: starting GC\n", cap->no);
274 break;
275 case EVENT_GC_END: // (cap)
276 debugBelch("cap %d: finished GC\n", cap->no);
277 break;
278 case EVENT_GC_IDLE: // (cap)
279 debugBelch("cap %d: GC idle\n", cap->no);
280 break;
281 case EVENT_GC_WORK: // (cap)
282 debugBelch("cap %d: GC working\n", cap->no);
283 break;
284 case EVENT_GC_DONE: // (cap)
285 debugBelch("cap %d: GC done\n", cap->no);
286 break;
287 case EVENT_GC_GLOBAL_SYNC: // (cap)
288 debugBelch("cap %d: all caps stopped for GC\n", cap->no);
289 break;
290 default:
291 barf("traceGcEvent: unknown event tag %d", tag);
292 break;
293 }
294
295 RELEASE_LOCK(&trace_utx);
296 }
297 #endif
298
299 void traceGcEvent_ (Capability *cap, EventTypeNum tag)
300 {
301 #ifdef DEBUG
302 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
303 traceGcEvent_stderr(cap, tag);
304 } else
305 #endif
306 {
307 /* currently all GC events are nullary events */
308 postEvent(cap, tag);
309 }
310 }
311
312 void traceGcEventAtT_ (Capability *cap, StgWord64 ts, EventTypeNum tag)
313 {
314 #ifdef DEBUG
315 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
316 traceGcEvent_stderr(cap, tag);
317 } else
318 #endif
319 {
320 /* assuming nullary events and explicitly inserting a timestamp */
321 postEventAtTimestamp(cap, ts, tag);
322 }
323 }
324
325 void traceHeapEvent_ (Capability *cap,
326 EventTypeNum tag,
327 CapsetID heap_capset,
328 W_ info1)
329 {
330 #ifdef DEBUG
331 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
332 /* no stderr equivalent for these ones */
333 } else
334 #endif
335 {
336 postHeapEvent(cap, tag, heap_capset, info1);
337 }
338 }
339
340 void traceEventHeapInfo_ (CapsetID heap_capset,
341 uint32_t gens,
342 W_ maxHeapSize,
343 W_ allocAreaSize,
344 W_ mblockSize,
345 W_ blockSize)
346 {
347 #ifdef DEBUG
348 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
349 /* no stderr equivalent for these ones */
350 } else
351 #endif
352 {
353 postEventHeapInfo(heap_capset, gens,
354 maxHeapSize, allocAreaSize,
355 mblockSize, blockSize);
356 }
357 }
358
359 void traceEventGcStats_ (Capability *cap,
360 CapsetID heap_capset,
361 uint32_t gen,
362 W_ copied,
363 W_ slop,
364 W_ fragmentation,
365 uint32_t par_n_threads,
366 W_ par_max_copied,
367 W_ par_tot_copied)
368 {
369 #ifdef DEBUG
370 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
371 /* no stderr equivalent for these ones */
372 } else
373 #endif
374 {
375 postEventGcStats(cap, heap_capset, gen,
376 copied, slop, fragmentation,
377 par_n_threads, par_max_copied, par_tot_copied);
378 }
379 }
380
381 void traceCapEvent (Capability *cap,
382 EventTypeNum tag)
383 {
384 #ifdef DEBUG
385 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
386 ACQUIRE_LOCK(&trace_utx);
387
388 tracePreface();
389 switch (tag) {
390 case EVENT_CAP_CREATE: // (cap)
391 debugBelch("cap %d: initialised\n", cap->no);
392 break;
393 case EVENT_CAP_DELETE: // (cap)
394 debugBelch("cap %d: shutting down\n", cap->no);
395 break;
396 case EVENT_CAP_ENABLE: // (cap)
397 debugBelch("cap %d: enabling capability\n", cap->no);
398 break;
399 case EVENT_CAP_DISABLE: // (cap)
400 debugBelch("cap %d: disabling capability\n", cap->no);
401 break;
402 }
403 RELEASE_LOCK(&trace_utx);
404 } else
405 #endif
406 {
407 if (eventlog_enabled) {
408 postCapEvent(tag, (EventCapNo)cap->no);
409 }
410 }
411 }
412
413 void traceCapsetEvent (EventTypeNum tag,
414 CapsetID capset,
415 StgWord info)
416 {
417 #ifdef DEBUG
418 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR && TRACE_sched)
419 // When events go to stderr, it is annoying to see the capset
420 // events every time, so we only emit them with -Ds.
421 {
422 ACQUIRE_LOCK(&trace_utx);
423
424 tracePreface();
425 switch (tag) {
426 case EVENT_CAPSET_CREATE: // (capset, capset_type)
427 debugBelch("created capset %" FMT_Word32 " of type %d\n", capset,
428 (int)info);
429 break;
430 case EVENT_CAPSET_DELETE: // (capset)
431 debugBelch("deleted capset %" FMT_Word32 "\n", capset);
432 break;
433 case EVENT_CAPSET_ASSIGN_CAP: // (capset, capno)
434 debugBelch("assigned cap %" FMT_Word " to capset %" FMT_Word32 "\n",
435 info, capset);
436 break;
437 case EVENT_CAPSET_REMOVE_CAP: // (capset, capno)
438 debugBelch("removed cap %" FMT_Word " from capset %" FMT_Word32
439 "\n", info, capset);
440 break;
441 }
442 RELEASE_LOCK(&trace_utx);
443 } else
444 #endif
445 {
446 if (eventlog_enabled) {
447 postCapsetEvent(tag, capset, info);
448 }
449 }
450 }
451
452 void traceWallClockTime_(void) {
453 if (eventlog_enabled) {
454 postWallClockTime(CAPSET_CLOCKDOMAIN_DEFAULT);
455 }
456 }
457
458 void traceOSProcessInfo_(void) {
459 if (eventlog_enabled) {
460 postCapsetEvent(EVENT_OSPROCESS_PID,
461 CAPSET_OSPROCESS_DEFAULT,
462 getpid());
463
464 #if !defined (mingw32_HOST_OS)
465 /* Windows has no strong concept of process hierarchy, so no getppid().
466 * In any case, this trace event is mainly useful for tracing programs
467 * that use 'forkProcess' which Windows doesn't support anyway.
468 */
469 postCapsetEvent(EVENT_OSPROCESS_PPID,
470 CAPSET_OSPROCESS_DEFAULT,
471 getppid());
472 #endif
473 {
474 char buf[256];
475 snprintf(buf, sizeof(buf), "GHC-%s %s", ProjectVersion, RtsWay);
476 postCapsetStrEvent(EVENT_RTS_IDENTIFIER,
477 CAPSET_OSPROCESS_DEFAULT,
478 buf);
479 }
480 {
481 int argc = 0; char **argv;
482 getFullProgArgv(&argc, &argv);
483 if (argc != 0) {
484 postCapsetVecEvent(EVENT_PROGRAM_ARGS,
485 CAPSET_OSPROCESS_DEFAULT,
486 argc, argv);
487 }
488 }
489 {
490 int envc = 0; char **envv;
491 getProgEnvv(&envc, &envv);
492 if (envc != 0) {
493 postCapsetVecEvent(EVENT_PROGRAM_ENV,
494 CAPSET_OSPROCESS_DEFAULT,
495 envc, envv);
496 }
497 freeProgEnvv(envc, envv);
498 }
499 }
500 }
501
502 #ifdef DEBUG
503 static void traceSparkEvent_stderr (Capability *cap, EventTypeNum tag,
504 StgWord info1)
505 {
506 ACQUIRE_LOCK(&trace_utx);
507
508 tracePreface();
509 switch (tag) {
510
511 case EVENT_CREATE_SPARK_THREAD: // (cap, spark_thread)
512 debugBelch("cap %d: creating spark thread %lu\n",
513 cap->no, (long)info1);
514 break;
515 case EVENT_SPARK_CREATE: // (cap)
516 debugBelch("cap %d: added spark to pool\n",
517 cap->no);
518 break;
519 case EVENT_SPARK_DUD: // (cap)
520 debugBelch("cap %d: discarded dud spark\n",
521 cap->no);
522 break;
523 case EVENT_SPARK_OVERFLOW: // (cap)
524 debugBelch("cap %d: discarded overflowed spark\n",
525 cap->no);
526 break;
527 case EVENT_SPARK_RUN: // (cap)
528 debugBelch("cap %d: running a spark\n",
529 cap->no);
530 break;
531 case EVENT_SPARK_STEAL: // (cap, victim_cap)
532 debugBelch("cap %d: stealing a spark from cap %d\n",
533 cap->no, (int)info1);
534 break;
535 case EVENT_SPARK_FIZZLE: // (cap)
536 debugBelch("cap %d: fizzled spark removed from pool\n",
537 cap->no);
538 break;
539 case EVENT_SPARK_GC: // (cap)
540 debugBelch("cap %d: GCd spark removed from pool\n",
541 cap->no);
542 break;
543 default:
544 barf("traceSparkEvent: unknown event tag %d", tag);
545 break;
546 }
547
548 RELEASE_LOCK(&trace_utx);
549 }
550 #endif
551
552 void traceSparkEvent_ (Capability *cap, EventTypeNum tag, StgWord info1)
553 {
554 #ifdef DEBUG
555 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
556 traceSparkEvent_stderr(cap, tag, info1);
557 } else
558 #endif
559 {
560 postSparkEvent(cap,tag,info1);
561 }
562 }
563
564 void traceSparkCounters_ (Capability *cap,
565 SparkCounters counters,
566 StgWord remaining)
567 {
568 #ifdef DEBUG
569 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
570 /* we currently don't do debug tracing of spark stats but we must
571 test for TRACE_STDERR because of the !eventlog_enabled case. */
572 } else
573 #endif
574 {
575 postSparkCountersEvent(cap, counters, remaining);
576 }
577 }
578
579 void traceTaskCreate_ (Task *task,
580 Capability *cap)
581 {
582 #ifdef DEBUG
583 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
584 /* We currently don't do debug tracing of tasks but we must
585 test for TRACE_STDERR because of the !eventlog_enabled case. */
586 } else
587 #endif
588 {
589 EventTaskId taskid = serialisableTaskId(task);
590 EventKernelThreadId tid = kernelThreadId();
591 postTaskCreateEvent(taskid, cap->no, tid);
592 }
593 }
594
595 void traceTaskMigrate_ (Task *task,
596 Capability *cap,
597 Capability *new_cap)
598 {
599 #ifdef DEBUG
600 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
601 /* We currently don't do debug tracing of tasks but we must
602 test for TRACE_STDERR because of the !eventlog_enabled case. */
603 } else
604 #endif
605 {
606 EventTaskId taskid = serialisableTaskId(task);
607 postTaskMigrateEvent(taskid, cap->no, new_cap->no);
608 }
609 }
610
611 void traceTaskDelete_ (Task *task)
612 {
613 #ifdef DEBUG
614 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
615 /* We currently don't do debug tracing of tasks but we must
616 test for TRACE_STDERR because of the !eventlog_enabled case. */
617 } else
618 #endif
619 {
620 EventTaskId taskid = serialisableTaskId(task);
621 postTaskDeleteEvent(taskid);
622 }
623 }
624
625 #ifdef DEBUG
626 static void vtraceCap_stderr(Capability *cap, char *msg, va_list ap)
627 {
628 ACQUIRE_LOCK(&trace_utx);
629
630 tracePreface();
631 debugBelch("cap %d: ", cap->no);
632 vdebugBelch(msg,ap);
633 debugBelch("\n");
634
635 RELEASE_LOCK(&trace_utx);
636 }
637
638 static void traceCap_stderr(Capability *cap, char *msg, ...)
639 {
640 va_list ap;
641 va_start(ap,msg);
642 vtraceCap_stderr(cap, msg, ap);
643 va_end(ap);
644 }
645 #endif
646
647 void traceCap_(Capability *cap, char *msg, ...)
648 {
649 va_list ap;
650 va_start(ap,msg);
651
652 #ifdef DEBUG
653 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
654 vtraceCap_stderr(cap, msg, ap);
655 } else
656 #endif
657 {
658 postCapMsg(cap, msg, ap);
659 }
660
661 va_end(ap);
662 }
663
664 #ifdef DEBUG
665 static void vtrace_stderr(char *msg, va_list ap)
666 {
667 ACQUIRE_LOCK(&trace_utx);
668
669 tracePreface();
670 vdebugBelch(msg,ap);
671 debugBelch("\n");
672
673 RELEASE_LOCK(&trace_utx);
674 }
675 #endif
676
677 void trace_(char *msg, ...)
678 {
679 va_list ap;
680 va_start(ap,msg);
681
682 #ifdef DEBUG
683 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
684 vtrace_stderr(msg, ap);
685 } else
686 #endif
687 {
688 postMsg(msg, ap);
689 }
690
691 va_end(ap);
692 }
693
694 void traceUserMsg(Capability *cap, char *msg)
695 {
696 /* Note: normally we don't check the TRACE_* flags here as they're checked
697 by the wrappers in Trace.h. But traceUserMsg is special since it has no
698 wrapper (it's called from cmm code), so we check TRACE_user here
699 */
700 #ifdef DEBUG
701 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR && TRACE_user) {
702 // Use "%s" as format string to ignore format specifiers in msg (#3874).
703 traceCap_stderr(cap, "%s", msg);
704 } else
705 #endif
706 {
707 if (eventlog_enabled && TRACE_user) {
708 postUserEvent(cap, EVENT_USER_MSG, msg);
709 }
710 }
711 dtraceUserMsg(cap->no, msg);
712 }
713
714 void traceUserMarker(Capability *cap, char *markername)
715 {
716 /* Note: traceUserMarker is special since it has no wrapper (it's called
717 from cmm code), so we check eventlog_enabled and TRACE_user here.
718 */
719 #ifdef DEBUG
720 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR && TRACE_user) {
721 traceCap_stderr(cap, "User marker: %s", markername);
722 } else
723 #endif
724 {
725 if (eventlog_enabled && TRACE_user) {
726 postUserEvent(cap, EVENT_USER_MARKER, markername);
727 }
728 }
729 dtraceUserMarker(cap->no, markername);
730 }
731
732
733 void traceThreadLabel_(Capability *cap,
734 StgTSO *tso,
735 char *label)
736 {
737 #ifdef DEBUG
738 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
739 ACQUIRE_LOCK(&trace_utx);
740 tracePreface();
741 debugBelch("cap %d: thread %" FMT_Word " has label %s\n",
742 cap->no, (W_)tso->id, label);
743 RELEASE_LOCK(&trace_utx);
744 } else
745 #endif
746 {
747 postThreadLabel(cap, tso->id, label);
748 }
749 }
750
751 void traceThreadStatus_ (StgTSO *tso USED_IF_DEBUG)
752 {
753 #ifdef DEBUG
754 if (RtsFlags.TraceFlags.tracing == TRACE_STDERR) {
755 printThreadStatus(tso);
756 } else
757 #endif
758 {
759 /* nothing - no event for this one yet */
760 }
761 }
762
763 #ifdef DEBUG
764 void traceBegin (const char *str, ...)
765 {
766 va_list ap;
767 va_start(ap,str);
768
769 ACQUIRE_LOCK(&trace_utx);
770
771 tracePreface();
772 vdebugBelch(str,ap);
773 va_end(ap);
774 }
775
776 void traceEnd (void)
777 {
778 debugBelch("\n");
779 RELEASE_LOCK(&trace_utx);
780 }
781 #endif /* DEBUG */
782
783 #endif /* TRACING */
784
785 // If DTRACE is enabled, but neither DEBUG nor TRACING, we need a C land
786 // wrapper for the user-msg probe (as we can't expand that in PrimOps.cmm)
787 //
788 #if !defined(DEBUG) && !defined(TRACING) && defined(DTRACE)
789
790 void dtraceUserMsgWrapper(Capability *cap, char *msg)
791 {
792 dtraceUserMsg(cap->no, msg);
793 }
794
795 void dtraceUserMarkerWrapper(Capability *cap, char *msg)
796 {
797 dtraceUserMarker(cap->no, msg);
798 }
799
800 #endif /* !defined(DEBUG) && !defined(TRACING) && defined(DTRACE) */