PIPS
misc.c
Go to the documentation of this file.
1 /*
2 
3  $Id: misc.c 23256 2016-11-02 07:24:49Z 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  * Directly from the old implementation of pipsdbm.
29  * Too many static buffers in my opinion;-) FC.
30  */
31 #include <stdio.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <sys/times.h>
35 #include <sys/time.h>
36 
37 #include "genC.h"
38 
39 #include "database.h"
40 #include "linear.h"
41 #include "ri.h"
42 
43 #include "pipsdbm.h"
44 
45 /****************************************************** PIPSMAKE INTERRUPTION */
46 static bool flag_interrupt_pipsmake_asap = false;
47 
49 {
51 }
52 
54 {
56 }
57 
59 {
62  return res;
63 }
64 
65 /**************************************************************** LOG_TIMINGS */
66 
67 /* Timing of one request */
68 static struct tms request_time;
69 static double real_request_time;
70 
71 static struct tms request_phase_time;
73 
74 static struct tms request_dbm_time;
75 static double real_request_dbm_time;
76 
77 /* Timing of one phase */
78 static struct tms phase_time;
79 static double real_phase_time;
80 
81 static struct tms dbm_time;
82 static double real_dbm_time;
83 
84 static struct tms total_dbm_time;
85 static double real_total_dbm_time;
86 
87 
88 /* Get real time in seconds in a double representation */
89 static double get_real_timer()
90 {
91  struct timeval tv;
92  gettimeofday(&tv, NULL);
93  return (double) tv.tv_sec + (double) tv.tv_usec / 1.0e6;
94 }
95 
96 /* set current usage and time in two formats
97  */
98 static void set_current_time(struct tms * now, double * rnow)
99 {
100  times(now);
101  *rnow = get_real_timer();
102 }
103 
104 /* Functions for timing one request
105  */
107 {
109 
110  /* initialize accumulators for dbm and phase times */
111  request_dbm_time.tms_utime = 0;
112  request_dbm_time.tms_stime = 0;
113  real_request_dbm_time = 0.0;
114 
115  request_phase_time.tms_utime = 0;
116  request_phase_time.tms_stime = 0;
118 }
119 
120 /* Functions for timing one phase
121  */
123 {
125 
126  total_dbm_time.tms_utime = 0;
127  total_dbm_time.tms_stime = 0;
128  real_total_dbm_time = 0.0;
129 }
130 
132 {
134 }
135 
136 /* accumulate dbm related times for one phase */
138 {
139  struct tms current;
140  double real_current;
141 
142  set_current_time(&current, &real_current);
143 
144  // ??? does not include sub process time!
145  total_dbm_time.tms_utime += current.tms_utime - dbm_time.tms_utime;
146  total_dbm_time.tms_stime += current.tms_stime - dbm_time.tms_stime;
147  real_total_dbm_time += real_current - real_dbm_time;
148 }
149 
150 #define MAX_TIME_STRING_LENGTH 1024 // YUK
151 
152 #include <unistd.h>
153 
154 /* compute times elapsed since init_log_timers(), i.e. for one phase */
155 void get_string_timers(string *with_io, string *io)
156 {
157  struct tms total_phase_time;
158  double real_total_phase_time;
159  static char s1[MAX_TIME_STRING_LENGTH];
160  static char s2[MAX_TIME_STRING_LENGTH];
161 
162  set_current_time(&total_phase_time, &real_total_phase_time);
163 
164  // switch stop start time to an accumulator
165  total_phase_time.tms_utime -= phase_time.tms_utime;
166  total_phase_time.tms_stime -= phase_time.tms_stime;
167  real_total_phase_time -= real_phase_time;
168 
169  long HZ = sysconf(_SC_CLK_TCK);
170 
171  sprintf (s1, "(r%.3f u%.2f s%.2f)\n",
172  real_total_phase_time,
173  (double) total_phase_time.tms_utime / HZ,
174  (double) total_phase_time.tms_stime / HZ);
175 
176  sprintf (s2,"(r%.3f u%.2f s%.2f)\n",
178  (double) total_dbm_time.tms_utime / HZ,
179  (double) total_dbm_time.tms_stime / HZ);
180 
181  *with_io = s1; *io = s2;
182 
183  /* accumulate phase times in request times, ignoring sub-processes ??? */
184  request_dbm_time.tms_utime += total_dbm_time.tms_utime;
185  request_dbm_time.tms_stime += total_dbm_time.tms_stime;
187 
188  request_phase_time.tms_utime += total_phase_time.tms_utime;
189  request_phase_time.tms_stime += total_phase_time.tms_stime;
190  real_request_phase_time += real_total_phase_time;
191 }
192 
193 /* compute times elapsed since init_request_log_timers(),
194  * i.e. for one request to pipsmake (btw this code is misplaced...)
195  */
196 void get_request_string_timers(string *global, string *phases, string *dbm)
197 {
198  struct tms total_request_time;
199  double real_total_request_time;
200  static char s1[MAX_TIME_STRING_LENGTH];
201  static char s2[MAX_TIME_STRING_LENGTH];
202  static char s3[MAX_TIME_STRING_LENGTH];
203 
204  set_current_time(&total_request_time, &real_total_request_time);
205 
206  // switch to accumulator
207  total_request_time.tms_utime -= request_time.tms_utime;
208  total_request_time.tms_stime -= request_time.tms_stime;
209  real_total_request_time -= real_request_time;
210 
211  long HZ = sysconf(_SC_CLK_TCK);
212 
213  sprintf (s1, "(r%.3f u%.2f s%.2f)\n",
214  real_total_request_time,
215  (double) total_request_time.tms_utime / HZ,
216  (double) total_request_time.tms_stime / HZ);
217 
218  sprintf (s2, "(r%.3f u%.2f s%.2f)\n",
220  (double) request_phase_time.tms_utime / HZ,
221  (double) request_phase_time.tms_stime / HZ);
222 
223  sprintf (s3, "(r%.3f u%.2f s%.2f)\n",
225  (double) request_dbm_time.tms_utime / HZ,
226  (double) request_dbm_time.tms_stime / HZ);
227 
228  *global = s1;
229  *phases = s2;
230  *dbm = s3;
231 }
232 
233 /**************************************************************** OBSOLETE? */
234 
235 /* Sets of the readwrite resources by pipsdbm */
238 
239 /* init variables */
241 {
248 }
249 
250 /* add an element to the read set */
251 void add_read_resource(string rname,string oname)
252 {
255  res_read,
256  strdup(concatenate(oname, ".", rname, NULL)));
257 }
258 
259 /* add an element to the write set */
260 void add_write_resource(string rname,string oname)
261 {
264  strdup(concatenate(oname, ".", rname, NULL)));
265 }
266 
267 /* Get the made sets */
269 {
270  *sr = res_read;
271  *sw = res_write;
272 }
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define set_undefined
Definition: newgen_set.h:48
set set_clear(set)
Assign the empty set to s s := {}.
Definition: set.c:326
@ set_string
Definition: newgen_set.h:42
#define set_undefined_p(s)
Definition: newgen_set.h:49
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
set set_add_element(set, const set, const void *)
Definition: set.c:152
static struct tms request_phase_time
Definition: misc.c:71
void dbm_start_timer()
Definition: misc.c:131
static bool flag_interrupt_pipsmake_asap
Definition: misc.c:46
void interrupt_pipsmake_asap()
misc.c
Definition: misc.c:48
void get_request_string_timers(string *global, string *phases, string *dbm)
compute times elapsed since init_request_log_timers(), i.e.
Definition: misc.c:196
static set res_read
Sets of the readwrite resources by pipsdbm.
Definition: misc.c:236
static double get_real_timer()
Get real time in seconds in a double representation.
Definition: misc.c:89
void dbm_stop_timer()
accumulate dbm related times for one phase
Definition: misc.c:137
void init_request_timers()
Functions for timing one request.
Definition: misc.c:106
static struct tms dbm_time
Definition: misc.c:81
static set res_write
Definition: misc.c:237
static struct tms request_time
Timing of one request.
Definition: misc.c:68
void get_string_timers(string *with_io, string *io)
compute times elapsed since init_log_timers(), i.e.
Definition: misc.c:155
void get_logged_resources(set *sr, set *sw)
Get the made sets.
Definition: misc.c:268
#define MAX_TIME_STRING_LENGTH
Definition: misc.c:150
static double real_request_dbm_time
Definition: misc.c:75
static struct tms total_dbm_time
Definition: misc.c:84
static void set_current_time(struct tms *now, double *rnow)
set current usage and time in two formats
Definition: misc.c:98
static double real_request_phase_time
Definition: misc.c:72
static double real_phase_time
Definition: misc.c:79
void add_read_resource(string rname, string oname)
add an element to the read set
Definition: misc.c:251
void init_log_timers()
Functions for timing one phase.
Definition: misc.c:122
bool interrupt_pipsmake_asap_p()
Definition: misc.c:58
static double real_total_dbm_time
Definition: misc.c:85
void init_resource_usage_check()
init variables
Definition: misc.c:240
void dont_interrupt_pipsmake_asap()
Definition: misc.c:53
static struct tms request_dbm_time
Definition: misc.c:74
void add_write_resource(string rname, string oname)
add an element to the write set
Definition: misc.c:260
static double real_dbm_time
Definition: misc.c:82
static double real_request_time
Definition: misc.c:69
static struct tms phase_time
Timing of one phase.
Definition: misc.c:78
char * strdup()
s1
Definition: set.c:247
static size_t current
Definition: string.c:115
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59