Mercurial > octave
annotate libinterp/corefcn/getrusage.cc @ 18794:03c2671493f9
maint: Periodic merge of gui-release to default.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 02 Jun 2014 11:17:59 -0700 |
parents | 175b392e91fe |
children | 4197fc428c7d |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
2928 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
27 #include <sys/time.h> |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
28 #include <sys/times.h> |
3176 | 29 #include <sys/types.h> |
30 | |
2928 | 31 #ifdef HAVE_SYS_RESOURCE_H |
32 #include <sys/resource.h> | |
33 #endif | |
34 | |
35 #if defined (HAVE_SYS_PARAM_H) | |
36 #include <sys/param.h> | |
37 #endif | |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
38 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
39 #include "defun.h" |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
40 #include "oct-map.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
41 #include "sysdep.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
42 #include "ov.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
43 #include "oct-obj.h" |
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
44 #include "utils.h" |
2928 | 45 |
46 #if !defined (HZ) | |
47 #if defined (CLK_TCK) | |
48 #define HZ CLK_TCK | |
49 #elif defined (USG) | |
50 #define HZ 100 | |
51 #else | |
52 #define HZ 60 | |
53 #endif | |
54 #endif | |
55 | |
56 #ifndef RUSAGE_SELF | |
57 #define RUSAGE_SELF 0 | |
58 #endif | |
59 | |
60 // System resource functions. | |
61 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
62 DEFUN (getrusage, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
64 @deftypefn {Built-in Function} {} getrusage ()\n\ |
3301 | 65 Return a structure containing a number of statistics about the current\n\ |
66 Octave process. Not all fields are available on all systems. If it is\n\ | |
67 not possible to get CPU time statistics, the CPU time slots are set to\n\ | |
12208
9611014e7cf1
Add function compare_versions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
68 zero. Other missing data are replaced by NaN@. The list of possible\n\ |
9611014e7cf1
Add function compare_versions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
69 fields is:\n\ |
3301 | 70 \n\ |
71 @table @code\n\ | |
72 @item idrss\n\ | |
73 Unshared data size.\n\ | |
74 \n\ | |
75 @item inblock\n\ | |
76 Number of block input operations.\n\ | |
77 \n\ | |
78 @item isrss\n\ | |
79 Unshared stack size.\n\ | |
80 \n\ | |
81 @item ixrss\n\ | |
82 Shared memory size.\n\ | |
83 \n\ | |
84 @item majflt\n\ | |
85 Number of major page faults.\n\ | |
86 \n\ | |
87 @item maxrss\n\ | |
88 Maximum data size.\n\ | |
89 \n\ | |
90 @item minflt\n\ | |
91 Number of minor page faults.\n\ | |
2928 | 92 \n\ |
3301 | 93 @item msgrcv\n\ |
94 Number of messages received.\n\ | |
95 \n\ | |
96 @item msgsnd\n\ | |
97 Number of messages sent.\n\ | |
98 \n\ | |
99 @item nivcsw\n\ | |
100 Number of involuntary context switches.\n\ | |
101 \n\ | |
102 @item nsignals\n\ | |
103 Number of signals received.\n\ | |
104 \n\ | |
105 @item nswap\n\ | |
106 Number of swaps.\n\ | |
107 \n\ | |
108 @item nvcsw\n\ | |
109 Number of voluntary context switches.\n\ | |
110 \n\ | |
111 @item oublock\n\ | |
112 Number of block output operations.\n\ | |
113 \n\ | |
114 @item stime\n\ | |
115 A structure containing the system CPU time used. The structure has the\n\ | |
116 elements @code{sec} (seconds) @code{usec} (microseconds).\n\ | |
117 \n\ | |
118 @item utime\n\ | |
119 A structure containing the user CPU time used. The structure has the\n\ | |
120 elements @code{sec} (seconds) @code{usec} (microseconds).\n\ | |
121 @end table\n\ | |
122 @end deftypefn") | |
2928 | 123 { |
11043
e9966851619b
getpwent.cc, getgrent.cc, getrusage.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
124 octave_scalar_map m; |
e9966851619b
getpwent.cc, getgrent.cc, getrusage.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
125 octave_scalar_map tv_tmp; |
2928 | 126 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 // FIXME: maybe encapsulate all of this in a liboctave class |
2928 | 128 #if defined (HAVE_GETRUSAGE) |
129 | |
130 struct rusage ru; | |
131 | |
132 getrusage (RUSAGE_SELF, &ru); | |
133 | |
4675 | 134 tv_tmp.assign ("sec", static_cast<double> (ru.ru_utime.tv_sec)); |
135 tv_tmp.assign ("usec", static_cast<double> (ru.ru_utime.tv_usec)); | |
136 m.assign ("utime", octave_value (tv_tmp)); | |
2928 | 137 |
4675 | 138 tv_tmp.assign ("sec", static_cast<double> (ru.ru_stime.tv_sec)); |
139 tv_tmp.assign ("usec", static_cast<double> (ru.ru_stime.tv_usec)); | |
140 m.assign ("stime", octave_value (tv_tmp)); | |
2928 | 141 |
142 #if ! defined (RUSAGE_TIMES_ONLY) | |
4675 | 143 m.assign ("maxrss", static_cast<double> (ru.ru_maxrss)); |
144 m.assign ("ixrss", static_cast<double> (ru.ru_ixrss)); | |
145 m.assign ("idrss", static_cast<double> (ru.ru_idrss)); | |
146 m.assign ("isrss", static_cast<double> (ru.ru_isrss)); | |
147 m.assign ("minflt", static_cast<double> (ru.ru_minflt)); | |
148 m.assign ("majflt", static_cast<double> (ru.ru_majflt)); | |
149 m.assign ("nswap", static_cast<double> (ru.ru_nswap)); | |
150 m.assign ("inblock", static_cast<double> (ru.ru_inblock)); | |
151 m.assign ("oublock", static_cast<double> (ru.ru_oublock)); | |
152 m.assign ("msgsnd", static_cast<double> (ru.ru_msgsnd)); | |
153 m.assign ("msgrcv", static_cast<double> (ru.ru_msgrcv)); | |
154 m.assign ("nsignals", static_cast<double> (ru.ru_nsignals)); | |
155 m.assign ("nvcsw", static_cast<double> (ru.ru_nvcsw)); | |
156 m.assign ("nivcsw", static_cast<double> (ru.ru_nivcsw)); | |
2928 | 157 #endif |
158 | |
159 #else | |
160 | |
161 struct tms t; | |
162 | |
163 times (&t); | |
164 | |
165 unsigned long ticks; | |
166 unsigned long seconds; | |
167 unsigned long fraction; | |
168 | |
169 ticks = t.tms_utime + t.tms_cutime; | |
170 fraction = ticks % HZ; | |
171 seconds = ticks / HZ; | |
172 | |
4675 | 173 tv_tmp.assign ("sec", static_cast<double> (seconds)); |
174 tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ)); | |
175 m.assign ("utime", octave_value (tv_tmp)); | |
2928 | 176 |
177 ticks = t.tms_stime + t.tms_cstime; | |
178 fraction = ticks % HZ; | |
179 seconds = ticks / HZ; | |
180 | |
4675 | 181 tv_tmp.assign ("sec", static_cast<double> (seconds)); |
182 tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ)); | |
183 m.assign ("stime", octave_value (tv_tmp)); | |
2928 | 184 |
4102 | 185 double tmp = lo_ieee_nan_value (); |
186 | |
4675 | 187 m.assign ("maxrss", tmp); |
188 m.assign ("ixrss", tmp); | |
189 m.assign ("idrss", tmp); | |
190 m.assign ("isrss", tmp); | |
191 m.assign ("minflt", tmp); | |
192 m.assign ("majflt", tmp); | |
193 m.assign ("nswap", tmp); | |
194 m.assign ("inblock", tmp); | |
195 m.assign ("oublock", tmp); | |
196 m.assign ("msgsnd", tmp); | |
197 m.assign ("msgrcv", tmp); | |
198 m.assign ("nsignals", tmp); | |
199 m.assign ("nvcsw", tmp); | |
200 m.assign ("nivcsw", tmp); | |
2928 | 201 |
202 #endif | |
203 | |
204 return octave_value (m); | |
205 } |