PIPS
misc.c File Reference
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/time.h>
#include "genC.h"
#include "database.h"
#include "linear.h"
#include "ri.h"
#include "pipsdbm.h"
#include <unistd.h>
+ Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define MAX_TIME_STRING_LENGTH   1024
 

Functions

void interrupt_pipsmake_asap ()
 misc.c More...
 
void dont_interrupt_pipsmake_asap ()
 
bool interrupt_pipsmake_asap_p ()
 
static double get_real_timer ()
 Get real time in seconds in a double representation. More...
 
static void set_current_time (struct tms *now, double *rnow)
 set current usage and time in two formats More...
 
void init_request_timers ()
 Functions for timing one request. More...
 
void init_log_timers ()
 Functions for timing one phase. More...
 
void dbm_start_timer ()
 
void dbm_stop_timer ()
 accumulate dbm related times for one phase More...
 
void get_string_timers (string *with_io, string *io)
 compute times elapsed since init_log_timers(), i.e. More...
 
void get_request_string_timers (string *global, string *phases, string *dbm)
 compute times elapsed since init_request_log_timers(), i.e. More...
 
void init_resource_usage_check ()
 init variables More...
 
void add_read_resource (string rname, string oname)
 add an element to the read set More...
 
void add_write_resource (string rname, string oname)
 add an element to the write set More...
 
void get_logged_resources (set *sr, set *sw)
 Get the made sets. More...
 

Variables

static bool flag_interrupt_pipsmake_asap = false
 
static struct tms request_time
 Timing of one request. More...
 
static double real_request_time
 
static struct tms request_phase_time
 
static double real_request_phase_time
 
static struct tms request_dbm_time
 
static double real_request_dbm_time
 
static struct tms phase_time
 Timing of one phase. More...
 
static double real_phase_time
 
static struct tms dbm_time
 
static double real_dbm_time
 
static struct tms total_dbm_time
 
static double real_total_dbm_time
 
static set res_read = set_undefined
 Sets of the readwrite resources by pipsdbm. More...
 
static set res_write = set_undefined
 

Macro Definition Documentation

◆ MAX_TIME_STRING_LENGTH

#define MAX_TIME_STRING_LENGTH   1024

Definition at line 150 of file misc.c.

Function Documentation

◆ add_read_resource()

void add_read_resource ( string  rname,
string  oname 
)

add an element to the read set

Parameters
rnamename
onamename

Definition at line 251 of file misc.c.

252 {
255  res_read,
256  strdup(concatenate(oname, ".", rname, NULL)));
257 }
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define set_undefined_p(s)
Definition: newgen_set.h:49
set set_add_element(set, const set, const void *)
Definition: set.c:152
static set res_read
Sets of the readwrite resources by pipsdbm.
Definition: misc.c:236
char * strdup()

References concatenate(), res_read, set_add_element(), set_undefined_p, and strdup().

+ Here is the call graph for this function:

◆ add_write_resource()

void add_write_resource ( string  rname,
string  oname 
)

add an element to the write set

Parameters
rnamename
onamename

Definition at line 260 of file misc.c.

261 {
264  strdup(concatenate(oname, ".", rname, NULL)));
265 }
static set res_write
Definition: misc.c:237

References concatenate(), res_write, set_add_element(), set_undefined_p, and strdup().

+ Here is the call graph for this function:

◆ dbm_start_timer()

void dbm_start_timer ( void  )

Definition at line 131 of file misc.c.

132 {
134 }
static struct tms dbm_time
Definition: misc.c:81
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_dbm_time
Definition: misc.c:82

References dbm_time, real_dbm_time, and set_current_time().

+ Here is the call graph for this function:

◆ dbm_stop_timer()

void dbm_stop_timer ( void  )

accumulate dbm related times for one phase

Definition at line 137 of file misc.c.

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 }
static struct tms total_dbm_time
Definition: misc.c:84
static double real_total_dbm_time
Definition: misc.c:85
static size_t current
Definition: string.c:115

