Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Posix_Profile.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_Profile.h"
20 #include "VMPI.h"
21 
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <mpi.h>
25 
26 #include "Timer.h"
27 
28 #include "Posix_Wrapp.h"
29 
30 
32 
33 
35 {
36  //bzero( ent, sizeof(struct Profile_Entry) );
37  ent->id = id;
38 }
39 
41 {
42  bzero( ent, sizeof(struct Profile_Entry) );
43 }
44 
46 {
47  /* Fill Profile entries with Zeroes */
48  int i;
49 
50  for( i = 0 ; i < T_POSIX_COUNT; i++ )
52 
53  TEST_LOAD_SYMBOL( qsort );
54  TEST_LOAD_SYMBOL( malloc );
55  TEST_LOAD_SYMBOL( free );
56 }
57 
59 {
60  int i;
61 
62  for( i = 0 ; i < T_POSIX_COUNT; i++ )
64 }
65 
66 
68 {
69  /* Allocate arrays to perform the reduction */
70  uint64_t * hits = REAL(malloc)( sizeof( uint64_t ) * T_POSIX_COUNT );
71  uint64_t * time = REAL(malloc)( sizeof( uint64_t ) * T_POSIX_COUNT );
72  int64_t * size = REAL(malloc)( sizeof( uint64_t ) * T_POSIX_COUNT );
73 
74  uint64_t * out_hits = REAL(malloc)( sizeof( uint64_t ) * T_POSIX_COUNT );
75  uint64_t * out_time = REAL(malloc)( sizeof( uint64_t ) * T_POSIX_COUNT );
76  int64_t * out_size = REAL(malloc)( sizeof( uint64_t ) * T_POSIX_COUNT );
77 
78  if( !hits||!time||!size||!out_hits||!out_time||!out_size)
79  {
80  perror("malloc");
81  printf("Failled to allocate array\n");
82  abort();
83  }
84 
85 
86  /* Copy back datas */
87  int i;
88 
89  for( i = 0 ; i < T_POSIX_COUNT; i++ )
90  {
91  hits[i] = __POSIX_Profile_entries[i].hits;
92  time[i] = __POSIX_Profile_entries[i].time;
93  size[i] = __POSIX_Profile_entries[i].size;
94  }
95 
96  /* Perform the reduction to rank 0 */
97  PMPI_Allreduce(hits, out_hits, T_POSIX_COUNT, MPI_UNSIGNED_LONG_LONG, MPI_SUM, VMPI_Get_partition_comm());
98  PMPI_Allreduce(time, out_time, T_POSIX_COUNT, MPI_UNSIGNED_LONG_LONG, MPI_SUM, VMPI_Get_partition_comm());
99  PMPI_Allreduce(size, out_size, T_POSIX_COUNT, MPI_LONG_LONG, MPI_SUM, VMPI_Get_partition_comm());
100 
101 
102  /* Copy back */
103  for( i = 0 ; i < T_POSIX_COUNT; i++ )
104  {
105  __POSIX_Profile_entries[i].hits = out_hits[i];
106  __POSIX_Profile_entries[i].time = out_time[i];
107  __POSIX_Profile_entries[i].size = out_size[i];
108  }
109 
110  /* Free datas */
111  REAL(free)( hits );
112  REAL(free)( time );
113  REAL(free)( size );
114  REAL(free)( out_hits );
115  REAL(free)( out_time );
116  REAL(free)( out_size );
117 }
118 
119 int Profile_Entry_sort(const void *a, const void *b)
120 {
121  struct Profile_Entry *sa = (struct Profile_Entry *) a;
122  struct Profile_Entry *sb = (struct Profile_Entry *) b;
123 
124  if( !sa || !sb )
125  return 0;
126 
127  if( sb->time < sa->time )
128  return -1;
129 
130  if( sa->time < sb->time )
131  return 1;
132 
133  if( sb->time == sa->time )
134  return 0;
135 }
136 
138 {
139  struct Profile_Entry *entries = REAL(malloc)( sizeof( struct Profile_Entry ) * T_POSIX_COUNT );
140 
141  if( !entries )
142  {
143  perror("malloc");
144  return;
145  }
146 
147  /* Fill the array to be sorted */
148  memcpy( entries, __POSIX_Profile_entries , sizeof( struct Profile_Entry ) * T_POSIX_COUNT );
149 
150  /* Sort the array in terms of total time */
151  REAL(qsort)(entries, T_POSIX_COUNT, sizeof( struct Profile_Entry ) , Profile_Entry_sort);
152 
153  /* Perform the output */
154  int i;
155 
156  printf("POSIX profile ======================================\n");
157 
158  for( i = 0 ; i < T_POSIX_COUNT ; i++ )
159  {
160  if( !entries[i].hits )
161  continue;
162 
163  printf("\t%s hits: %llu time: %.2g sec (%llu ticks) ", Wrapped_symbol_names[entries[i].id], entries[i].hits, (double)entries[i].time/Timer_second(), entries[i].time );
164 
165  if( entries[i].size )
166  printf("size: %lld", entries[i].size );
167  else
168  printf("\n");
169  }
170 
171  printf("===================================================\n");
172 
173  /* Free the array */
174  REAL(free)( entries );
175 }
176 
177 
179 {
180 
181 
182 }
void Profile_Entry_init(struct Profile_Entry *ent, Wrapped_symbol id)
Definition: Posix_Profile.c:34
void POSIX_profile_render()
#define REAL(a)
Definition: Posix_Wrapp.h:81
static MPI_Comm VMPI_Get_partition_comm()
Returns current partition's communicator.
Definition: VMPI.h:175
void POSIX_profile_reduce()
Definition: Posix_Profile.c:67
uint64_t hits
Definition: Posix_Profile.h:36
Definition: Posix_Profile.h:32
void POSIX_profile_release()
Definition: Posix_Profile.c:58
#define TEST_LOAD_SYMBOL(a)
Definition: Posix_Wrapp.h:83
Wrapped_symbol
enum indicating which symbols are wrapped
Wrapped_symbol id
Definition: Posix_Profile.h:34
void POSIX_profile_init()
Definition: Posix_Profile.c:45
static double Timer_second()
Getter on the current timer scale second.
Definition: Timer.h:74
uint64_t time
Definition: Posix_Profile.h:37
int Profile_Entry_sort(const void *a, const void *b)
void Profile_Entry_release(struct Profile_Entry *ent)
Definition: Posix_Profile.c:40
static const char *const Wrapped_symbol_names[T_POSIX_COUNT]
Array containing wrapped symbols names.
struct Profile_Entry __POSIX_Profile_entries[T_POSIX_COUNT]
Definition: Posix_Profile.c:31
void POSIX_profile_serialize()
int64_t size
Definition: Posix_Profile.h:38