Getting processor usage information

How can I get CPU usage with process time information in Linux? Basically, I want my application to run overnight. At the same time, I would like to track CPU usage during the period during which the application starts.

I tried the top | grep appName> & log, it doesn't seem to return anything to the log to me. Can anyone help me with this?

Thank.

+3
source share
5 answers

vmstat and iostat may provide you with periodic information of this nature; I would suggest either manually adjust the number of times, or put one poll in the cron job, and then redirect the output to a file:

vmstat 20 4230 >> cpu_log_file

20 24 .

+2

sysstat sar

nohup sar -o output.file 12 8 >/dev/null 2>&1 &
+1

top watch

PID    COMMAND      %CPU TIME     #TH  #WQ  #PORT #MREG RPRVT  RSHRD  RSIZE  VPRVT  VSIZE  PGRP  PPID  STATE    UID  FAULTS    COW    MSGSENT    MSGRECV    SYSBSD    SYSMACH   CSW       PAGEINS USER
10764  top          8.4  00:01.04 1/1  0    24    33    2000K  244K   2576K  17M    2378M      10764 10719 running  0    9908+     54     564790+    282365+    3381+     283412+   838+          27      root
10763  taskgated    0.0  00:00.00 2    0    25    27    432K   244K   1004K  27M    2387M  10763 1     sleeping 0    376       60     140        60         160       109       11        0       root
0

, , getrusage (2) .

0

, , top .

time, , , . time ./my_app ./my_app

man 1 time

0

All Articles