Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
let make distcheck work
[simgrid.git] / examples / msg / messages.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 /** \file messages.h
9  *  \ingroup MSG_examples
10  *  \brief Convenient debuging functions that should be used in combination with 
11  *  the perl-script tools/MSG_visualization/colorize.pl.
12 */
13
14 #ifndef MESSAGES_H
15 #define MESSAGES_H
16
17 #include <stdio.h>
18 #include <stdarg.h>
19 #include "msg/datatypes.h"
20 #include "xbt/error.h"
21
22 /** just like an assert.
23  * This function is used to ensure that a condition is true. 
24  * If not, it prints an error message (with the virtual date and the
25  * PID of the #m_process_t that called it).
26  */
27 static void ASSERT(int value, const char *fmt, ...)
28 {
29   m_process_t self = MSG_process_self();
30   va_list ap;
31
32   if(!value) {
33     va_start(ap, fmt);
34     if (self)
35       fprintf(stderr, "[%Lg] P%d | ", MSG_getClock(),
36               MSG_process_get_PID(self));
37     vfprintf(stderr, fmt, ap);
38     va_end(ap);
39     
40     xbt_abort();
41   }
42   return;
43 }
44
45 /** Die
46  * Just like #ASSERT() except you already know that the condition does not hold 
47  * true.
48  */
49 static void DIE(const char *fmt, ...)
50 {
51   m_process_t self = MSG_process_self();
52   va_list ap;
53
54   va_start(ap, fmt);
55   if (self)
56     fprintf(stderr, "[%Lg] P%d | ", MSG_getClock(),
57             MSG_process_get_PID(self));
58   vfprintf(stderr, fmt, ap);
59   va_end(ap);
60
61   xbt_abort();
62   return;
63 }
64
65 /** 
66  * Print a one-line message with the virtual date and the PID of the #m_process_t
67  * that called it
68  */
69 static void PRINT_MESSAGE(const char *fmt, ...)
70 {
71 #ifdef VERBOSE
72   m_process_t self = MSG_process_self();
73   va_list ap;
74
75   va_start(ap, fmt);
76   if (self)
77     fprintf(stderr, "[%Lg] P%d | (%s:%s) ", MSG_getClock(),
78             MSG_process_get_PID(self), MSG_host_self()->name, self->name);
79   vfprintf(stderr, fmt, ap);
80   va_end(ap);
81 #endif
82   return;
83 }
84
85 /** 
86  * Just like #PRINT_MESSAGE() except that it prints DEBUG in front of the line.
87  */
88 static void PRINT_DEBUG_MESSAGE(const char *fmt, ...)
89 {
90 #ifdef VERBOSE
91   m_process_t self = MSG_process_self();
92   va_list ap;
93
94   va_start(ap, fmt);
95   if (self)
96     fprintf(stderr, "DEBUG [%Lg] P%d | (%s) ", MSG_getClock(),
97             MSG_process_get_PID(self), MSG_host_self()->name);
98   vfprintf(stderr, fmt, ap);
99   va_end(ap);
100 #endif
101   return;
102 }
103
104 #endif