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. i.e.:
$ profiler . sh ./ phonebook test -1- in . txt test -2- in . txt
profiling execution time [20 Points]
Your script should run the executable given, passing the test input to it and time the
execution (man 1 time1 to capture its output).
profiling cpu and memory usage [40 Points]
Your script should also monitor the processs CPU and memory usage at 100ms intervals
(hint: man sleep2). 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=$(background-task &) will wait for the background-task to finish, but not set var to
its output.
var=$(background-task) & will not wait, and will not set var.
1time is also a built in of bash, but does not allow output capture, so you will need to run this command
as \time
2yes, sleep can accept sub 1 second intervals
2
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 [20 Points]
After running a test output your program should output the following:
:
,,,,,,...
test-file-name2:
,,,,,,...
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 [20 Points]
In this section you will create 2 input profiles to be used on the phonebook program. You
may test on your own solution to Assignment 6, 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 copy-paste,
or you may even want to write a shell script to generate patterns. Given that our profiler
monitors every 100ms, we generally want our test inputs to take more than 1 second to run
(though 3+ seconds is better). For the sanity of your markers please do not make tests
longer than 10 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 filter/map functions
Randomly adding and removing entries
Creating specific list populations w.r.t. where find will locate an item

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!