Brief introduction
Ksh_timer is designed to help Ksh or ksh93 script administrators or developers to calculate the time spent in each function and its shell script user-defined section.
The following points define the features of the Ksh_timer:
If you run a script in Ksh_timer, the function called by the script is timed automatically.
The user uses the # #KTB <section_name> (the beginning of this section) and the # #KTE <section_name> (the end of this section) to define the relevant section in the Script Center.
The time given is the total elapsed time, not the time used.
Output included? Main? Time, this is the total elapsed time of the script.
Also include an unknown output time, which is spent outside the function or user-defined part? Main? The time in the section.
The unknown time also includes the ksh_timer overhead caused by the calculated function.
Ksh_timer supports the execution of Ksh and ksh93 scripts.
Usage: Ksh_timer [-d] [-c] [-?] [-S] [Script name arguments ...]
-D puts Ksh_timer in debug mode.
-C retains the original output file (ksh_timer.<script_name>.<pid>.out). is usually deleted after execution.
-S [script name arguments ...] scripting file name and required parameters for the script.
-? Print usage.
Important Tips
This interface (Ksh_timer) is provided for the convenience of the user. This article uses a sample program to illustrate the usage and functionality of Ksh_timer, which are provided as is, and we do not provide any warranty and support.
The tool is already in IBM? Aix? Tested on 5.3,6.1 and version 7.1. Ksh_timer can be used with other operating systems, to do this, you must rebuild the Ksh_timer_c executable for that operating system using the source code provided in the installation section of this article.
Overview
At startup, Ksh_timer reads the input script provided by the command line and constructs the following 3 files (source, timer, and exec files) from it.
The source file contains the original function definition and comes from the exec file.
The timer file contains a wrapper function that includes the timing code and calls the original function. The timer file also comes from the exec file. In the following example, the original function F1 is renamed to F1_orig in the source file, and in the timer file, F1 has a timing code containing the F1_orig function, which allows us to get the time that the original function F1.
The exec file is the source file and the timer file, and contains the original main code and the timer code for any user-defined part.
When the files are built, Ksh_timer runs the build exec file. When you run the original code, the function calculates the elapsed time of the function and user-defined portions, and writes those times to the output file. After doing so, it analyzes the output file, and then calculates the minimum, maximum, average, and total elapsed times of the function name, indentation, iterations, and these functions or code portions, and displays them on the screen.
Use the following input script sample: Ksh_timer.test_pres
#! /usr/bin/ksh
F1 ()
{
echo "Hello"
}
#Main
# #KTB user_defined_section sleep
1
F1
# #KTE User_defined_section sleep
2
F1
Source file: Contains the original function definition
F1_orig ()
{
echo "Hello"
}
Timer file: Contains encapsulated functions including timing code and calling the original function
Function F1
{
time1f1= '/home/albl/ksh_timer/ksh_timer_c '
ksh_timer_add_func F1
f1_orig $*
f1_ Orig_rc=$?
time2f1= '/home/albl/ksh_timer/ksh_timer_c ' let
' time3f1 = $time 2f1-$time 1f1 "
print" $indent 1: $indent 2:$ Indent3: $indent 4: $indent 5: $time 3f1 ">&9
ksh_timer_remove_func F1 return
$f 1_ORIG_RC
}
EXEC file: Contains raw code and timer code for any user-defined section
.
. /ksh_timer.test_pres.413914.source
./ksh_timer.test_pres.413914.timer
time1user_defined_section= '/ Home/albl/ksh_timer/ksh_timer_c '
ksh_timer_add_func user_defined_section sleep
1
F1
time2user_ defined_section= '/home/albl/ksh_timer/ksh_timer_c ' let
' time3user_defined_section= $time 2user_defined_ section-$time 1user_defined_section "
print" $indent 1: $indent 2: $indent 3: $indent 4: $indent 5: $time 3user_defined_ Section ' >&9
ksh_timer_remove_func user_defined_section sleep
2
F1
Run the sample to get the following output:
$/ksh_timer-s./sample----------------------Start of sample output--------------------------------Hello----- -----------------end of sample output---------------------------------------------------------------------------- ----------------------------------------------
| function | Minimum | Maximum | Average | Total | | +-------------------+-------------------+------------+-------------------|
| or section |iter.#| Time |iter.#| Time | Time | #iter. | Time | | |---------------+------+------------+------+------------+------------+------+------------| | Main | |0m03.092834s| |---------------+------+------------+------+------------+------------+------+------------| |-user _defined| 1|0m01.027853s| 1|0m01.027853s|0m01.027853s| 1|0m01.027853s| |--F1 | 1|0m00.003143s| 1|0m00.003143s|0m00.003143s| 1|0m00.003143s| |-F1 | 1|0m00.002652s| 1|0m00.002652s|0m00.002652s| 1|0m00.002652s| |---------------------------------------------------------------------------+------------| | unaccounted |
|0m02.062329s|
------------------------------------------------------------------------------------------