1189
|
1 // resource.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1189
|
26 #endif |
|
27 |
|
28 #include "tree-const.h" |
|
29 #include "systime.h" |
|
30 #include "oct-obj.h" |
|
31 #include "oct-map.h" |
|
32 #include "defun.h" |
|
33 #include "utils.h" |
|
34 #include "help.h" |
|
35 |
|
36 #ifdef HAVE_SYS_RESOURCE_H |
|
37 extern "C" |
|
38 { |
|
39 #include <sys/resource.h> |
|
40 } |
|
41 #endif |
|
42 |
|
43 #ifndef RUSAGE_SELF |
|
44 #define RUSAGE_SELF 0 |
|
45 #endif |
|
46 |
|
47 // System resource functions. |
|
48 |
|
49 static Octave_map |
|
50 mk_ru_map (struct rusage *ru) |
|
51 { |
|
52 Octave_map m; |
|
53 Octave_map tv_tmp; |
|
54 |
|
55 #if defined (HAVE_GETRUSAGE) |
|
56 tv_tmp ["tv_sec"] = (double) ru->ru_utime.tv_sec; |
|
57 tv_tmp ["tv_usec"] = (double) ru->ru_utime.tv_usec; |
|
58 m ["ru_utime"] = tree_constant (tv_tmp); |
|
59 |
|
60 tv_tmp ["tv_sec"] = (double) ru->ru_stime.tv_sec; |
|
61 tv_tmp ["tv_usec"] = (double) ru->ru_stime.tv_usec; |
|
62 m ["ru_stime"] = tree_constant (tv_tmp); |
|
63 |
|
64 m ["ru_maxrss"] = (double) ru->ru_maxrss; |
|
65 m ["ru_ixrss"] = (double) ru->ru_ixrss; |
|
66 m ["ru_idrss"] = (double) ru->ru_idrss; |
|
67 m ["ru_isrss"] = (double) ru->ru_isrss; |
|
68 m ["ru_minflt"] = (double) ru->ru_minflt; |
|
69 m ["ru_majflt"] = (double) ru->ru_majflt; |
|
70 m ["ru_nswap"] = (double) ru->ru_nswap; |
|
71 m ["ru_inblock"] = (double) ru->ru_inblock; |
|
72 m ["ru_oublock"] = (double) ru->ru_oublock; |
|
73 m ["ru_msgsnd"] = (double) ru->ru_msgsnd; |
|
74 m ["ru_msgrcv"] = (double) ru->ru_msgrcv; |
|
75 m ["ru_nsignals"] = (double) ru->ru_nsignals; |
|
76 m ["ru_nvcsw"] = (double) ru->ru_nvcsw; |
|
77 m ["ru_nivcsw"] = (double) ru->ru_nivcsw; |
|
78 #else |
|
79 tv_tmp ["tv_sec"] = octave_NaN; |
|
80 tv_tmp ["tv_usec"] = octave_NaN; |
|
81 m ["ru_utime"] = tree_constant (tv_tmp); |
|
82 |
|
83 tv_tmp ["tv_sec"] = octave_NaN; |
|
84 tv_tmp ["tv_usec"] = octave_NaN; |
|
85 m ["ru_stime"] = tree_constant (tv_tmp); |
|
86 |
|
87 m ["ru_maxrss"] = octave_NaN; |
|
88 m ["ru_ixrss"] = octave_NaN; |
|
89 m ["ru_idrss"] = octave_NaN; |
|
90 m ["ru_isrss"] = octave_NaN; |
|
91 m ["ru_minflt"] = octave_NaN; |
|
92 m ["ru_majflt"] = octave_NaN; |
|
93 m ["ru_nswap"] = octave_NaN; |
|
94 m ["ru_inblock"] = octave_NaN; |
|
95 m ["ru_oublock"] = octave_NaN; |
|
96 m ["ru_msgsnd"] = octave_NaN; |
|
97 m ["ru_msgrcv"] = octave_NaN; |
|
98 m ["ru_nsignals"] = octave_NaN; |
|
99 m ["ru_nvcsw"] = octave_NaN; |
|
100 m ["ru_nivcsw"] = octave_NaN; |
|
101 #endif |
|
102 |
|
103 return m; |
|
104 } |
|
105 |
|
106 DEFUN ("getrusage", Fgetrusage, Sgetrusage, 0, 0, |
|
107 "getrusage ()\n\ |
|
108 \n\ |
|
109 Return system resource statistics.") |
|
110 { |
|
111 Octave_object retval; |
|
112 |
|
113 #if defined (HAVE_GETRUSAGE) |
|
114 |
|
115 struct rusage resource_stats; |
|
116 |
|
117 getrusage (RUSAGE_SELF, &resource_stats); |
|
118 |
1193
|
119 retval = tree_constant (mk_ru_map (&resource_stats)); |
1189
|
120 |
|
121 #endif |
|
122 |
|
123 return retval; |
|
124 } |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; page-delimiter: "^/\\*" *** |
|
130 ;;; End: *** |
|
131 */ |