GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getrusage.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "oct-time.h"
28 
29 #include "defun.h"
30 #include "oct-map.h"
31 #include "ov.h"
32 #include "ovl.h"
33 
34 DEFUN (getrusage, , ,
35  doc: /* -*- texinfo -*-
36 @deftypefn {} {} getrusage ()
37 Return a structure containing a number of statistics about the current
38 Octave process.
39 
40 Not all fields are available on all systems. If it is not possible to get
41 CPU time statistics, the CPU time slots are set to zero. Other missing data
42 are replaced by NaN@. The list of possible fields is:
43 
44 @table @code
45 @item idrss
46 Unshared data size.
47 
48 @item inblock
49 Number of block input operations.
50 
51 @item isrss
52 Unshared stack size.
53 
54 @item ixrss
55 Shared memory size.
56 
57 @item majflt
58 Number of major page faults.
59 
60 @item maxrss
61 Maximum data size.
62 
63 @item minflt
64 Number of minor page faults.
65 
66 @item msgrcv
67 Number of messages received.
68 
69 @item msgsnd
70 Number of messages sent.
71 
72 @item nivcsw
73 Number of involuntary context switches.
74 
75 @item nsignals
76 Number of signals received.
77 
78 @item nswap
79 Number of swaps.
80 
81 @item nvcsw
82 Number of voluntary context switches.
83 
84 @item oublock
85 Number of block output operations.
86 
87 @item stime
88 A structure containing the system CPU time used. The structure has the
89 elements @code{sec} (seconds) @code{usec} (microseconds).
90 
91 @item utime
92 A structure containing the user CPU time used. The structure has the
93 elements @code{sec} (seconds) @code{usec} (microseconds).
94 @end table
95 @end deftypefn */)
96 {
97  octave_scalar_map ru_map;
98  octave_scalar_map tv_map;
99 
101 
102  octave::sys::cpu_time cpu = rusage.cpu ();
103 
104  tv_map.assign ("sec", cpu.user_sec ());
105  tv_map.assign ("usec", cpu.user_usec ());
106  ru_map.assign ("utime", octave_value (tv_map));
107 
108  tv_map.assign ("sec", cpu.system_sec ());
109  tv_map.assign ("usec", cpu.system_usec ());
110  ru_map.assign ("stime", octave_value (tv_map));
111 
112  ru_map.assign ("maxrss", static_cast<double> (rusage.maxrss ()));
113  ru_map.assign ("ixrss", static_cast<double> (rusage.ixrss ()));
114  ru_map.assign ("idrss", static_cast<double> (rusage.idrss ()));
115  ru_map.assign ("isrss", static_cast<double> (rusage.isrss ()));
116  ru_map.assign ("minflt", static_cast<double> (rusage.minflt ()));
117  ru_map.assign ("majflt", static_cast<double> (rusage.majflt ()));
118  ru_map.assign ("nswap", static_cast<double> (rusage.nswap ()));
119  ru_map.assign ("inblock", static_cast<double> (rusage.inblock ()));
120  ru_map.assign ("oublock", static_cast<double> (rusage.oublock ()));
121  ru_map.assign ("msgsnd", static_cast<double> (rusage.msgsnd ()));
122  ru_map.assign ("msgrcv", static_cast<double> (rusage.msgrcv ()));
123  ru_map.assign ("nsignals", static_cast<double> (rusage.nsignals ()));
124  ru_map.assign ("nvcsw", static_cast<double> (rusage.nvcsw ()));
125  ru_map.assign ("nivcsw", static_cast<double> (rusage.nivcsw ()));
126 
127  return ovl (ru_map);
128 }
129 
130 /*
131 %!test
132 %! r = getrusage ();
133 %! assert (isstruct (r));
134 %! assert (isfield (r, "idrss"));
135 %! assert (isfield (r, "inblock"));
136 %! assert (isfield (r, "isrss"));
137 %! assert (isfield (r, "ixrss"));
138 %! assert (isfield (r, "majflt"));
139 %! assert (isfield (r, "maxrss"));
140 %! assert (isfield (r, "minflt"));
141 %! assert (isfield (r, "msgrcv"));
142 %! assert (isfield (r, "msgsnd"));
143 %! assert (isfield (r, "nivcsw"));
144 %! assert (isfield (r, "nsignals"));
145 %! assert (isfield (r, "nswap"));
146 %! assert (isfield (r, "nvcsw"));
147 %! assert (isfield (r, "oublock"));
148 %! assert (isfield (r, "stime"));
149 %! assert (isfield (r, "utime"));
150 %! assert (isfield (r.stime, "sec"));
151 %! assert (isfield (r.stime, "usec"));
152 %! assert (isfield (r.utime, "sec"));
153 %! assert (isfield (r.utime, "usec"));
154 */
long isrss(void) const
Definition: oct-time.h:490
long minflt(void) const
Definition: oct-time.h:491
time_t user_sec(void) const
Definition: oct-time.h:413
cpu_time cpu(void) const
Definition: oct-time.h:485
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
long ixrss(void) const
Definition: oct-time.h:488
long inblock(void) const
Definition: oct-time.h:494
long nsignals(void) const
Definition: oct-time.h:498
long nivcsw(void) const
Definition: oct-time.h:500
long msgsnd(void) const
Definition: oct-time.h:496
long maxrss(void) const
Definition: oct-time.h:487
long nvcsw(void) const
Definition: oct-time.h:499
time_t system_sec(void) const
Definition: oct-time.h:416
long user_usec(void) const
Definition: oct-time.h:414
long majflt(void) const
Definition: oct-time.h:492
long idrss(void) const
Definition: oct-time.h:489
long msgrcv(void) const
Definition: oct-time.h:497
long oublock(void) const
Definition: oct-time.h:495
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:223
long system_usec(void) const
Definition: oct-time.h:417
long nswap(void) const
Definition: oct-time.h:493