References current, dbm_time, real_dbm_time, real_total_dbm_time, set_current_time(), and total_dbm_time.

+ Here is the call graph for this function:

◆ dont_interrupt_pipsmake_asap()

void dont_interrupt_pipsmake_asap ( void  )

Definition at line 53 of file misc.c.

54 {
56 }
static bool flag_interrupt_pipsmake_asap
Definition: misc.c:46

References flag_interrupt_pipsmake_asap.

Referenced by apply(), concurrent_apply(), delete_some_resources(), and make().

+ Here is the caller graph for this function:

◆ get_logged_resources()

void get_logged_resources ( set sr,
set sw 
)

Get the made sets.

Parameters
srr
sww

Definition at line 268 of file misc.c.

269 {
270  *sr = res_read;
271  *sw = res_write;
272 }

References res_read, and res_write.

Referenced by do_resource_usage_check().

+ Here is the caller graph for this function:

◆ get_real_timer()

static double get_real_timer ( )
static

Get real time in seconds in a double representation.

Definition at line 89 of file misc.c.

90 {
91  struct timeval tv;
92  gettimeofday(&tv, NULL);
93  return (double) tv.tv_sec + (double) tv.tv_usec / 1.0e6;
94 }

Referenced by set_current_time().

+ Here is the caller graph for this function:

◆ get_request_string_timers()

void get_request_string_timers ( string global,
string phases,
string dbm 
)

compute times elapsed since init_request_log_timers(), i.e.

for one request to pipsmake (btw this code is misplaced...)

Parameters
globallobal
phaseshases
dbmbm

Definition at line 196 of file misc.c.

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 }
static struct tms request_phase_time
Definition: misc.c:71
static struct tms request_time
Timing of one request.
Definition: misc.c:68
#define MAX_TIME_STRING_LENGTH
Definition: misc.c:150
static double real_request_dbm_time
Definition: misc.c:75
static double real_request_phase_time
Definition: misc.c:72
static struct tms request_dbm_time
Definition: misc.c:74
static double real_request_time
Definition: misc.c:69
s1
Definition: set.c:247

References MAX_TIME_STRING_LENGTH, real_request_dbm_time, real_request_phase_time, real_request_time, request_dbm_time, request_phase_time, request_time, s1, and set_current_time().

Referenced by logs_off().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_string_timers()

void get_string_timers ( string with_io,
string io 
)

compute times elapsed since init_log_timers(), i.e.

for one phase

accumulate phase times in request times, ignoring sub-processes ???

Parameters
with_ioith_io
ioo

Definition at line 155 of file misc.c.

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 }
static double real_phase_time
Definition: misc.c:79
static struct tms phase_time
Timing of one phase.
Definition: misc.c:78

References MAX_TIME_STRING_LENGTH, phase_time, real_phase_time, real_request_dbm_time, real_request_phase_time, real_total_dbm_time, request_dbm_time, request_phase_time, s1, set_current_time(), and total_dbm_time.

Referenced by apply_a_rule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_log_timers()

void init_log_timers ( void  )

Functions for timing one phase.

Definition at line 122 of file misc.c.

123 {
125 
126  total_dbm_time.tms_utime = 0;
127  total_dbm_time.tms_stime = 0;
128  real_total_dbm_time = 0.0;
129 }

References phase_time, real_phase_time, real_total_dbm_time, set_current_time(), and total_dbm_time.

Referenced by apply_a_rule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_request_timers()

void init_request_timers ( void  )

Functions for timing one request.

initialize accumulators for dbm and phase times

Definition at line 106 of file misc.c.

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 }

References real_request_dbm_time, real_request_phase_time, real_request_time, request_dbm_time, request_phase_time, request_time, and set_current_time().

Referenced by logs_on().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_resource_usage_check()

void init_resource_usage_check ( void  )

init variables

Definition at line 240 of file misc.c.

