Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Posix_Wrapp.c
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #include "Posix_Wrapp.h"
20 
21 #define _GNU_SOURCE
22 #include <getopt.h>
23 
24 
25 #include "Timer.h"
26 #include "Event_Desc.h"
27 #include "Event_Pack.h"
28 #include "VMPI.h"
29 #include "Stream_MGR.h"
30 #include "Posix_Profile.h"
31 #include "MALP_Config.h"
32 
33 #include <stdarg.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 
38 
39 /* Interception table */
41 
42 static int posix_wrap_gate = 0;
43 
45 {
46  posix_wrap_gate = 1;
47 }
48 
49 
51 {
52  posix_wrap_gate = 0;
53 }
54 
55 void ___TEST_LOAD_SYMBOL( Wrapped_symbol symb, const char * const symbol )
56 {
57  if( Tracelib_symbol_table[ symb ].p == NULL )
58  {
59  Tracelib_symbol_table[ symb ].p = dlsym( RTLD_NEXT , symbol );
60  if( Tracelib_symbol_table[ symb ].p == NULL )
61  {
62  return;
63  }
64  }
65 }
66 
67 
68 
70 {
71  TEST_LOAD_SYMBOL(calloc);
73 
74  int i;
75 
76  for( i = 0 ; i < T_POSIX_COUNT ; i++ )
77  {
79  }
80 
81 }
82 
83 
84 
85 static inline void Wrapp_Format( struct MALP_Trace_Event * event, Wrapped_symbol s, uint64_t start , uint64_t duration, int64_t size, void * ptr )
86 {
87  MALP_Trace_Event_fill( event, MALP_EVENT_WRAPPED, start, duration );
88 
89  event->event.wrapped_event.type = s;
90  event->event.wrapped_event.size = size;
91  event->event.wrapped_event.ptr = ptr;
92 
93 }
94 
95 
96 static inline void Wrap_Submit( struct MALP_Trace_Event * event )
97 {
98  if( (event->type == MALP_EVENT_NONE) || !Stream_desc_get() )
99  return;
100 
101  Event_Packer_push(event);
102 }
103 
104 static inline void Wrapp_OTF_enter( uint64_t timestamp, Wrapped_symbol symbol )
105 {
106  /********************************/
107  /* EMIT OTF ENTER */
108  /********************************/
109 
110  struct MALP_Trace_Event otf_event;
111 
112  uint64_t _begin = Timer_tsc ();
113 
114  MALP_Trace_Event_fill( &otf_event, MALP_EVENT_OTF, timestamp, 0);
115  OTF_Event_forge( &otf_event, OTF_EVENT_ENTER,
116  MALP_EVENT_WRAPPED, symbol );
117  Wrap_Submit(&otf_event);
118 }
119 
120 static inline void Wrapp_OTF_leave( uint64_t end, uint64_t start, Wrapped_symbol symbol )
121 {
122  /********************************/
123  /* EMIT OTF LEAVE */
124  /********************************/
125 
126  struct MALP_Trace_Event otf_event;
127 
128  uint64_t _begin = Timer_tsc ();
129 
130  MALP_Trace_Event_fill( &otf_event, MALP_EVENT_OTF, end, end - start);
131  OTF_Event_forge( &otf_event, OTF_EVENT_LEAVE,
132  MALP_EVENT_WRAPPED, symbol );
133  Wrap_Submit(&otf_event);
134 }
135 
136 
static struct Stream_Descriptor * Stream_desc_get()
Getter on the current Stream_Descriptor.
Definition: Stream_MGR.h:147
static void Wrapp_OTF_leave(uint64_t end, uint64_t start, Wrapped_symbol symbol)
Definition: Posix_Wrapp.c:120
int OTF_Event_forge(struct MALP_Trace_Event *event, OTF_Event_type enterleave, MALP_Trace_event_type type, uint64_t subtype)
static void Wrapp_OTF_enter(uint64_t timestamp, Wrapped_symbol symbol)
Definition: Posix_Wrapp.c:104
void * p
the void* (to be get by dlsym)
Definition: Posix_Wrapp.h:32
void Event_Packer_push(struct MALP_Trace_Event *event)
Sends an event.
Definition: Event_Pack.c:141
static void MALP_Trace_Event_fill(struct MALP_Trace_Event *event, MALP_Trace_event_type type, uint64_t timestamp, uint64_t duration)
Definition: Stream_MGR.h:186
Struct defining an event.
Definition: Event_Desc.h:82
static void Wrapp_Format(struct MALP_Trace_Event *event, Wrapped_symbol s, uint64_t start, uint64_t duration, int64_t size, void *ptr)
Definition: Posix_Wrapp.c:85
static int posix_wrap_gate
Definition: Posix_Wrapp.c:42
void Wrapp_enable()
Definition: Posix_Wrapp.c:44
MALP_Trace_event_type type
The type of the event.
Definition: Event_Desc.h:85
The event contains wrapped function informations.
Definition: Event_Desc.h:46
#define TEST_LOAD_SYMBOL(a)
Definition: Posix_Wrapp.h:83
void ___TEST_LOAD_SYMBOL(Wrapped_symbol symb, const char *const symbol)
Definition: Posix_Wrapp.c:55
Wrapped_symbol
enum indicating which symbols are wrapped
Union defining a function pointer.
Definition: Posix_Wrapp.h:31
union function_table_elem Tracelib_symbol_table[T_POSIX_COUNT]
The table containing every wrapped symbols.
Definition: Posix_Wrapp.c:40
void POSIX_profile_init()
Definition: Posix_Profile.c:45
None type event.
Definition: Event_Desc.h:43
Enter + Leave events for OTF2 compatibility.
Definition: Event_Desc.h:47
void Wrapp_disable()
Definition: Posix_Wrapp.c:50
void Posix_Wrapp_init()
Definition: Posix_Wrapp.c:69
static const char *const Wrapped_symbol_names[T_POSIX_COUNT]
Array containing wrapped symbols names.
static void Wrap_Submit(struct MALP_Trace_Event *event)
Definition: Posix_Wrapp.c:96