0

I'm searching for a linux tool to make some "performance tests". I have two (or more versions) of programms wihch do the same. To compare versions with each other I want to run these for a specific time (something between 30s and 5m) and then see their load average in the running system for the whole time (e.g. my programm foo needs in 2min about 30% of the system time). To do this in a comfortable way it would be nice to see the whole average system, because the various versions don't consists of one programm with one ID rather than a collection of programms. So if its possible to have a output into a log file then I can search manually for programms which are interesting.

Do anyone know such a program and can help me how to work with it?

0

Stat by process could be found in

/proc/$PID/stat

You could read documentation by running man proc, search for /proc/[pid]/stat:

man -P'less +/\\\/proc\\\/\\\[pid\\\]\\\/stat' proc

...

(14) utime %lu Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)). This includes guest time, guest_time (time spent running a virtual CPU, see below), so that applications that are not aware of the guest time field do not lose that time from their calculations.

(15) stime %lu Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).

Nota: The other fields could be important, for sample if your tool generate many subprocess (children).

For sample, there is a quick perl doing this job, but with a fixed delay of 1 second:

#!/usr/bin/perl -w

my ( $lut, $lst ) = ( 0, 0 );
my $pid = $ARGV[0] or die "No pid";

open FH, "</proc/$pid/stat" or die "Can't open \`\`/proc/$pid/stat''";
open UT, "</proc/uptime"    or die "Can't open \`\`/proc/uptime''";

sub getvals {
    seek FH, 0, 0;
    seek UT, 0, 0;
    my $st  = <FH>;
    my $ut  = <UT>;
    my $out = $lut;
    my $ost = $lst;
    $lut = ( split " ", $ut )[0] * 100;
    $lst = eval( join( "+", ( split " ", $st )[ 13, 14 ] ) );
    return $lut - $out, $lst - $ost;
}
getvals;
$| = 1;
while (1) {
    sleep 1;
    printf "%7.2f%%\n", eval sprintf "100/%s*%s", getvals;
};
  • Thanks for your answer and try to help me. I think this is not helpful for me, because there are, like I said, a huge number of processes to collect. So I must search for all pids for these processes and run the same number of instances of your script started at the same moment... I thought there is any chance to say to top something like: I want a system statistic for the time of 60s with average from the individually processes... – alabamajack Sep 25 '16 at 12:12
  • you could modifiy this script or write your own,.. read values for many files in same field and sumarize is not a big job. – F. Hauri Sep 25 '16 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.