Merge branch 'misaligned-struct-access' of BenBE/htop

Closes #263
This commit is contained in:
Daniel Lange 2020-10-18 19:43:59 +02:00
commit 8c93f31809
1 changed files with 12 additions and 11 deletions

View File

@ -766,7 +766,7 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) {
struct nlmsghdr *nlhdr; struct nlmsghdr *nlhdr;
struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1]; struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1];
struct nlattr *nlattr; struct nlattr *nlattr;
struct taskstats *stats; struct taskstats stats;
int rem; int rem;
unsigned long long int timeDelta; unsigned long long int timeDelta;
LinuxProcess* lp = (LinuxProcess*) linuxProcess; LinuxProcess* lp = (LinuxProcess*) linuxProcess;
@ -778,20 +778,21 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) {
} }
if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) { if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) {
stats = nla_data(nla_next(nla_data(nlattr), &rem)); memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats));
assert(lp->super.pid == (pid_t)stats->ac_pid); assert(lp->super.pid == (pid_t)stats.ac_pid);
timeDelta = (stats->ac_etime*1000 - lp->delay_read_time);
timeDelta = (stats.ac_etime*1000 - lp->delay_read_time);
#define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x; #define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x;
#define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100); #define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100);
lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total); lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total);
lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total); lp->blkio_delay_percent = DELTAPERC(stats.blkio_delay_total, lp->blkio_delay_total);
lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total); lp->swapin_delay_percent = DELTAPERC(stats.swapin_delay_total, lp->swapin_delay_total);
#undef DELTAPERC #undef DELTAPERC
#undef BOUNDS #undef BOUNDS
lp->swapin_delay_total = stats->swapin_delay_total; lp->swapin_delay_total = stats.swapin_delay_total;
lp->blkio_delay_total = stats->blkio_delay_total; lp->blkio_delay_total = stats.blkio_delay_total;
lp->cpu_delay_total = stats->cpu_delay_total; lp->cpu_delay_total = stats.cpu_delay_total;
lp->delay_read_time = stats->ac_etime*1000; lp->delay_read_time = stats.ac_etime*1000;
} }
return NL_OK; return NL_OK;
} }