Modular C
+ Collaboration diagram for C◼mod◼timer:

Modules

 Specific macros to deal with the structure of module C◼mod◼timer.
 

Files

file  C-mod-timer.c
 Collect some simple timing statistics online as we go.
 

Data Structures

struct  C◼mod◼timer
 

Macros

#define C◼mod◼timer◼INITIALIZER—0(DESC, SOONER, ...)   { .sooner = (SOONER), .desc = ""DESC"", }
 
#define C◼mod◼timer◼INITIALIZER(...)   C◼mod◼timer◼INITIALIZER—0(__VA_ARGS__ , 0, )
 

Functions

_Bool C◼mod◼timer◼startup (C◼mod◼timer *t)
 
void C◼mod◼timer◼sample (C◼mod◼timer *t)
 
int C◼mod◼timer◼test (int argc, char *argv[argc+1])
 

Detailed Description

Context expressions
Context expression inside ⟦ ... ⟧ have been replaced with function calls from C◼time◼spec

Data Structure Documentation

§ C◼mod◼timer

struct C◼mod◼timer

Definition at line 121 of file C-mod-timer.c.

+ Collaboration diagram for C◼mod◼timer:

Data Fields

C◼mod◼timer *const sooner
 
C◼time◼spec _Atomic t
 
C◼mod◼stats *_Atomic stat
 
char const *const desc
 

Field Documentation

§ desc

char const* const desc

Definition at line 131 of file C-mod-timer.c.

§ sooner

C◼mod◼timer* const sooner

Definition at line 123 of file C-mod-timer.c.

Referenced by C◼mod◼timer◼sample().

§ stat

C◼mod◼stats* _Atomic stat

Definition at line 129 of file C-mod-timer.c.

§ t

C◼time◼spec _Atomic t

Definition at line 128 of file C-mod-timer.c.

Referenced by C◼mod◼timer◼startup().

Macro Definition Documentation

§ C◼mod◼timer◼INITIALIZER

#define C◼mod◼timer◼INITIALIZER (   ...)    C◼mod◼timer◼INITIALIZER—0(__VA_ARGS__ , 0, )

Definition at line 137 of file C-mod-timer.c.

Referenced by C◼mod◼timer◼test().

§ C◼mod◼timer◼INITIALIZER—0

#define C◼mod◼timer◼INITIALIZER—0 (   DESC,
  SOONER,
  ... 
)    { .sooner = (SOONER), .desc = ""DESC"", }

Definition at line 134 of file C-mod-timer.c.

Function Documentation

§ C◼mod◼timer◼sample()

void C◼mod◼timer◼sample ( C◼mod◼timer t)
inline

Definition at line 162 of file C-mod-timer.c.

References C◼mod◼stats◼collect3(), C◼mod◼timer◼startup(), C◼time◼spec◼_Operator—bnotbnot(), C◼time◼spec◼_Operator—sub(), C◼time◼spec◼get(), C◼time◼UTC, and sooner.

Referenced by C◼mod◼timer◼test().

162  {
163 #line 57 "/home/gustedt/build/cmod/C/C-mod-timer.X"
164  if (C◼mod◼timer◼startup(t)) {
165 #line 58 "/home/gustedt/build/cmod/C/C-mod-timer.X"
166  C◼time◼spec now;
168  if (t→sooner) {
169 #line 61 "/home/gustedt/build/cmod/C/C-mod-timer.X"
170  // .t may be atomic. Make sure that there is only one load.
171  C◼time◼spec sooner = t→sooner→t;
173  }
174  // .t may be atomic. Make sure that there is only one store.
175  t→t = now;
176  }
177 }
The platform struct struct timespec.
Definition: C-time-spec.c:44
double C◼time◼spec◼_Operator—bnotbnot(C◼time◼spec a)
Definition: C-time-spec.c:173
int C◼time◼spec◼get(C◼time◼spec *, int)
#define C◼time◼UTC
The platform specific value TIME_UTC.
void C◼mod◼stats◼collect3(C◼mod◼stats *c, double val)
Definition: C-mod-stats.c:274
_Bool C◼mod◼timer◼startup(C◼mod◼timer *t)
Definition: C-mod-timer.c:140
C◼time◼spec C◼time◼spec◼_Operator—sub(C◼time◼spec a, C◼time◼spec b)
Definition: C-time-spec.c:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

