atop is a great tool that should work for your case. It is an improved
top tool with accounting (which is exactly what you need for the reasons I'll write out next).
atop is a daemon that accounts for a lot of statistics per X seconds (however you configure it, default on Debian is 60s) and it saves a history of all processes and their usages on the system, basically like
atop also has the functionality to print out specific statistics in a parseable format:
atop -r /var/log/atop/atop_<date> -P <format>
This will read the process history from a log file from the specified date and print it out in a machine parseable format specific for certain statistics.
The format you need is PRC:
PRC Process and thread level totals.
This line contains the total cpu time consumed in system mode (`sys') and in user mode (`user'), the total number of processes present at this moment (`#proc'), the total number of threads present at this moment in state `running' (`#trun'), `sleeping
interruptible' (`#tslpi') and `sleeping uninterruptible' (`#tslpu'), the number of zombie processes (`#zombie'), the number of clone system calls (`clones'), and the number of processes that ended during the interval (`#exit') when process accounting is
used. Instead of `#exit` the last column may indicate that process accounting could not be activated (`no procacct`).
If the screen-width does not allow all of these counters, only a relevant subset is shown.
For example, with the following command you will get an output like the following:
$ atop -r /var/log/atop/atop_20200617 -P PRC
PRC hostname 1592403710 2020/06/17 14:21:50 5000098 377 (google_osconfig) S 100 262341 41122 0 120 0 0 0 0 377 y
Where the total SYS CPU time is
262341 and total USR CPU time is
41122 for the process
google_osconfig with PID
atopacct.service is the service that does the accounting and it is a deamon, so it accounts even for short-running processes.
You can install it on Debian 9 via the package manager:
sudo apt-get update
sudo apt-get install atop
And it will automatically start accounting.
You can read more in the manpage.