Mercurial > octave
annotate src/DLD-FUNCTIONS/getrusage.cc @ 10840:89f4d7e294cc
Grammarcheck .cc files
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 31 Jul 2010 11:18:11 -0700 |
parents | fa7b5751730c |
children | e9966851619b |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2002, 2003, 2005, 2006, 2007, 2008 |
7017 | 4 John W. Eaton |
2928 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2928 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
28 #include <sys/time.h> |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
29 #include <sys/times.h> |
3176 | 30 #include <sys/types.h> |
31 | |
2928 | 32 #ifdef HAVE_SYS_RESOURCE_H |
33 #include <sys/resource.h> | |
34 #endif | |
35 | |
36 #if defined (HAVE_SYS_PARAM_H) | |
37 #include <sys/param.h> | |
38 #endif | |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
39 |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
40 #include "defun-dld.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
41 #include "oct-map.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
42 #include "sysdep.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
43 #include "ov.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
44 #include "oct-obj.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
45 #include "utils.h" |
2928 | 46 |
47 #if !defined (HZ) | |
48 #if defined (CLK_TCK) | |
49 #define HZ CLK_TCK | |
50 #elif defined (USG) | |
51 #define HZ 100 | |
52 #else | |
53 #define HZ 60 | |
54 #endif | |
55 #endif | |
56 | |
57 #ifndef RUSAGE_SELF | |
58 #define RUSAGE_SELF 0 | |
59 #endif | |
60 | |
61 // System resource functions. | |
62 | |
63 DEFUN_DLD (getrusage, , , | |
3301 | 64 "-*- texinfo -*-\n\ |
65 @deftypefn {Loadable Function} {} getrusage ()\n\ | |
66 Return a structure containing a number of statistics about the current\n\ | |
67 Octave process. Not all fields are available on all systems. If it is\n\ | |
68 not possible to get CPU time statistics, the CPU time slots are set to\n\ | |
10840 | 69 zero. Other missing data are replaced by NaN@. Here is a list of all\n\ |
3301 | 70 the possible fields that can be present in the structure returned by\n\ |
71 @code{getrusage}:\n\ | |
72 \n\ | |
73 @table @code\n\ | |
74 @item idrss\n\ | |
75 Unshared data size.\n\ | |
76 \n\ | |
77 @item inblock\n\ | |
78 Number of block input operations.\n\ | |
79 \n\ | |
80 @item isrss\n\ | |
81 Unshared stack size.\n\ | |
82 \n\ | |
83 @item ixrss\n\ | |
84 Shared memory size.\n\ | |
85 \n\ | |
86 @item majflt\n\ | |
87 Number of major page faults.\n\ | |
88 \n\ | |
89 @item maxrss\n\ | |
90 Maximum data size.\n\ | |
91 \n\ | |
92 @item minflt\n\ | |
93 Number of minor page faults.\n\ | |
2928 | 94 \n\ |
3301 | 95 @item msgrcv\n\ |
96 Number of messages received.\n\ | |
97 \n\ | |
98 @item msgsnd\n\ | |
99 Number of messages sent.\n\ | |
100 \n\ | |
101 @item nivcsw\n\ | |
102 Number of involuntary context switches.\n\ | |
103 \n\ | |
104 @item nsignals\n\ | |
105 Number of signals received.\n\ | |
106 \n\ | |
107 @item nswap\n\ | |
108 Number of swaps.\n\ | |
109 \n\ | |
110 @item nvcsw\n\ | |
111 Number of voluntary context switches.\n\ | |
112 \n\ | |
113 @item oublock\n\ | |
114 Number of block output operations.\n\ | |
115 \n\ | |
116 @item stime\n\ | |
117 A structure containing the system CPU time used. The structure has the\n\ | |
118 elements @code{sec} (seconds) @code{usec} (microseconds).\n\ | |
119 \n\ | |
120 @item utime\n\ | |
121 A structure containing the user CPU time used. The structure has the\n\ | |
122 elements @code{sec} (seconds) @code{usec} (microseconds).\n\ | |
123 @end table\n\ | |
124 @end deftypefn") | |
2928 | 125 { |
126 Octave_map m; | |
127 Octave_map tv_tmp; | |
128 | |
5775 | 129 // FIXME -- maybe encapsulate all of this in a liboctave class |
2928 | 130 #if defined (HAVE_GETRUSAGE) |
131 | |
132 struct rusage ru; | |
133 | |
134 getrusage (RUSAGE_SELF, &ru); | |
135 | |
4675 | 136 tv_tmp.assign ("sec", static_cast<double> (ru.ru_utime.tv_sec)); |
137 tv_tmp.assign ("usec", static_cast<double> (ru.ru_utime.tv_usec)); | |
138 m.assign ("utime", octave_value (tv_tmp)); | |
2928 | 139 |
4675 | 140 tv_tmp.assign ("sec", static_cast<double> (ru.ru_stime.tv_sec)); |
141 tv_tmp.assign ("usec", static_cast<double> (ru.ru_stime.tv_usec)); | |
142 m.assign ("stime", octave_value (tv_tmp)); | |
2928 | 143 |
144 #if ! defined (RUSAGE_TIMES_ONLY) | |
4675 | 145 m.assign ("maxrss", static_cast<double> (ru.ru_maxrss)); |
146 m.assign ("ixrss", static_cast<double> (ru.ru_ixrss)); | |
147 m.assign ("idrss", static_cast<double> (ru.ru_idrss)); | |
148 m.assign ("isrss", static_cast<double> (ru.ru_isrss)); | |
149 m.assign ("minflt", static_cast<double> (ru.ru_minflt)); | |
150 m.assign ("majflt", static_cast<double> (ru.ru_majflt)); | |
151 m.assign ("nswap", static_cast<double> (ru.ru_nswap)); | |
152 m.assign ("inblock", static_cast<double> (ru.ru_inblock)); | |
153 m.assign ("oublock", static_cast<double> (ru.ru_oublock)); | |
154 m.assign ("msgsnd", static_cast<double> (ru.ru_msgsnd)); | |
155 m.assign ("msgrcv", static_cast<double> (ru.ru_msgrcv)); | |
156 m.assign ("nsignals", static_cast<double> (ru.ru_nsignals)); | |
157 m.assign ("nvcsw", static_cast<double> (ru.ru_nvcsw)); | |
158 m.assign ("nivcsw", static_cast<double> (ru.ru_nivcsw)); | |
2928 | 159 #endif |
160 | |
161 #else | |
162 | |
163 struct tms t; | |
164 | |
165 times (&t); | |
166 | |
167 unsigned long ticks; | |
168 unsigned long seconds; | |
169 unsigned long fraction; | |
170 | |
171 ticks = t.tms_utime + t.tms_cutime; | |
172 fraction = ticks % HZ; | |
173 seconds = ticks / HZ; | |
174 | |
4675 | 175 tv_tmp.assign ("sec", static_cast<double> (seconds)); |
176 tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ)); | |
177 m.assign ("utime", octave_value (tv_tmp)); | |
2928 | 178 |
179 ticks = t.tms_stime + t.tms_cstime; | |
180 fraction = ticks % HZ; | |
181 seconds = ticks / HZ; | |
182 | |
4675 | 183 tv_tmp.assign ("sec", static_cast<double> (seconds)); |
184 tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ)); | |
185 m.assign ("stime", octave_value (tv_tmp)); | |
2928 | 186 |
4102 | 187 double tmp = lo_ieee_nan_value (); |
188 | |
4675 | 189 m.assign ("maxrss", tmp); |
190 m.assign ("ixrss", tmp); | |
191 m.assign ("idrss", tmp); | |
192 m.assign ("isrss", tmp); | |
193 m.assign ("minflt", tmp); | |
194 m.assign ("majflt", tmp); | |
195 m.assign ("nswap", tmp); | |
196 m.assign ("inblock", tmp); | |
197 m.assign ("oublock", tmp); | |
198 m.assign ("msgsnd", tmp); | |
199 m.assign ("msgrcv", tmp); | |
200 m.assign ("nsignals", tmp); | |
201 m.assign ("nvcsw", tmp); | |
202 m.assign ("nivcsw", tmp); | |
2928 | 203 |
204 #endif | |
205 | |
206 return octave_value (m); | |
207 } |