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;








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);










share|improve this question






















  • To reproduce this, an example of the process under observation is also needed.

    – Armali
    Mar 29 at 8:27

















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);










share|improve this question






















  • To reproduce this, an example of the process under observation is also needed.

    – Armali
    Mar 29 at 8:27













0












0








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);










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









0














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.






share|improve this answer























  • 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















0














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.






share|improve this answer























  • 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













0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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








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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현