GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
time-wrappers.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2016-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 // These functions may be provided by gnulib. We don't include gnulib
27 // headers directly in Octave's C++ source files to avoid problems that
28 // may be caused by the way that gnulib overrides standard library
29 // functions.
30 
31 #if defined (HAVE_CONFIG_H)
32 # include "config.h"
33 #endif
34 
35 #include <sys/resource.h>
36 #include <sys/time.h>
37 #include <sys/times.h>
38 
39 #include "time-wrappers.h"
40 
41 int
42 octave_gettimeofday_wrapper (time_t *sec, long *usec)
43 {
44  struct timeval tv;
45 
46  int status = gettimeofday (&tv, 0);
47 
48  if (status < 0)
49  {
50  *sec = 0;
51  *usec = 0;
52  }
53  else
54  {
55  *sec = tv.tv_sec;
56  *usec = tv.tv_usec;
57  }
58 
59  return status;
60 }
61 
62 int
63 octave_cpu_time (time_t *usr_sec, time_t *sys_sec,
64  long *usr_usec, long *sys_usec)
65 {
66  struct rusage ru;
67 
68  int status = getrusage (RUSAGE_SELF, &ru);
69 
70  if (status < 0)
71  {
72  *usr_sec = 0;
73  *sys_sec = 0;
74 
75  *usr_usec = 0;
76  *sys_usec = 0;
77  }
78  else
79  {
80  *usr_sec = ru.ru_utime.tv_sec;
81  *usr_usec = ru.ru_utime.tv_usec;
82 
83  *sys_sec = ru.ru_stime.tv_sec;
84  *sys_usec = ru.ru_stime.tv_usec;
85  }
86 
87  return status;
88 }
89 
90 int
91 octave_getrusage_wrapper (time_t *usr_sec, time_t *sys_sec,
92  long *usr_usec, long *sys_usec,
93  long *maxrss, long *ixrss, long *idrss,
94  long *isrss, long *minflt, long *majflt,
95  long *nswap, long *inblock, long *oublock,
96  long *msgsnd, long *msgrcv, long *nsignals,
97  long *nvcsw, long *nivcsw)
98 {
99  struct rusage ru;
100 
101  int status = getrusage (RUSAGE_SELF, &ru);
102 
103  if (status < 0)
104  {
105  *usr_sec = 0;
106  *usr_usec = 0;
107 
108  *sys_sec = 0;
109  *sys_usec = 0;
110 
111  *maxrss = 0;
112  *ixrss = 0;
113  *idrss = 0;
114  *isrss = 0;
115  *minflt = 0;
116  *majflt = 0;
117  *nswap = 0;
118  *inblock = 0;
119  *oublock = 0;
120  *msgsnd = 0;
121  *msgrcv = 0;
122  *nsignals = 0;
123  *nvcsw = 0;
124  *nivcsw = 0;
125  }
126  else
127  {
128  *usr_sec = ru.ru_utime.tv_sec;
129  *usr_usec = ru.ru_utime.tv_usec;
130 
131  *sys_sec = ru.ru_stime.tv_sec;
132  *sys_usec = ru.ru_stime.tv_usec;
133 
134  *maxrss = ru.ru_maxrss;
135  *ixrss = ru.ru_ixrss;
136  *idrss = ru.ru_idrss;
137  *isrss = ru.ru_isrss;
138  *minflt = ru.ru_minflt;
139  *majflt = ru.ru_majflt;
140  *nswap = ru.ru_nswap;
141  *inblock = ru.ru_inblock;
142  *oublock = ru.ru_oublock;
143  *msgsnd = ru.ru_msgsnd;
144  *msgrcv = ru.ru_msgrcv;
145  *nsignals = ru.ru_nsignals;
146  *nvcsw = ru.ru_nvcsw;
147  *nivcsw = ru.ru_nivcsw;
148  }
149 
150  return status;
151 }
152 
153 time_t
154 octave_mktime_wrapper (struct tm *tp)
155 {
156  return mktime (tp);
157 }
int octave_cpu_time(time_t *usr_sec, time_t *sys_sec, long *usr_usec, long *sys_usec)
Definition: time-wrappers.c:63
int octave_gettimeofday_wrapper(time_t *sec, long *usec)
Definition: time-wrappers.c:42
time_t octave_mktime_wrapper(struct tm *tp)
int octave_getrusage_wrapper(time_t *usr_sec, time_t *sys_sec, long *usr_usec, long *sys_usec, long *maxrss, long *ixrss, long *idrss, long *isrss, long *minflt, long *majflt, long *nswap, long *inblock, long *oublock, long *msgsnd, long *msgrcv, long *nsignals, long *nvcsw, long *nivcsw)
Definition: time-wrappers.c:91