Skip to content

Commit

Permalink
Fix for issue Atoptool#261: Offline CPUs not handled well.
Browse files Browse the repository at this point in the history
  • Loading branch information
githubbie committed Feb 27, 2024
1 parent eec97d5 commit dbb56c2
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 87 deletions.
5 changes: 4 additions & 1 deletion atopsar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,10 @@ cpuline(struct sstat *ss, struct tstat *ts, struct tstat **ps, int nactproc,
*/
if (ss->cpu.nrcpu > 1)
{
for (i=0; i < ss->cpu.nrcpu; i++)
for (i=0; i <= ss->cpu.maxcpunr; i++)
{
if (ss->cpu.cpu[i].active)
{
cputot = ss->cpu.cpu[i].stime + ss->cpu.cpu[i].utime +
ss->cpu.cpu[i].ntime + ss->cpu.cpu[i].itime +
ss->cpu.cpu[i].wtime + ss->cpu.cpu[i].Itime +
Expand Down Expand Up @@ -1310,6 +1312,7 @@ cpuline(struct sstat *ss, struct tstat *ts, struct tstat **ps, int nactproc,
postprint(badness);

nlines++;
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions deviate.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ deviatsyst(struct sstat *cur, struct sstat *pre, struct sstat *dev,
struct ifprop ifprop;

dev->cpu.nrcpu = cur->cpu.nrcpu;
dev->cpu.maxcpunr = cur->cpu.maxcpunr;
dev->cpu.devint = subcount(cur->cpu.devint, pre->cpu.devint);
dev->cpu.csw = subcount(cur->cpu.csw, pre->cpu.csw);
dev->cpu.nprocs = subcount(cur->cpu.nprocs, pre->cpu.nprocs);
Expand All @@ -651,11 +652,14 @@ deviatsyst(struct sstat *cur, struct sstat *pre, struct sstat *dev,
dev->cpu.all.instr = subcount(cur->cpu.all.instr, pre->cpu.all.instr);
dev->cpu.all.cycle = subcount(cur->cpu.all.cycle, pre->cpu.all.cycle);

for (i=0; i < dev->cpu.nrcpu; i++)
for (i=0; i <= dev->cpu.maxcpunr; i++)
{
if (cur->cpu.cpu[i].active)
{
count_t ticks;

dev->cpu.cpu[i].cpunr = cur->cpu.cpu[i].cpunr;
dev->cpu.cpu[i].active= cur->cpu.cpu[i].active;
dev->cpu.cpu[i].stime = subcount(cur->cpu.cpu[i].stime,
pre->cpu.cpu[i].stime);
dev->cpu.cpu[i].utime = subcount(cur->cpu.cpu[i].utime,
Expand Down Expand Up @@ -694,6 +698,7 @@ deviatsyst(struct sstat *cur, struct sstat *pre, struct sstat *dev,
subcount(cur->cpu.cpu[i].freqcnt.ticks,
pre->cpu.cpu[i].freqcnt.ticks)
: cur->cpu.cpu[i].freqcnt.ticks;
}
}

dev->cpu.lavg1 = cur->cpu.lavg1;
Expand Down Expand Up @@ -1502,6 +1507,7 @@ totalsyst(char category, struct sstat *new, struct sstat *tot)
{
case 'c': /* accumulate cpu-related counters */
tot->cpu.nrcpu = new->cpu.nrcpu;
tot->cpu.maxcpunr = new->cpu.maxcpunr;
tot->cpu.devint += new->cpu.devint;
tot->cpu.csw += new->cpu.csw;
tot->cpu.nprocs += new->cpu.nprocs;
Expand All @@ -1522,9 +1528,12 @@ totalsyst(char category, struct sstat *new, struct sstat *tot)
}
else
{
for (i=0; i < new->cpu.nrcpu; i++)
for (i=0; i <= new->cpu.maxcpunr; i++)
{
if (new->cpu.cpu[i].active)
{
tot->cpu.cpu[i].cpunr = new->cpu.cpu[i].cpunr;
tot->cpu.cpu[i].active = new->cpu.cpu[i].active;
tot->cpu.cpu[i].stime += new->cpu.cpu[i].stime;
tot->cpu.cpu[i].utime += new->cpu.cpu[i].utime;
tot->cpu.cpu[i].ntime += new->cpu.cpu[i].ntime;
Expand All @@ -1534,6 +1543,7 @@ totalsyst(char category, struct sstat *new, struct sstat *tot)
tot->cpu.cpu[i].Stime += new->cpu.cpu[i].Stime;
tot->cpu.cpu[i].steal += new->cpu.cpu[i].steal;
tot->cpu.cpu[i].guest += new->cpu.cpu[i].guest;
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions json.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,12 @@ json_print_CPU(char *hp, struct sstat *ss,
int i;

// calculate average clock frequency
for (i = 0; i < ss->cpu.nrcpu; i++) {
for (i = 0; i <= ss->cpu.maxcpunr; i++) {
if (ss->cpu.cpu[i].active)
{
cnt += ss->cpu.cpu[i].freqcnt.cnt;
ticks += ss->cpu.cpu[i].freqcnt.ticks;
}
}
maxfreq = ss->cpu.cpu[0].freqcnt.maxfreq;
json_calc_freqscale(maxfreq, cnt, ticks, &freq, &freqperc);
Expand Down Expand Up @@ -388,7 +391,9 @@ json_print_cpu(char *hp, struct sstat *ss,

printf(", %s: [", hp);

for (i = 0; i < ss->cpu.nrcpu; i++) {
for (i = 0; i <= ss->cpu.maxcpunr; i++) {
if (ss->cpu.cpu[i].active)
{
if (i > 0) {
printf(", ");
}
Expand All @@ -412,7 +417,7 @@ json_print_cpu(char *hp, struct sstat *ss,
"\"freqperc\": %d, "
"\"instr\": %lld, "
"\"cycle\": %lld}",
i,
ss->cpu.cpu[i].cpunr,
ss->cpu.cpu[i].stime,
ss->cpu.cpu[i].utime,
ss->cpu.cpu[i].ntime,
Expand All @@ -426,6 +431,7 @@ json_print_cpu(char *hp, struct sstat *ss,
freqperc,
ss->cpu.cpu[i].instr,
ss->cpu.cpu[i].cycle);
}
}

printf("]");
Expand Down
13 changes: 10 additions & 3 deletions parseable.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,13 @@ print_CPU(char *hp, struct sstat *ss,
int i;

// calculate average clock frequency
for (i=0; i < ss->cpu.nrcpu; i++)
for (i=0; i <= ss->cpu.maxcpunr; i++)
{
if (ss->cpu.cpu[i].active)
{
cnt += ss->cpu.cpu[i].freqcnt.cnt;
ticks += ss->cpu.cpu[i].freqcnt.ticks;
}
}
maxfreq = ss->cpu.cpu[0].freqcnt.maxfreq;
calc_freqscale(maxfreq, cnt, ticks, &freq, &freqperc);
Expand Down Expand Up @@ -372,8 +375,10 @@ print_cpu(char *hp, struct sstat *ss,
count_t freq;
int freqperc;

for (i=0; i < ss->cpu.nrcpu; i++)
for (i=0; i <= ss->cpu.maxcpunr; i++)
{
if (ss->cpu.cpu[i].active)
{
cnt = ss->cpu.cpu[i].freqcnt.cnt;
ticks = ss->cpu.cpu[i].freqcnt.ticks;
maxfreq= ss->cpu.cpu[0].freqcnt.maxfreq;
Expand All @@ -382,7 +387,8 @@ print_cpu(char *hp, struct sstat *ss,

printf("%s %u %d %lld %lld %lld "
"%lld %lld %lld %lld %lld %lld %lld %d %lld %lld\n",
hp, hertz, i,
hp, hertz,
ss->cpu.cpu[i].cpunr,
ss->cpu.cpu[i].stime,
ss->cpu.cpu[i].utime,
ss->cpu.cpu[i].ntime,
Expand All @@ -397,6 +403,7 @@ print_cpu(char *hp, struct sstat *ss,
ss->cpu.cpu[i].instr,
ss->cpu.cpu[i].cycle
);
}
}
}

Expand Down
Loading

0 comments on commit dbb56c2

Please sign in to comment.