2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1189
|
19 |
3301
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {[@var{total}, @var{user}, @var{system}] =} cputime (); |
|
22 ## Return the CPU time used by your Octave session. The first output is |
|
23 ## the total time spent executing your process and is equal to the sum of |
|
24 ## second and third outputs, which are the number of CPU seconds spent |
|
25 ## executing in user mode and the number of CPU seconds spent executing in |
|
26 ## system mode, respectively. If your system does not have a way to report |
|
27 ## CPU time usage, @code{cputime} returns 0 for each of its output values. |
|
28 ## Note that because Octave used some CPU time to start, it is reasonable |
|
29 ## to check to see if @code{cputime} works by checking to see if the total |
|
30 ## CPU time used is nonzero. |
|
31 ## @end deftypefn |
1189
|
32 |
2314
|
33 ## Author: jwe |
|
34 |
2311
|
35 function [total, user, system] = cputime () |
1189
|
36 |
|
37 if (nargin != 0) |
|
38 warning ("cputime: ignoring extra arguments"); |
|
39 endif |
|
40 |
|
41 resource_stats = getrusage (); |
|
42 |
1383
|
43 usr = resource_stats.utime; |
|
44 sys = resource_stats.stime; |
1189
|
45 |
2017
|
46 user = usr.sec + usr.usec / 1e6; |
|
47 system = sys.sec + sys.usec / 1e6; |
|
48 total = user + system; |
1189
|
49 |
|
50 endfunction |