LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script - Find time between entries in log file (https://www.linuxquestions.org/questions/linux-newbie-8/script-find-time-between-entries-in-log-file-4175418304/)

antegallya 07-24-2012 04:35 PM

Quote:

Thanks. I'm getting "Generations are not sequential !"
That's because you have generations taking place simultaneously. The problem there is to define what to do in that case
If you in your logs something like
Code:

1 generating
4 generating
8 completed
10 completed

Does it means there was a generation that took 4ms and the other took 9. Or the first one took 7ms and the second one took 6ms ?

The code you modified takes the first solution. But I don't find it the most correct as it will most likely give you generation times really far from reality if there's a lot of nesting. I personnaly prefer the second interpretation. For that one, here is another code :
Code:

#!/usr/bin/awk -f
BEGIN {
        idxb = 0;
        idxe = 0;
}

/- generating VirtualCard/ {
        jobs[idxe++] = $1;
}

/Completed generating VirtualCard/ {
        print "Generated a VirtualCard in", ($1 - jobs[idxb++]) / 1000, "s";
}

It doesn't check for an invalid log file anymore. I will give an incorrect generation time if the log starts with "Completed".
I've also modified it to display seconds instead of milliseconds -- it's as simple as dividing the answer by 1000...

Concerning the calling of the script, you can avoid using that loop (which seems somewhat wrong, why do you append the content of the logs to generation.log ?) :
Code:

cat logFile.*.log | ./script.sh > generation.log
Regards,
Antegallya

blsimpson 07-24-2012 07:03 PM

Awesome. That takes care of everything. :)

The reason I am writing to another log file, is I need to take the times, and plot them in a graph to watch the time increase.


All times are GMT -5. The time now is 01:02 AM.