241 {
248 }
set set_clear(set)
Assign the empty set to s s := {}.
Definition: set.c:326
@ set_string
Definition: newgen_set.h:42
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102

References res_read, res_write, set_clear(), set_make(), set_string, and set_undefined_p.

Referenced by apply_a_rule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ interrupt_pipsmake_asap()

void interrupt_pipsmake_asap ( void  )

misc.c

Definition at line 48 of file misc.c.

49 {
51 }

References flag_interrupt_pipsmake_asap.

Referenced by pips_signal_handler(), and wpips_interrupt_pipsmake().

+ Here is the caller graph for this function:

◆ interrupt_pipsmake_asap_p()

bool interrupt_pipsmake_asap_p ( void  )

Definition at line 58 of file misc.c.

59 {
62  return res;
63 }

References flag_interrupt_pipsmake_asap.

Referenced by apply_a_rule().

+ Here is the caller graph for this function:

◆ set_current_time()

static void set_current_time ( struct tms *  now,
double *  rnow 
)
static

set current usage and time in two formats

Definition at line 98 of file misc.c.

99 {
100  times(now);
101  *rnow = get_real_timer();
102 }
static double get_real_timer()
Get real time in seconds in a double representation.
Definition: misc.c:89

References get_real_timer().

Referenced by dbm_start_timer(), dbm_stop_timer(), get_request_string_timers(), get_string_timers(), init_log_timers(), and init_request_timers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ dbm_time

struct tms dbm_time
static

Definition at line 79 of file misc.c.

Referenced by dbm_start_timer(), dbm_stop_timer(), and logs_off().

◆ flag_interrupt_pipsmake_asap

bool flag_interrupt_pipsmake_asap = false
static

◆ phase_time

struct tms phase_time
static

Timing of one phase.

Definition at line 75 of file misc.c.

Referenced by get_string_timers(), init_log_timers(), and logs_off().

◆ real_dbm_time

double real_dbm_time
static

Definition at line 82 of file misc.c.

Referenced by dbm_start_timer(), and dbm_stop_timer().

◆ real_phase_time

double real_phase_time
static

Definition at line 79 of file misc.c.

Referenced by get_string_timers(), and init_log_timers().

◆ real_request_dbm_time

double real_request_dbm_time
static

Definition at line 75 of file misc.c.

Referenced by get_request_string_timers(), get_string_timers(), and init_request_timers().

◆ real_request_phase_time

double real_request_phase_time
static

Definition at line 72 of file misc.c.

Referenced by get_request_string_timers(), get_string_timers(), and init_request_timers().

◆ real_request_time

double real_request_time
static

Definition at line 69 of file misc.c.

Referenced by get_request_string_timers(), and init_request_timers().

◆ real_total_dbm_time

double real_total_dbm_time
static

Definition at line 85 of file misc.c.

Referenced by dbm_stop_timer(), get_string_timers(), and init_log_timers().

◆ request_dbm_time

struct tms request_dbm_time
static

Definition at line 72 of file misc.c.

Referenced by get_request_string_timers(), get_string_timers(), and init_request_timers().

◆ request_phase_time

struct tms request_phase_time
static

Definition at line 69 of file misc.c.

Referenced by get_request_string_timers(), get_string_timers(), and init_request_timers().

◆ request_time

struct tms request_time
static

Timing of one request.

Definition at line 58 of file misc.c.

Referenced by get_request_string_timers(), init_request_timers(), and logs_off().

◆ res_read

set res_read = set_undefined
static

Sets of the readwrite resources by pipsdbm.

Definition at line 236 of file misc.c.

Referenced by add_read_resource(), do_resource_usage_check(), get_logged_resources(), and init_resource_usage_check().

◆ res_write

◆ total_dbm_time

struct tms total_dbm_time
static

Definition at line 82 of file misc.c.

Referenced by dbm_stop_timer(), get_string_timers(), and init_log_timers().