Thanks for marking the issue to blocked, Vinod
I am submitting this again with the update in
This patch does the following things:
1. Parse utime and stime in /proc/<pid>/stat for all the subprocesses under the assigned PID (see "man proc" for the definition of utime and stime)
2. Compute the CPU time gained for each subprocess (utime + stime) - (last_utime + last_stime). If this is the first time the subprocess is seen, last_utime = 0 and last_stime = 0.
3. Sum the CPU time gained and update the cumulative CPU time of the process tree
This may seem confusing. Note that we cannot simply sum up (utime + stime) for all the subprocesses. This is because some of the subprocesses may finish before the process tree finishes. So if we just sum up the CPU time for the existing subprocesses, we may lose the CPU used by the finished subprocesses. So our approach is computing the CPU gain each update and cumulate them. In this way, even if the subprocess finished, we still get the CPU usage of it.