PIPS
perf_spy.c
Go to the documentation of this file.
1 /*
2 
3  $Id: perf_spy.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * functions to spy performances.
29  * I agree, -pg does a better job, but for page fault and related issues...
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 /* for USAGE information
36  */
37 #include <sys/time.h>
38 #include <sys/resource.h>
39 
40 #include "genC.h"
41 #include "misc.h"
42 
43 #define USAGE_STACK_SIZE 10
44 static struct rusage usage_stack[USAGE_STACK_SIZE];
45 static int stack_index = 0; /* available bucket */
46 
47 static void
49  FILE *f,
50  struct timeval *p)
51 {
52  fprintf(f, "%.3f", (double) p->tv_sec + (double) p->tv_usec/1e6);
53 }
54 
55 static void
57  FILE *f,
58  struct timeval *begin,
59  struct timeval *end)
60 {
61  struct timeval delta;
62  delta.tv_sec = end->tv_sec - begin->tv_sec;
63  delta.tv_usec = end->tv_usec - begin->tv_usec;
64  printf_time(f, &delta);
65 }
66 
67 /* simply dump all available information...
68  */
69 static void
71  FILE *f,
72  struct rusage *begin,
73  struct rusage *end)
74 {
75  fprintf(f, " user: ");
76  printf_time_delta(f, &begin->ru_utime, &end->ru_utime);
77  fprintf(f, "/");
78  printf_time(f, &end->ru_utime);
79  fprintf(f, "s syst: ");
80  printf_time_delta(f, &begin->ru_stime, &end->ru_stime);
81  fprintf(f, "/");
82  printf_time(f, &end->ru_stime);
83  fprintf(f, "s\n page faults major: %ld/%ld minor: %ld/%ld\n",
84  end->ru_majflt-begin->ru_majflt, end->ru_majflt,
85  end->ru_minflt-begin->ru_minflt, end->ru_minflt);
86 }
87 
88 void
90 {
91  message_assert("stack not full", stack_index<USAGE_STACK_SIZE);
92  getrusage(RUSAGE_CHILDREN, &usage_stack[stack_index++]);
93  getrusage(RUSAGE_SELF, &usage_stack[stack_index++]);
94 }
95 
96 void
98  FILE *f,
99  string msg)
100 {
101  struct rusage current;
102  message_assert("stack not empty", stack_index>0);
103  fprintf(f, "[performance_spy] %s\n", msg);
104 
105  getrusage(RUSAGE_SELF, &current);
106  fprintf(f, "self:\n");
108  fprintf(f, "children:\n");
109  getrusage(RUSAGE_CHILDREN, &current);
111 }
112 
char end
Definition: gtk_status.c:82
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define USAGE_STACK_SIZE
for USAGE information
Definition: perf_spy.c:43
void push_performance_spy()
perf_spy.c
Definition: perf_spy.c:89
static void printf_time(FILE *f, struct timeval *p)
available bucket
Definition: perf_spy.c:48
static void printf_usage_delta(FILE *f, struct rusage *begin, struct rusage *end)
simply dump all available information...
Definition: perf_spy.c:70
static struct rusage usage_stack[USAGE_STACK_SIZE]
Definition: perf_spy.c:44
static int stack_index
Definition: perf_spy.c:45
void pop_performance_spy(FILE *f, string msg)
Definition: perf_spy.c:97
static void printf_time_delta(FILE *f, struct timeval *begin, struct timeval *end)
Definition: perf_spy.c:56
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static size_t current
Definition: string.c:115