po_hi_utils.h 3.94 KB
Newer Older
1
2
3
4
5
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
yoogx's avatar
yoogx committed
6
 * For more informations, please visit http://taste.tuxfamily.org/wiki
7
 *
8
 * Copyright (C) 2007-2009 Telecom ParisTech, 2010-2017 ESA & ISAE.
9
10
11
12
13
14
15
16
17
18
19
20
 */

#ifndef __PO_HI_UTILS_H__
#define __PO_HI_UTILS_H__

#include <po_hi_time.h>
#include <po_hi_types.h>

/*
 * Take a rate as argument, returns the probability that we meet this rate.
 */
int __po_hi_compute_miss (__po_hi_uint8_t rate);
21
22

unsigned long __po_hi_swap_byte (unsigned long value);
23

yoogx's avatar
yoogx committed
24
#if defined(__PO_HI_USE_VCD) && defined(__unix__)
25

26
27
28
#include <pthread.h>
#include <string.h>

29
30
31
32
33
/* Variable keeping track of whether VCD tracing is enabled or not */
enum tagVCD {
    VCD_UNCHECKED,
    VCD_DISABLED,
    VCD_ENABLED
34
};
35

36
37
38
39
void __po_hi_instrumentation_vcd_init (void);

#define __PO_HI_INSTRUMENTATION_VCD_INIT __po_hi_instrumentation_vcd_init ();

40
41
#define __PO_HI_INSTRUMENTATION_VCD_WRITE(s, args...)                          \
   {                                                                           \
42
      extern enum tagVCD VCD_state;                                            \
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
      if (VCD_state == VCD_UNCHECKED) {                                        \
          VCD_state = NULL == getenv("VCD_ENABLED")?VCD_DISABLED:VCD_ENABLED;  \
      }                                                                        \
      if (VCD_state == VCD_ENABLED) {                                          \
          extern int               __po_hi_vcd_file;                           \
          extern __po_hi_time_t    __po_hi_vcd_start_time;                     \
          extern pthread_mutex_t   __po_hi_vcd_mutex;                          \
          __po_hi_time_t           __po_hi_vcd_current_time;                   \
          char                    buf[1024];                                   \
          int                     size_to_write = 0;                           \
          uint64_t                st,ct,et = 0;                                \
                                                                               \
          pthread_mutex_lock (&__po_hi_vcd_mutex);                             \
                                                                               \
          if (__po_hi_get_time(&__po_hi_vcd_current_time) != __PO_HI_SUCCESS)  \
          {                                                                    \
             __DEBUGMSG("[POHIC-INSTRUMENTATION] Could not retrieve time\n");  \
          }                                                                    \
          else                                                                 \
          {                                                                    \
             st = __PO_HI_TIME_TO_US(__po_hi_vcd_start_time);                  \
             ct = __PO_HI_TIME_TO_US(__po_hi_vcd_current_time);                \
             et = ct - st ;                                                    \
             memset (buf, '\0', 1024);                                         \
             size_to_write = sprintf (buf, "#%llu\n", et);                     \
             write (__po_hi_vcd_file, buf, size_to_write);                     \
                                                                               \
             memset (buf, '\0', 1024);                                         \
             size_to_write = sprintf (buf, s, ##args);                         \
             write (__po_hi_vcd_file, buf, size_to_write);                     \
          }                                                                    \
          pthread_mutex_unlock (&__po_hi_vcd_mutex);                           \
75
      }                                                                        \
76
77
78
79
80
81
   }
#else
   #define __PO_HI_INSTRUMENTATION_VCD_WRITE(s, args...)
   #define __PO_HI_INSTRUMENTATION_VCD_INIT
#endif

yoogx's avatar
yoogx committed
82
#endif /* __PO_HI_UTILS_H__ */