[BACK]Return to other_timing_package.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / System

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>