Question: You will create a script which will take several arguments, the first will be the executable to test and the remaining will be a series
You will create a script which will take several arguments, the first will be the executable to
test and the remaining will be a series of test inputs to give the program. ie:
$ profiler sh phonebook test in txt test in txt
profiling execution time Points
Your script should run the executable given, passing the test input to it and time the
execution man time to capture its output
profiling cpu and memory usage Points
Your script should also monitor the processs CPU and memory usage at ms intervals
hint: man sleep Recall you can get these values from the output of ps
Note: Although the shell can return the process id pid of the last started process with $
this will only be the last process the shell started, which when using the time command
will be the time command itself, not the process you intend to test. You will instead need
to find the process in ps another way.
You will also need to be doing two things at once. To do this you will need to utilize
background processes and a method to communicate the output of the background process
back to the main script.
You can start a process in the background by adding & at the end of the command. The
script will immediately proceed to the next command and the background task will run in
parallel.
A note on commands running in commands in the background:
var$backgroundtask & will wait for the backgroundtask to finish, but not set var to
its output.
var$backgroundtask & will not wait, and will not set var.
time is also a built in of bash, but does not allow output capture, so you will need to run this command
as time
yes, sleep can accept sub second intervals
You will therefore need to either use a temporary variable or create a function which runs
a subshell and export to set a variable in the parent shell.
You also may need to stop the background task depending on which task you made the
background task or detect the background task has exited. You can terminate processes
using the kill command. and remember from above you can use $ to get the last started
process sub shells are processes
profiling output Points
After running a test output your program should output the following:
:
testfilename:
Where all of the items should be replaced with their correct values, and the number of
outputs depends on the run time of the test.
Note that even if your timing or cpu profiling is incomplete you must output
some part of the above output for the sections that are complete to be fully
marked
profiling inputs Points
In this section you will create input profiles to be used on the phonebook program. You
may test on your own solution to Assignment or use the provided solution.
Profiling is different from testing. When profiling you are attempting to create specific use
patterns so you can understand how a program behaves. You are not attempting to test
the limitations of the program or its functionality. In general your profiling inputs will need
to be much longer than a testing input, and may be repetitive. Its OK to use copypaste,
or you may even want to write a shell script to generate patterns. Given that our profiler
monitors every ms we generally want our test inputs to take more than second to run
though seconds is better For the sanity of your markers please do not make tests
longer than seconds.
A profiling input may look like:
Cyclically adding entries and removing them either to full, or some partially full state
Adding a large number of entries and testing filtermap functions
Randomly adding and removing entries
Creating specific list populations wrt where find will locate an item
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
