LINUX.ORG.RU

API для получения загрузки процессора.


0

0

Мне нужно в моей программе получить производительность процессора, разложенный на user, system, I/O. Подобные показатели есть в sysinfo но я не знаю как это конвертировать в проценты. Помогите если кто знает.

Ответ на: комментарий от jr_A

В таком случае лучше sar или top. Мне нужно для всей системы в целом. Я надеялся не рыться в исходниках.

Но все равно спасибо.

borispli
() автор топика

/proc/stat
1.8 Miscellaneous kernel statistics in /proc/stat
-------------------------------------------------

Various pieces of information about kernel activity are available in the
/proc/stat file. All of the numbers reported in this file are aggregates
since the system first booted. For a quick look, simply cat the file:

> cat /proc/stat
cpu 2255 34 2290 22625563 6290 127 456
cpu0 1132 34 1441 11311718 3675 127 438
cpu1 1123 0 849 11313845 2614 0 18
intr 114930548 113199788 3 0 5 263 0 4 [... lots more numbers ...]
ctxt 1990473
btime 1062191376
processes 2915
procs_running 1
procs_blocked 0

The very first "cpu" line aggregates the numbers in all of the other "cpuN"
lines. These numbers identify the amount of time the CPU has spent performing
different kinds of work. Time units are in USER_HZ (typically hundredths of a
second). The meanings of the columns are as follows, from left to right:

- user: normal processes executing in user mode
- nice: niced processes executing in user mode
- system: processes executing in kernel mode
- idle: twiddling thumbs
- iowait: waiting for I/O to complete
- irq: servicing interrupts
- softirq: servicing softirqs

TaranSergey
()
Ответ на: комментарий от borispli

>Мне нужно для всей системы в целом. Я надеялся не рыться в исходниках.

Буду очень благодарен, если кто-нибудь подскажет, как это сделать не для всей системы, а для отдельного процесса (хотя, может быть, я что-то не очень верно понимаю) через некоторые промежутки времени. Очень нужно

BigBiker
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.