Annotation of OpenXM_contrib/PHC/Ada/System/unix_resource_usage.adb, Revision 1.1.1.1
1.1 maekawa 1: package body Unix_Resource_Usage is
2:
3: package C_Interfaces is
4:
5: times_map : constant array (times_enum)
6: of integer
7: := (self => 0, children => -1);
8:
9: function getrusage (who : integer;
10: rusage : system.address)
11: return integer;
12: pragma interface (C, getrusage);
13:
14: function timeval_to_duration (tv : timeval)
15: return duration;
16:
17: end C_Interfaces;
18:
19: function Get_Process_Times (who : times_enum := self)
20: return Process_Times
21: is
22: answer : Process_Times;
23: c_result : integer;
24: begin
25: c_result := C_Interfaces.getrusage
26: (who => C_Interfaces.times_map(who),
27: rusage => answer'address);
28: if (c_result = -1) then
29: raise program_error; -- something broke in Unix!
30: else
31: return answer;
32: end if;
33: end Get_Process_Times;
34:
35: function Total_Time_of (Times: in Process_Times)
36: return duration
37: is
38: begin
39: return user_cpu_time_of (times) + system_cpu_time_of (times);
40: end;
41:
42: function User_CPU_Time_Of (Times: in Process_Times)
43: return Duration
44: is
45: begin
46: return C_Interfaces.timeval_to_duration (times.ru_utime);
47: end User_CPU_Time_Of;
48:
49: function System_CPU_Time_Of (Times: in Process_Times)
50: return Duration
51: is
52: begin
53: return C_Interfaces.timeval_to_duration (times.ru_stime);
54: end System_CPU_Time_Of;
55:
56: function Max_Resident_Set_Size_of (Times: in Process_Times)
57: return natural
58: is
59: begin
60: return times.ru_maxrss;
61: end max_resident_set_size_of;
62:
63: function Shared_Pages_Value_of (Times: in Process_Times)
64: return page_seconds
65: is
66: begin
67: return page_seconds(times.ru_ixrss);
68: end;
69:
70: function Unshared_Data_Pages_Value_of (Times: in Process_Times)
71: return page_seconds
72: is
73: begin
74: return page_seconds(times.ru_idrss);
75: end;
76:
77: function Stack_Pages_Value_of (Times: in Process_Times)
78: return page_seconds
79: is
80: begin
81: return page_seconds(times.ru_isrss);
82: end;
83:
84: function Non_IO_Page_Faults_of (Times: in Process_Times)
85: return natural
86: is
87: begin
88: return times.ru_minflt;
89: end;
90:
91: function IO_Page_Faults_of (Times: in Process_Times)
92: return natural
93: is
94: begin
95: return times.ru_majflt;
96: end;
97:
98: function Swaps_of (Times : in Process_Times)
99: return natural
100: is
101: begin
102: return times.ru_nswap;
103: end;
104:
105: function Input_Blocks_of (Times : in Process_Times)
106: return natural
107: is
108: begin
109: return times.ru_inblock;
110: end;
111:
112: function Output_Blocks_of (Times : in Process_Times)
113: return natural
114: is
115: begin
116: return times.ru_outblock;
117: end;
118:
119: function Socket_Messages_Sent_of (Times : in Process_Times)
120: return natural
121: is
122: begin
123: return times.ru_msgsnd;
124: end;
125:
126: function Socket_Messages_Received_of (Times : in Process_Times)
127: return natural
128: is
129: begin
130: return times.ru_msgrcv;
131: end;
132:
133: function Signals_Delivered_of (Times : in Process_Times)
134: return natural
135: is
136: begin
137: return times.ru_nsignals;
138: end;
139:
140: function Voluntary_Context_Switches_of (Times: in Process_Times)
141: return natural
142: is
143: begin
144: return times.ru_nvcsw;
145: end;
146:
147: function Involuntary_Context_Switches_of (Times: in Process_Times)
148: return natural
149: is
150: begin
151: return times.ru_nivcsw;
152: end;
153:
154: package body C_Interfaces is
155:
156: function timeval_to_duration (tv : timeval)
157: return duration
158: is
159: answer : duration;
160: begin
161: -- on a sun:
162: answer := duration(tv.tv_sec) + duration(tv.tv_usec)/1_000_000;
163: -- on a dec:
164: -- answer := duration(tv.tv_sec);
165: -- if float(tv.tv_usec) <= duration'large
166: -- then answer := answer + duration(tv.tv_usec)/1_000_000;
167: -- else answer := answer + duration(tv.tv_usec/100)/10_000;
168: -- end if;
169: -- because of the strange fact that on a dec
170: -- duration'large is about 2.14E+5 < 1_000_000;
171: -- with the following trials, only the seconds were printed:
172: -- answer := duration(tv.tv_sec + tv.tv_usec/1_000_000);
173: -- answer := duration(tv.tv_sec) + duration(tv.tv_usec/1_000_000);
174: return answer;
175: end timeval_to_duration;
176:
177: end C_Interfaces;
178:
179: end Unix_Resource_Usage;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>