Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Event_Pack.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 "Event_Pack.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "Stream_MGR.h"
25 #include "Posix_Wrapp.h"
26 
28 
29 
31 {
32  Event_Packer()->pack = calloc( 1, sizeof(struct Event_Pack) );
33 
34  Event_Packer()->lock = 0;
35 
36  if( !Event_Packer()->pack )
37  {
38  perror("malloc");
39  exit(1);
40  }
41 
42  VMPI_Partition_desc *an_desc = VMPI_Get_desc_by_name("Analyzer");
43 
44  if( !an_desc)
45  {
46  /* If there is no analyzer lets try to find an IO_Connector
47  * in writing mode to store a post mortem trace
48  */
49  an_desc = VMPI_Get_desc_by_name("IO_WRITE");
50 
51  if(!an_desc)
52  {
53  printf("ERRROR : Could not locate either an IO partition or an Analyzer\n");
54  exit(1);
55  }
56  }
57 
58  int target_partition_id = an_desc->id;
59 
60  VMPI_Map map;
61  VMPI_Map_clear( &map );
62 
63  if( VMPI_Map_partitions( target_partition_id, VMPI_MAP_ROUND_ROBIN, &map) )
64  {
65  printf("Failed to map Instrumentation to Analyzer or IO Connector\n");
66  exit(1);
67  }
68 
70 
71  VMPI_Stream_open_map( &Event_Packer()->stream, &map, "w" );
72 }
73 
75 {
78  free( Event_Packer()->pack );
79  Event_Packer()->pack = NULL;
80 }
81 
82 
84 {
85  /* Otherwise process the actual event */
87 
89  {
91  }
92 
93  if( event->type == MALP_EVENT_META )
94  {
96  }
97 
98  memcpy( &Event_Packer()->pack->events[Event_Packer()->pack->offset], event, sizeof( struct MALP_Trace_Event ) );
99 
100  Event_Packer()->pack->offset++;
101 
103 
104 }
105 
106 
108 {
109  if( !__trace_module )
110  return;
111 
112  struct MALP_Trace_Event event;
113  void *ret;
114 
115  ret = Buffered_FIFO_pop( &Stream_infos_get()->mpi_wrapped_event_buffer, &event);
116 
117  while( ret )
118  {
119  /* We call the "no lock" version as we are only called from locked CTX*/
120  __Event_Packer_push( &event );
121  ret = Buffered_FIFO_pop( &Stream_infos_get()->mpi_wrapped_event_buffer, &event);
122  }
123 }
124 
125 
127 {
128  if( !__trace_module )
129  return;
130 
131  if(MAX_PENDING_EVENT < Buffered_FIFO_count(&Stream_infos_get()->mpi_wrapped_event_buffer))
132  return;
133 
134  Buffered_FIFO_push( &Stream_infos_get()->mpi_wrapped_event_buffer, (void *)event );
135 }
136 
137 
138 
140 
142 {
144  {
145  return;
146  }
147 
148  if( Stream_Infos_is_in_mpi() )
149  {
151  }
152  else
153  {
154  /* First lets try to process pending events */
156 
157  __Event_Packer_push(event);
158  }
159 
161 }
162 
163 
165 {
166  if( Event_Packer()->pack->offset )
167  {
168  /* Set locus */
171 
172  /* Send events */
173  VMPI_Stream_write( &Event_Packer()->stream, (char *)Event_Packer()->pack, 1 );
174 
175  /* Clear context */
176  Event_Packer()->pack->offset = 0;
178  }
179 }
void Event_Packer_flush()
Processes the send of all events present in the internal FIFO.
Definition: Event_Pack.c:164
uint8_t contains_metadata
Indicates whether the pack contains at least one MALP_EVENT_META event.
Definition: Event_Desc.h:108
Defines a map.
Definition: VMPI.h:287
MALP_Spinlock is_in_instrum
Definition: Event_Pack.c:139
struct Event_Pack * pack
The event pack.
Definition: Event_Pack.h:40
static struct Event_Packer * Event_Packer()
Getter on the current event packer.
Definition: Event_Pack.h:54
The event contains meta data.
Definition: Event_Desc.h:44
int VMPI_Stream_open_map(VMPI_Stream *st, VMPI_Map *map, char *mode)
Open a stream according to a mapping.
Definition: VMPI_stream.c:303
Map processes in a round robin fashion.
Definition: VMPI.h:279
void * Buffered_FIFO_push(struct Buffered_FIFO *fifo, void *elem)
Pushes an element into a FIFO.
Struct defining a pack of events.
Definition: Event_Desc.h:103
void Event_Packer_push(struct MALP_Trace_Event *event)
Sends an event.
Definition: Event_Pack.c:141
void * Buffered_FIFO_pop(struct Buffered_FIFO *fifo, void *dest)
Pops an element from a FIFO.
void Event_Packer_release()
Releases the event packer.
Definition: Event_Pack.c:74
struct MALP_Trace_Event events[EVENT_PACK_SIZE]
The events.
Definition: Event_Desc.h:106
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
static VMPI_Partition_desc * VMPI_Get_desc_by_name(char *name)
Find a descriptions by its name.
Definition: VMPI.h:228
struct Stream_Infos * __trace_module
This is a global Stream_Infos (not shared between threads)
Definition: Stream_MGR.c:33
static void VMPI_Map_clear(VMPI_Map *map)
Clears a map.
Definition: VMPI.h:300
Struct defining an event.
Definition: Event_Desc.h:82
int VMPI_Map_partitions(int target, VMPI_Map_mode mode, VMPI_Map *map)
Map to another partition (can be additive)
Definition: VMPI.c:94
static int Stream_Infos_is_in_mpi()
Checks if we are currently inside a MPI call.
Definition: Stream_MGR.h:178
Structure holding partitions descriptions.
Definition: VMPI.h:100
This is the struct used to send events throuh a stream.
Definition: Event_Pack.h:38
static struct Stream_Infos * Stream_infos_get()
Getter on the current Stream_Infos.
Definition: Stream_MGR.h:129
MALP_Trace_event_type type
The type of the event.
Definition: Event_Desc.h:85
uint32_t application
tha application id
Definition: Locus.h:50
uint32_t offset
The number of packed events.
Definition: Event_Desc.h:107
uint64_t Buffered_FIFO_count(struct Buffered_FIFO *fifo)
Thread-safely gets the number of elements stored in the FIFO.
Definition: Buffered_FIFO.c:23
uint32_t partition
the partition id
Definition: Locus.h:49
MALP_Trace_event_t event
The event data.
Definition: Event_Desc.h:91
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
Definition: Spinlock.c:29
void __Event_Packer_push(struct MALP_Trace_Event *event)
Definition: Event_Pack.c:83
struct Event_Packer _malp_e_packer
The event packer of the current MPI rank.
Definition: Event_Pack.c:27
int id
Unique identifier of the partition.
Definition: VMPI.h:102
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
struct Pack_Locus locus
The pack locator.
Definition: Event_Desc.h:105
int VMPI_Stream_init(VMPI_Stream *st, size_t block_size, VMPI_Stream_load_balance lb)
Initializes a stream should be called before any *open call.
Definition: VMPI_stream.c:26
static int VMPI_Get_partition_id()
Returns the unique ID of the current partition.
Definition: VMPI.h:142
void Event_Packer_init()
Initializes the event packer, maps current process to existing Analyser or IO_WRITE partition and ini...
Definition: Event_Pack.c:30
#define EVENT_PACK_SIZE
The size of a pack of events.
Definition: Event_Desc.h:98
int VMPI_Stream_close(VMPI_Stream *st)
Closes a stream and sends EOF to remote endpoints.
Definition: VMPI_stream.c:316
Send or receive from each turn by turn.
Definition: VMPI_stream.h:43
int MALP_Spinlock_trylock(MALP_Spinlock *mutex)
Tries to lock the given MALP_Spinlock.
Definition: Spinlock.c:22
static void Stream_Infos_push_pending_event(struct MALP_Trace_Event *event)
Definition: Event_Pack.c:126
VMPI_Stream stream
The associated stream.
Definition: Event_Pack.h:41
int VMPI_Stream_write(VMPI_Stream *st, char *buff, unsigned int block_count)
Write data to a VMPI_Stream.
Definition: VMPI_stream.c:395
#define MAX_PENDING_EVENT
Defines the maximum pending events.
Definition: Stream_MGR.h:93
static void Stream_Infos_process_pending_events()
Definition: Event_Pack.c:107
MALP_Spinlock lock
the lock for concurrent access
Definition: Event_Pack.h:42