Annotation of OpenXM_contrib/PHC/Ada/System/sun_timing_package.adb, Revision 1.1.1.1
1.1 maekawa 1: with Text_Io, Unix_Resource_Usage;
2:
3: package body Timing_Package is
4:
5: package duration_io is new text_io.fixed_io(duration);
6: package integer_io is new text_io.integer_io (integer);
7:
8: function duration_to_string (dur : duration)
9: return string;
10: pragma inline (duration_to_string);
11:
12: type timing_item is record
13: start_time : Unix_Resource_Usage.Process_Times;
14: stop_time : Unix_Resource_Usage.Process_Times;
15: end record;
16:
17: type rusage_timing_stuff is
18: record
19: total_time : duration;
20: user_time : duration;
21: system_time : duration;
22: -- max_resident_size : natural;
23: -- shared_pages : natural;
24: -- unshared_pages : natural;
25: -- stack_pages : natural;
26: non_io_faults : natural;
27: io_faults : natural;
28: swaps : natural;
29: -- input_blocks : natural;
30: -- output_blocks : natural;
31: -- messages_out : natural;
32: -- messages_in : natural;
33: signals : natural;
34: -- vol_context_switches : natural;
35: -- invol_context_switches : natural;
36: total_context_switches : natural;
37: end record;
38:
39: function to_rusage_timing_stuff (item : Timing_Widget)
40: return rusage_timing_stuff;
41: pragma inline (to_rusage_timing_stuff);
42:
43: procedure tstart ( widget : out Timing_Widget ) is
44:
45: answer : timing_item;
46:
47: begin
48: answer.start_time := Unix_Resource_Usage.get_process_times;
49: widget := new timing_item'(answer);
50: end tstart;
51:
52: procedure tstop ( widget : in out Timing_Widget ) is
53: begin
54: widget.all.stop_time := Unix_Resource_Usage.get_process_times;
55: end tstop;
56:
57: function Elapsed_Total_Time ( widget : Timing_Widget ) return duration is
58: begin
59: return (Unix_Resource_Usage.Total_Time_of(widget.Stop_Time)
60: - Unix_Resource_Usage.Total_Time_of(widget.Start_Time));
61: end Elapsed_Total_Time;
62:
63: function Elapsed_User_Time ( widget : Timing_Widget ) return duration is
64: begin
65: return (Unix_Resource_Usage.User_CPU_Time_of(widget.Stop_Time)
66: - Unix_Resource_Usage.User_CPU_Time_of(widget.Start_Time));
67: end Elapsed_User_Time;
68:
69: function Elapsed_System_Time ( widget : Timing_Widget ) return duration is
70: begin
71: return (Unix_Resource_Usage.System_CPU_Time_of(widget.Stop_Time)
72: - Unix_Resource_Usage.System_CPU_Time_of(widget.Start_Time));
73: end Elapsed_System_Time;
74:
75: procedure print_time ( file : file_type; mach_time : duration ) is
76: begin
77: duration_io.put(file,mach_time);
78: end print_time;
79:
80: function truncate ( d : duration ) return integer is
81:
82: rd : integer := integer(d);
83:
84: begin
85: if rd > 0
86: then if duration(rd) > d
87: then rd := rd-1;
88: end if;
89: end if;
90: return rd;
91: end truncate;
92:
93: procedure print_hms ( file : file_type; mach_time : duration ) is
94:
95: seconds : integer := truncate(mach_time);
96: millsec : integer := integer((mach_time-duration(seconds))*1000);
97: minutes,hours : integer;
98:
99: begin
100: if millsec >= 1000 -- could be due to rounding
101: then seconds := seconds + 1;
102: millsec := millsec - 1000;
103: end if;
104: minutes := seconds/60;
105: hours := minutes/60;
106: seconds := seconds - 60*minutes;
107: minutes := minutes - 60*hours;
108: integer_io.put(file,hours,2); text_io.put(file,"h");
109: integer_io.put(file,minutes,2); text_io.put(file,"m");
110: integer_io.put(file,seconds,2); text_io.put(file,"s");
111: integer_io.put(file,millsec,3); text_io.put(file,"ms");
112: end print_hms;
113:
114: procedure print_times ( widget : Timing_Widget; tag : string := "" ) is
115: begin
116: print_times(Standard_Output,widget,tag);
117: end print_times;
118:
119: procedure print_times ( file : file_type;
120: widget : Timing_Widget; tag : string := "") is
121:
122: rusage_stuff : rusage_timing_stuff;
123:
124: printout_column : text_io.positive_count := 40;
125: function "+" (l,r : text_io.positive_count)
126: return text_io.positive_count renames Text_IO."+";
127:
128: begin
129: text_io.put_line (file,"TIMING INFORMATION for " & tag);
130: rusage_stuff := to_rusage_timing_stuff (widget);
131: -- print out total time
132: Text_Io.Put (file,"The elapsed time in seconds was ");
133: -- text_io.set_col (file,Text_IO.positive_count(printout_column + 3));
134: -- sun4 modification :
135: text_io.set_col (file,Text_IO.positive_count(printout_column));
136: duration_io.put (file,rusage_stuff.total_time);
137: text_io.put(file," = "); print_hms(file,rusage_stuff.total_time);
138: text_io.new_line(file);
139: -- print out user time
140: Text_Io.Put (file,"User time in seconds was ");
141: -- text_io.set_col (file,Text_IO.positive_count(printout_column + 3));
142: -- sun4 modification :
143: text_io.set_col (file,Text_IO.positive_count(printout_column));
144: duration_io.put (file,rusage_stuff.user_time);
145: text_io.put(file," = "); print_hms(file,rusage_stuff.user_time);
146: text_io.new_line(file);
147: -- print out system time
148: Text_Io.Put (file,"System CPU time in seconds was ");
149: -- text_io.set_col (file,text_io.positive_count(printout_column + 3));
150: -- sun4 modification :
151: text_io.set_col (file,text_io.positive_count(printout_column));
152: duration_io.put (file,rusage_stuff.system_time);
153: text_io.put(file," = "); print_hms(file,rusage_stuff.system_time);
154: text_io.new_line(file);
155: -- print out non-I/O page faults
156: Text_IO.put (file,"Non-I/O page faults was ");
157: text_io.set_col (file,printout_column);
158: integer_io.put (file,rusage_stuff.non_io_faults);
159: Text_IO.new_line(file);
160: -- print out I/O page faults
161: Text_IO.put (file,"I/O page faults was ");
162: text_io.set_col (file,printout_column);
163: integer_io.put (file,rusage_stuff.io_faults);
164: text_io.new_line(file);
165: -- print out signals
166: Text_IO.put (file,"Signals delivered was ");
167: text_io.set_col (file,printout_column);
168: integer_io.put (file,rusage_stuff.signals);
169: text_io.new_line(file);
170: -- print out swaps
171: text_io.put (file,"Swaps was ");
172: text_io.set_col (file,printout_column);
173: integer_io.put (file,rusage_stuff.swaps);
174: text_io.new_line(file);
175: -- print out total context switches
176: text_io.put (file,"Total context switches was ");
177: text_io.set_col (file,printout_column);
178: integer_io.put (file,rusage_stuff.total_context_switches);
179: text_io.new_line(file);
180: -- text_io.put_line
181: --("-----------------------------------------------------------------");
182: end print_times;
183:
184: function times_to_string (widget : Timing_Widget;
185: delimiter : string := ":")
186: return string
187: is
188: rusage_stuff : rusage_timing_stuff;
189: begin
190: rusage_stuff := to_rusage_timing_stuff(widget);
191: return "Total Time in seconds => "
192: & duration_to_string (rusage_stuff.total_time) & delimiter
193: & "User Time in seconds => "
194: & duration_to_string (rusage_stuff.user_time) & delimiter
195: & "System Time in seconds => "
196: & duration_to_string (rusage_stuff.system_time) & delimiter
197: & "Non I/O Page Faults => "
198: & integer'image (rusage_stuff.non_io_faults) & delimiter
199: & "I/O Page Faults => "
200: & integer'image (rusage_stuff.io_faults) & delimiter
201: & "Swaps => "
202: & integer'image (rusage_stuff.swaps) & delimiter
203: & "Signals Delivered => "
204: & integer'image (rusage_stuff.signals) & delimiter
205: & "Total Context Switches => "
206: & integer'image (rusage_stuff.total_context_switches) & delimiter;
207: end times_to_string;
208:
209: function duration_to_string (dur : duration) return string is
210:
211: answer : string(1..(duration'fore + duration'aft + 1));
212:
213: begin
214: duration_io.put (to => answer, item => dur);
215: return answer;
216: end duration_to_string;
217:
218: function to_rusage_timing_stuff (item : Timing_Widget)
219: return rusage_timing_stuff is
220:
221: answer : rusage_timing_stuff;
222:
223: begin
224: answer.total_time := Unix_Resource_Usage.total_time_of
225: (item.Stop_Time)
226: - Unix_Resource_Usage.total_time_of
227: (item.Start_Time);
228: answer.user_time := Unix_Resource_Usage.user_cpu_time_of
229: (Item.Stop_time)
230: - Unix_Resource_Usage.user_cpu_time_of
231: (Item.Start_time);
232: answer.system_time := Unix_Resource_Usage.system_cpu_time_of
233: (Item.Stop_time)
234: - Unix_Resource_Usage.system_cpu_time_of
235: (Item.Start_time);
236: answer.non_io_faults := integer(Unix_Resource_Usage.non_io_page_faults_of
237: (item.stop_time)
238: - Unix_Resource_Usage.non_io_page_faults_of
239: (item.start_time));
240: answer.io_faults := integer (Unix_Resource_Usage.io_page_faults_of
241: (item.stop_time)
242: - Unix_Resource_Usage.io_page_faults_of
243: (item.start_time));
244: answer.swaps := (Unix_Resource_Usage.swaps_of
245: (item.stop_time)
246: - Unix_Resource_Usage.swaps_of
247: (item.start_time));
248: answer.signals := (Unix_Resource_Usage.signals_delivered_of
249: (item.stop_time)
250: - Unix_Resource_Usage.signals_delivered_of
251: (item.start_time));
252:
253: answer.total_context_switches
254: := ( Unix_Resource_Usage.voluntary_context_switches_of
255: (item.stop_time)
256: - Unix_Resource_Usage.voluntary_context_switches_of
257: (item.start_time))
258: + (Unix_Resource_Usage.involuntary_context_switches_of
259: (item.stop_time)
260: - Unix_Resource_Usage.involuntary_context_switches_of
261: (item.start_time));
262: return answer;
263: end to_rusage_timing_stuff;
264:
265: end Timing_Package;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>