SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
timer.c File Reference

Detailed Description

Provides functions for collecting run-time statistics such as CPU time, memory usage, I/O counts, and elapsed time.

This file contains implementations of functions like init_stats(), cpu_time(), memory_count(), and others, which collect various run-time statistics. The implementations vary depending on the operating system (VAX/VMS, SUN UNIX, Linux, Solaris, etc.). The functions utilize system-specific libraries and system calls to retrieve the necessary information.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C Saunders, R. Soliday, Y. Wang

Definition in file timer.c.

#include "mdb.h"
#include <sys/time.h>

Go to the source code of this file.

Functions

double delapsed_time ()
 Calculates the elapsed clock time since the last initialization as a numerical value.
 
char * elapsed_time ()
 
void init_stats ()
 
long cpu_time ()
 Retrieves the CPU time used since the last initialization.
 
long bio_count ()
 
long dio_count ()
 
long page_faults ()
 Retrieves the number of page faults since the last initialization.
 
long memory_count ()
 

Function Documentation

◆ bio_count()

long bio_count ( )

Definition at line 125 of file timer.c.

125 {
126 return 0;
127}

◆ cpu_time()

long cpu_time ( )

Retrieves the CPU time used since the last initialization.

This function retrieves the CPU time consumed by the process since init_stats() was last called.

Returns
The CPU time used in hundredths of seconds, or -1 on error.

Definition at line 117 of file timer.c.

117 {
118 return (long)((clock() * 100.0) / CLOCKS_PER_SEC);
119}

◆ delapsed_time()

double delapsed_time ( void )

Calculates the elapsed clock time since the last initialization as a numerical value.

This function calculates the elapsed time in seconds since init_stats() was last called.

Returns
The elapsed time in seconds, or 0.0 if not available.

Definition at line 92 of file timer.c.

92 {
93# if defined(linux)
94 struct timespec delapsedNow;
95 if (!delapsedStartInitialized)
96 init_stats();
97 clock_gettime(CLOCK_REALTIME, &delapsedNow);
98 return (double)(delapsedNow.tv_sec - delapsedStart.tv_sec) +
99 (delapsedNow.tv_nsec - delapsedStart.tv_nsec)/1e9;
100# else
101 static long delapsed_start = -1;
102 if (delapsed_start == -1) {
103 delapsed_start = time(0);
104 return 0.0;
105 } else
106 return time(0) - delapsed_start;
107# endif
108}

◆ dio_count()

long dio_count ( )

Definition at line 133 of file timer.c.

133 {
134 return (0);
135}

◆ elapsed_time()

char * elapsed_time ( )

Definition at line 30 of file timer.c.

30 {
31 static char buffer[20];
32 static double dtime;
33 int h, m;
34 float s;
35
36 dtime = delapsed_time();
37 h = dtime / 3600;
38 dtime -= h * 3600;
39 m = dtime / 60;
40 dtime -= m * 60;
41 s = dtime;
42
43 sprintf(buffer, "%02d:%02d:%02.3f", h, m, s);
44 return (buffer);
45}
double delapsed_time(void)
Calculates the elapsed clock time since the last initialization as a numerical value.
Definition timer.c:92

◆ init_stats()

void init_stats ( )

Definition at line 79 of file timer.c.

79 {
80 delapsed_start = delapsed_time();
81 clock();
82}

◆ memory_count()

long memory_count ( )

Definition at line 184 of file timer.c.

184 {
185 return 0;
186}

◆ page_faults()

long page_faults ( )

Retrieves the number of page faults since the last initialization.

This function retrieves the number of page faults that have occurred since init_stats() was last called.

Returns
The number of page faults, or -1 on error.

Definition at line 144 of file timer.c.

144 {
145 return 0;
146}