version 1.15, 2004/11/22 15:26:53 |
version 1.16, 2005/06/08 22:36:43 |
|
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
|
#include <err.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
cnt += 3; |
cnt += 3; |
|
|
/* allocate a char * array to hold the pointers */ |
/* allocate a char * array to hold the pointers */ |
argarray = (char **) malloc(cnt * sizeof(char *)); |
if ((argarray = malloc(cnt * sizeof(char *))) == NULL) |
|
err(1, NULL); |
|
|
/* allocate another array to hold the strings themselves */ |
/* allocate another array to hold the strings themselves */ |
args = (char *) malloc(length + 2); |
if ((args = malloc(length + 2)) == NULL) |
|
err(1, NULL); |
|
|
/* initialization for main loop */ |
/* initialization for main loop */ |
from = line; |
from = line; |
|
|
* useful on BSD mchines for calculating cpu state percentages. |
* useful on BSD mchines for calculating cpu state percentages. |
*/ |
*/ |
int |
int |
percentages(int cnt, int *out, long *new, long *old, long *diffs) |
percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_t *diffs) |
{ |
{ |
long change, total_change, *dp, half_total; |
int64_t change, total_change, *dp, half_total; |
int i; |
int i; |
|
|
/* initialization */ |
/* initialization */ |
|
|
for (i = 0; i < cnt; i++) { |
for (i = 0; i < cnt; i++) { |
if ((change = *new - *old) < 0) { |
if ((change = *new - *old) < 0) { |
/* this only happens when the counter wraps */ |
/* this only happens when the counter wraps */ |
change = ((unsigned int)*new - (unsigned int)*old); |
change = (*new - *old); |
} |
} |
total_change += (*dp++ = change); |
total_change += (*dp++ = change); |
*old++ = *new++; |
*old++ = *new++; |