Why does my measurement shows that a process consumes more CPU time than available?How do I measure separate CPU core usage for a process?Accurately Calculating CPU Utilization in Linux using /proc/statCalculating user, nice, sys, idle, iowait, irq and sirq from /proc/statWhat is the difference between a core idling or a core is offline in linux?Linux process cpu user ticks delta is bigger than system user ticks deltamemory usage more than 100%Execute process for n cpu cycles/proc/[pid]/stat refresh periodC Program to get CPU usage for a PID and all its childrenSum some elements in a list consisted of strings in C#
How can solar sailed ships be protected from space debris?
how to set the columns in pandas
Can I have a forest in the rain shadow of a mountain range?
Cannot update a field to a Lookup, MasterDetail, or Hierarchy from something else (44:13)
Is there ever a reason not to use Java 8's parallelSort?
What instances can be solved today by modern solvers (pure LP)?
Hiding a solar system in a nebula
What is -(-2,3,4)?
Where is read command?
How is /a/ pronounced before n/m in French?
What could a Medieval society do with excess animal blood?
Old story where computer expert digitally animates The Lord of the Rings
Olive oil in Japanese cooking
How frequently do Russian people still refer to others by their patronymic (отчество)?
I had an c.p.a file late returns, stating i would get money. but i.r.s. says they were filed too late
Why did moving the mouse cursor cause Windows 95 to run more quickly?
Phrasing "it says" or "it reads"
List of Implementations for common OR problems
How long had Bertha Mason been in the attic at the point of the events in Jane Eyre
Are the plates of a battery really charged?
Upload csv into QGIS
CPLEX exceeds time limit issue
Why would a propellor have blades of different lengths?
Is it possible that Curiosity measured its own methane or failed doing the spectrometry?
Why does my measurement shows that a process consumes more CPU time than available?
How do I measure separate CPU core usage for a process?Accurately Calculating CPU Utilization in Linux using /proc/statCalculating user, nice, sys, idle, iowait, irq and sirq from /proc/statWhat is the difference between a core idling or a core is offline in linux?Linux process cpu user ticks delta is bigger than system user ticks deltamemory usage more than 100%Execute process for n cpu cycles/proc/[pid]/stat refresh periodC Program to get CPU usage for a PID and all its childrenSum some elements in a list consisted of strings in C#
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a program where I measure the consumed CPU time of a process on a specific core (here second CPU core). Sometimes I get values higher than 100%.
What is the reason for this value?
Does the total CPU time changes so fast when accessing the CPU time of the process?
How can I get rid of this inaccuracy?
int main(int argc, char **argv)
int pid = 1111;
while (true)
long unsigned int diffCPUTotal, diffUserCPU, diffSysCPU, diffCuCPU, diffCsCPU, procCPUUsage;
setCPUTotal();
setProcCPU(pid);
diffCPUTotal = cpuTotal - prev_cpuTotal;
diffUserCPU = procUserCPU - prev_procUserCPU;
diffSysCPU = procSysCPU - prev_procSysCPU;
diffCuCPU = procCuCPU - prev_procCuCPU;
diffCsCPU = procCsCPU - prev_procCsCPU;
// Process CPU usage including child processes
procCPUUsage = ((diffUserCPU + diffSysCPU + diffCuCPU + diffCsCPU) / (float) diffCPUTotal) * 100;
printf("Process CPU usage: %lu%%n", procCPUUsage);
fflush(stdout);
prev_cpuTotal = cpuTotal;
prev_procUserCPU = procUserCPU;
prev_procSysCPU = procSysCPU;
prev_procCuCPU = procCuCPU;
prev_procCsCPU = procCsCPU;
usleep(500000);
void setCPUTotal()
std::ifstream fstat;
fstat.open("/proc/stat", std::ios_base::in);
std::string line;
// Go to desired line
for (int i = 0; i < 3; ++i)
std::getline(fstat, line);
long unsigned int user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice;
// Get statistics of second cpu core
sscanf(line.c_str(), "cpu1 %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
&user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
fstat.close();
// guest and guest_nice are already included user and nice,
// see http://unix.stackexchange.com/q/178045/20626
cpuTotal = user + nice + system + idle + iowait + irq + softirq + steal;
void setProcCPU(int pid)
std::stringstream ss;
ss << "/proc/" << pid << "/stat";
std::string procStatPath = ss.str();
FILE* fpstat = fopen(procStatPath.c_str(), "r");
fscanf(fpstat, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu"
"%lu %ld %ld %*d %*d %*d %*d %lu %*u %*d",
&procUserCPU, &procSysCPU, &procCuCPU, &procCsCPU, &procStartTime);
fclose(fpstat);
linux cpu-usage measurement procfs
add a comment |
I have a program where I measure the consumed CPU time of a process on a specific core (here second CPU core). Sometimes I get values higher than 100%.
What is the reason for this value?
Does the total CPU time changes so fast when accessing the CPU time of the process?
How can I get rid of this inaccuracy?
int main(int argc, char **argv)
int pid = 1111;
while (true)
long unsigned int diffCPUTotal, diffUserCPU, diffSysCPU, diffCuCPU, diffCsCPU, procCPUUsage;
setCPUTotal();
setProcCPU(pid);
diffCPUTotal = cpuTotal - prev_cpuTotal;
diffUserCPU = procUserCPU - prev_procUserCPU;
diffSysCPU = procSysCPU - prev_procSysCPU;
diffCuCPU = procCuCPU - prev_procCuCPU;
diffCsCPU = procCsCPU - prev_procCsCPU;
// Process CPU usage including child processes
procCPUUsage = ((diffUserCPU + diffSysCPU + diffCuCPU + diffCsCPU) / (float) diffCPUTotal) * 100;
printf("Process CPU usage: %lu%%n", procCPUUsage);
fflush(stdout);
prev_cpuTotal = cpuTotal;
prev_procUserCPU = procUserCPU;
prev_procSysCPU = procSysCPU;
prev_procCuCPU = procCuCPU;
prev_procCsCPU = procCsCPU;
usleep(500000);
void setCPUTotal()
std::ifstream fstat;
fstat.open("/proc/stat", std::ios_base::in);
std::string line;
// Go to desired line
for (int i = 0; i < 3; ++i)
std::getline(fstat, line);
long unsigned int user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice;
// Get statistics of second cpu core
sscanf(line.c_str(), "cpu1 %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
&user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
fstat.close();
// guest and guest_nice are already included user and nice,
// see http://unix.stackexchange.com/q/178045/20626
cpuTotal = user + nice + system + idle + iowait + irq + softirq + steal;
void setProcCPU(int pid)
std::stringstream ss;
ss << "/proc/" << pid << "/stat";
std::string procStatPath = ss.str();
FILE* fpstat = fopen(procStatPath.c_str(), "r");
fscanf(fpstat, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu"
"%lu %ld %ld %*d %*d %*d %*d %lu %*u %*d",
&procUserCPU, &procSysCPU, &procCuCPU, &procCsCPU, &procStartTime);
fclose(fpstat);
linux cpu-usage measurement procfs
To reproduce this, an example of the process under observation is also needed.
– Armali
Mar 29 at 8:27
add a comment |
I have a program where I measure the consumed CPU time of a process on a specific core (here second CPU core). Sometimes I get values higher than 100%.
What is the reason for this value?
Does the total CPU time changes so fast when accessing the CPU time of the process?
How can I get rid of this inaccuracy?
int main(int argc, char **argv)
int pid = 1111;
while (true)
long unsigned int diffCPUTotal, diffUserCPU, diffSysCPU, diffCuCPU, diffCsCPU, procCPUUsage;
setCPUTotal();
setProcCPU(pid);
diffCPUTotal = cpuTotal - prev_cpuTotal;
diffUserCPU = procUserCPU - prev_procUserCPU;
diffSysCPU = procSysCPU - prev_procSysCPU;
diffCuCPU = procCuCPU - prev_procCuCPU;
diffCsCPU = procCsCPU - prev_procCsCPU;
// Process CPU usage including child processes
procCPUUsage = ((diffUserCPU + diffSysCPU + diffCuCPU + diffCsCPU) / (float) diffCPUTotal) * 100;
printf("Process CPU usage: %lu%%n", procCPUUsage);
fflush(stdout);
prev_cpuTotal = cpuTotal;
prev_procUserCPU = procUserCPU;
prev_procSysCPU = procSysCPU;
prev_procCuCPU = procCuCPU;
prev_procCsCPU = procCsCPU;
usleep(500000);
void setCPUTotal()
std::ifstream fstat;
fstat.open("/proc/stat", std::ios_base::in);
std::string line;
// Go to desired line
for (int i = 0; i < 3; ++i)
std::getline(fstat, line);
long unsigned int user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice;
// Get statistics of second cpu core
sscanf(line.c_str(), "cpu1 %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
&user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
fstat.close();
// guest and guest_nice are already included user and nice,
// see http://unix.stackexchange.com/q/178045/20626
cpuTotal = user + nice + system + idle + iowait + irq + softirq + steal;
void setProcCPU(int pid)
std::stringstream ss;
ss << "/proc/" << pid << "/stat";
std::string procStatPath = ss.str();
FILE* fpstat = fopen(procStatPath.c_str(), "r");
fscanf(fpstat, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu"
"%lu %ld %ld %*d %*d %*d %*d %lu %*u %*d",
&procUserCPU, &procSysCPU, &procCuCPU, &procCsCPU, &procStartTime);
fclose(fpstat);
linux cpu-usage measurement procfs
I have a program where I measure the consumed CPU time of a process on a specific core (here second CPU core). Sometimes I get values higher than 100%.
What is the reason for this value?
Does the total CPU time changes so fast when accessing the CPU time of the process?
How can I get rid of this inaccuracy?
int main(int argc, char **argv)
int pid = 1111;
while (true)
long unsigned int diffCPUTotal, diffUserCPU, diffSysCPU, diffCuCPU, diffCsCPU, procCPUUsage;
setCPUTotal();
setProcCPU(pid);
diffCPUTotal = cpuTotal - prev_cpuTotal;
diffUserCPU = procUserCPU - prev_procUserCPU;
diffSysCPU = procSysCPU - prev_procSysCPU;
diffCuCPU = procCuCPU - prev_procCuCPU;
diffCsCPU = procCsCPU - prev_procCsCPU;
// Process CPU usage including child processes
procCPUUsage = ((diffUserCPU + diffSysCPU + diffCuCPU + diffCsCPU) / (float) diffCPUTotal) * 100;
printf("Process CPU usage: %lu%%n", procCPUUsage);
fflush(stdout);
prev_cpuTotal = cpuTotal;
prev_procUserCPU = procUserCPU;
prev_procSysCPU = procSysCPU;
prev_procCuCPU = procCuCPU;
prev_procCsCPU = procCsCPU;
usleep(500000);
void setCPUTotal()
std::ifstream fstat;
fstat.open("/proc/stat", std::ios_base::in);
std::string line;
// Go to desired line
for (int i = 0; i < 3; ++i)
std::getline(fstat, line);
long unsigned int user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice;
// Get statistics of second cpu core
sscanf(line.c_str(), "cpu1 %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
&user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice);
fstat.close();
// guest and guest_nice are already included user and nice,
// see http://unix.stackexchange.com/q/178045/20626
cpuTotal = user + nice + system + idle + iowait + irq + softirq + steal;
void setProcCPU(int pid)
std::stringstream ss;
ss << "/proc/" << pid << "/stat";
std::string procStatPath = ss.str();
FILE* fpstat = fopen(procStatPath.c_str(), "r");
fscanf(fpstat, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu"
"%lu %ld %ld %*d %*d %*d %*d %lu %*u %*d",
&procUserCPU, &procSysCPU, &procCuCPU, &procCsCPU, &procStartTime);
fclose(fpstat);
linux cpu-usage measurement procfs
linux cpu-usage measurement procfs
asked Mar 25 at 18:22
DevJoeDevJoe
183 bronze badges
183 bronze badges
To reproduce this, an example of the process under observation is also needed.
– Armali
Mar 29 at 8:27
add a comment |
To reproduce this, an example of the process under observation is also needed.
– Armali
Mar 29 at 8:27
To reproduce this, an example of the process under observation is also needed.
– Armali
Mar 29 at 8:27
To reproduce this, an example of the process under observation is also needed.
– Armali
Mar 29 at 8:27
add a comment |
1 Answer
1
active
oldest
votes
It's reported in terms of a single core.
100% means "all of one core". If your machine has, say, 8 cores, then the maximum possible is 800%.
If hyperthreading is enabled each hyperthread counts as a core.
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344264%2fwhy-does-my-measurement-shows-that-a-process-consumes-more-cpu-time-than-availab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's reported in terms of a single core.
100% means "all of one core". If your machine has, say, 8 cores, then the maximum possible is 800%.
If hyperthreading is enabled each hyperthread counts as a core.
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
add a comment |
It's reported in terms of a single core.
100% means "all of one core". If your machine has, say, 8 cores, then the maximum possible is 800%.
If hyperthreading is enabled each hyperthread counts as a core.
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
add a comment |
It's reported in terms of a single core.
100% means "all of one core". If your machine has, say, 8 cores, then the maximum possible is 800%.
If hyperthreading is enabled each hyperthread counts as a core.
It's reported in terms of a single core.
100% means "all of one core". If your machine has, say, 8 cores, then the maximum possible is 800%.
If hyperthreading is enabled each hyperthread counts as a core.
answered Mar 25 at 20:16
Jesper JuhlJesper Juhl
19.4k3 gold badges29 silver badges51 bronze badges
19.4k3 gold badges29 silver badges51 bronze badges
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
add a comment |
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
I have disabled hyperthreading and assigned the process with taskset to the specific CPU core. It should never reach a value over 100%. Did I miss anything?
– DevJoe
Mar 26 at 7:08
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344264%2fwhy-does-my-measurement-shows-that-a-process-consumes-more-cpu-time-than-availab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To reproduce this, an example of the process under observation is also needed.
– Armali
Mar 29 at 8:27