§ C◼mod◼timer◼startup()

_Bool C◼mod◼timer◼startup ( C◼mod◼timer t)
inline

Definition at line 140 of file C-mod-timer.c.

References C◼lib◼free(), C◼lib◼malloc(), C◼mod◼stats◼init(), and t.

Referenced by C◼mod◼timer◼sample().

140  {
141 #line 39 "/home/gustedt/build/cmod/C/C-mod-timer.X"
142  if (t ∧ t→sooner) {
143 #line 40 "/home/gustedt/build/cmod/C/C-mod-timer.X"
144  while (¬t→stat) {
145 #line 41 "/home/gustedt/build/cmod/C/C-mod-timer.X"
146  C◼mod◼stats* s = C◼lib◼malloc(sizeof *s);
147 #ifndef C◼atomics◼NO_ATOMICS
148  C◼mod◼stats* expect = 0;
149  if (¬C◼atomic◼compare_exchange_weak(&t→stat, &expect, s)) {
150 #line 45 "/home/gustedt/build/cmod/C/C-mod-timer.X"
151  C◼lib◼free(s);
152  continue;
153  }
154 #endif
155  t→stat = C◼mod◼stats◼init(s, t→desc);
156  }
157  }
158  return t;
159 }
void * C◼lib◼malloc(C◼lib◼size)
A simple data structure to collect the 0th to 3rd moment of a statistic.
Definition: C-mod-stats.c:124
void C◼lib◼free(void *)
C◼mod◼stats * C◼mod◼stats◼init(C◼mod◼stats *s, char const *desc)
Definition: C-mod-stats.c:375
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

§ C◼mod◼timer◼test()

int C◼mod◼timer◼test ( int  argc,
char *  argv[argc+1] 
)

Definition at line 188 of file C-mod-timer.c.

References C◼io◼out, C◼MODULE_ABI, C◼MODULE_FEATURES, C◼mod◼stats◼print(), C◼mod◼timer◼INITIALIZER, C◼mod◼timer◼sample(), and int().

188  {
189 #line 75 "/home/gustedt/build/cmod/C/C-mod-timer.X"
190  static unsigned volatile s;
191  static C◼mod◼timer start = C◼mod◼timer◼INITIALIZER("starting");
192  for (unsigned probe = 0; probe < 5; ++probe) {
193 #line 78 "/home/gustedt/build/cmod/C/C-mod-timer.X"
194  C◼mod◼timer◼sample(&start);
195  for (unsigned volatile i = 0; i < -1; i++) {
196 #line 80 "/home/gustedt/build/cmod/C/C-mod-timer.X"
197  }
198  static C◼mod◼timer count_vol = C◼mod◼timer◼INITIALIZER("counter volatile", &start);
199  C◼mod◼timer◼sample(&count_vol);
200  for (unsigned i = 0; i < -1; i++) {
201 #line 84 "/home/gustedt/build/cmod/C/C-mod-timer.X"
202  s += i;
203  }
204  static C◼mod◼timer store_vol = C◼mod◼timer◼INITIALIZER("store volatile", &count_vol);
205  C◼mod◼timer◼sample(&store_vol);
206  }
208  return 0;
209 }
#define C◼mod◼timer◼INITIALIZER(...)
Definition: C-mod-timer.c:137
void C◼mod◼timer◼sample(C◼mod◼timer *t)
Definition: C-mod-timer.c:162
C◼io * C◼io◼out
This aliases symbol stdout.
void C◼mod◼stats◼print(C◼io *out)
Definition: C-mod-stats.c:316
+ Here is the call graph for this function: