Remove white spaces and tabulations at end of lines.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
return 0;
while (fgets(line, sizeof(line), fp) != NULL) {
-
+
if (!strncmp(line, "Share (unique mount targets): ", 30)) {
sscanf(line + 30, "%d", &cifs);
break;
void io_sys_init(void)
{
int i;
-
+
/* How many processors on this machine? */
cpu_nr = get_cpu_nr(~0, FALSE);
perror("malloc");
exit(4);
}
-
+
/* Allocate structures for number of CIFS directories found */
for (i = 0; i < 2; i++) {
if ((st_cifs[i] =
for (i = 0; i < 2; i++) {
free(st_cifs[i]);
}
-
+
free(st_hdr_cifs);
}
}
}
}
-
+
if (start) {
scifs.fopens = all_open;
save_stats(cifs_name, curr, &scifs);
/* Don't buffer data if redirected to a pipe */
setbuf(stdout, NULL);
-
+
do {
if (cpu_nr > 1) {
/*
/* Display an easy-to-read CIFS report */
flags |= I_D_HUMAN_READ;
break;
-
+
case 'k':
if (DISPLAY_MEGABYTES(flags)) {
usage(argv[0]);
/* Print version number and exit */
print_version();
break;
-
+
default:
usage(argv[0]);
}
}
utc++;
}
-
+
if (utc == 2)
return get_gmtime(rectime, d_off);
else
int opt = 1;
int nr = 0;
char *t;
-
+
while (opt < arg_c) {
if (strchr(arg_v[opt], ',')) {
for (t = arg_v[opt]; t; t = strchr(t + 1, ',')) {
}
opt++;
}
-
+
return nr;
}
part++;
}
}
-
+
/* Close directory */
closedir(dir);
if (!access(line, R_OK)) {
/* Yep... */
dev++;
-
+
if (display_partitions) {
/* We also want the number of partitions for this device */
dev += get_dev_part_nr(drd->d_name);
out[MAX_FILE_LEN - 1] = '\0';
free(resolved_name);
-
+
return out;
}
}
snprintf(syspath, sizeof(syspath), "%s/%s%s", SYSFS_BLOCK, name,
allow_virtual ? "" : "/device");
-
+
return !(access(syspath, F_OK));
}
/* prev_time=0 when displaying stats since system startup */
itv = curr_uptime - prev_uptime;
-
+
if (!itv) { /* Paranoia checking */
itv = 1;
}
struct stats_cpu *scp)
{
unsigned long long ishift = 0LL;
-
+
if ((scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest)) {
/*
* Sometimes the nr of jiffies spent in guest mode given by the guest
ishift += (scp->cpu_nice - scp->cpu_guest_nice) -
(scc->cpu_nice - scc->cpu_guest_nice);
}
-
+
/*
* Don't take cpu_guest and cpu_guest_nice into account
* because cpu_user and cpu_nice already include them.
{
double tput
= ((double) (sdc->nr_ios - sdp->nr_ios)) * HZ / itv;
-
+
xds->util = S_VALUE(sdp->tot_ticks, sdc->tot_ticks, itv);
xds->svctm = tput ? xds->util / tput : 0.0;
/*
files = (char **) calloc(n - 1, sizeof(char *));
if (!files)
goto free_list;
-
+
/*
* i is for traversing namelist, k is for files.
* i != k because we are ignoring "." and ".." entries.
files[k] = NULL;
free_list:
-
+
for (i = 0; i < n; i++) {
free(namelist[i]);
}
/* Get current filesystem */
while (fgets(line, sizeof(line), fp) != NULL) {
if (line[0] == '/') {
-
+
/* Read filesystem name and mount point */
sscanf(line, "%71s %127s", fs_name, mountp);
-
+
/* Replace octal codes */
oct2chr(mountp);
-
+
/* Check that total size is not null */
if (statfs(mountp, &buf) < 0)
continue;
-
+
if (buf.f_blocks) {
fs++;
}
strncpy(ioconf_name, IOCONF, 64);
}
ioconf_name[63] = '\0';
-
+
/* Init ioc_refnr array */
memset(ioc_refnr, 0, sizeof(ioc_refnr));
void set_disk_output_unit(void)
{
char *e;
-
+
if (DISPLAY_KILOBYTES(flags) || DISPLAY_MEGABYTES(flags))
return;
void init_stats(void)
{
int i;
-
+
/* Allocate structures for CPUs "all" and 0 */
for (i = 0; i < 2; i++) {
if ((st_cpu[i] = (struct stats_cpu *) malloc(STATS_CPU_SIZE * 2)) == NULL) {
/* Also allocate stat structures for "group" devices */
iodev_nr += group_nr;
-
+
/*
* Allocate structures for number of disks found, but also
* for groups of devices if option -g has been entered on the command line.
void io_sys_free(void)
{
int i;
-
+
for (i = 0; i < 2; i++) {
/* Free CPU structures */
free(st_cpu[i]);
/* Free I/O device structures */
free(st_iodev[i]);
}
-
+
free(st_hdr_iodev);
}
/* Try to read given stat file */
if ((fp = fopen(filename, "r")) == NULL)
return 0;
-
+
i = fscanf(fp, "%lu %lu %lu %lu %lu %lu %lu %u %u %u %u",
&rd_ios, &rd_merges_or_rd_sec, &rd_sec_or_wr_ios, &rd_ticks_or_wr_sec,
&wr_ios, &wr_merges, &wr_sec, &wr_ticks, &ios_pgr, &tot_ticks, &rq_ticks);
sdev.wr_ios = rd_sec_or_wr_ios;
sdev.wr_sectors = rd_ticks_or_wr_sec;
}
-
+
if ((i == 11) || !DISPLAY_EXTENDED(flags)) {
/*
* In fact, we _don't_ save stats if it's a partition without
snprintf(filename, MAX_PF_NAME, "%s/%s/%s",
SYSFS_BLOCK, drd->d_name, S_STAT);
filename[MAX_PF_NAME - 1] = '\0';
-
+
/* If current entry is a directory, try to read its stat file */
ok = read_sysfs_file_stat(curr, filename, drd->d_name);
-
+
/*
* If '-p ALL' was entered on the command line,
* also try to read stats for its partitions
struct stats_disk sdc, sdp;
struct ext_disk_stats xds;
double r_await, w_await;
-
+
/*
* Counters overflows are possible, but don't need to be handled in
* a special way: The difference is still properly calculated if the
sdp.rd_sect = ioj->rd_sectors;
sdc.wr_sect = ioi->wr_sectors;
sdp.wr_sect = ioj->wr_sectors;
-
+
compute_ext_disk_stats(&sdc, &sdp, itv, &xds);
-
+
r_await = (ioi->rd_ios - ioj->rd_ios) ?
(ioi->rd_ticks - ioj->rd_ticks) /
((double) (ioi->rd_ios - ioj->rd_ios)) : 0.0;
for (i = 0; i < iodev_nr; i++, shi++) {
if (shi->used) {
-
+
if (dlist_idx && !HAS_SYSFS(flags)) {
/*
* With /proc/diskstats, stats for every device
/* Device not found in list: Don't display it */
continue;
}
-
+
ioi = st_iodev[curr] + i;
ioj = st_iodev[!curr] + i;
if (!ioi->rd_ios && !ioi->wr_ios)
continue;
}
-
+
if (DISPLAY_ZERO_OMIT(flags)) {
if ((ioi->rd_ios == ioj->rd_ios) &&
(ioi->wr_ios == ioj->wr_ios))
{
int curr = 1;
int skip = 0;
-
+
/* Should we skip first report? */
if (DISPLAY_OMIT_SINCE_BOOT(flags) && interval > 0) {
skip = 1;
/* Don't buffer data if redirected to a pipe */
setbuf(stdout, NULL);
-
+
do {
if (cpu_nr > 1) {
/*
if (!skip) {
/* Print results */
write_stats(curr, rectime);
-
+
if (count > 0) {
count--;
}
(strspn(argv[opt], DIGITS) != strlen(argv[opt])) &&
(strncmp(argv[opt], "-", 1))) {
flags |= I_D_UNFILTERED;
-
+
for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
if (!strcmp(t, K_ALL)) {
flags |= I_D_PART_ALL;
}
group_nr++;
}
-
+
else if (!strcmp(argv[opt], "-j")) {
if (argv[++opt]) {
if (strnlen(argv[opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1) {
/* Display stats in MB/s */
flags |= I_D_MEGABYTES;
break;
-
+
case 'N':
/* Display device mapper logical name */
flags |= I_D_DEVMAP_NAME;
/* Display timestamp */
flags |= I_D_TIMESTAMP;
break;
-
+
case 'x':
/* Display extended stats */
flags |= I_D_EXTENDED;
/* Don't display stats since system restart */
flags |= I_D_OMIT_SINCE_BOOT;
break;
-
+
case 'z':
/* Omit output for devices with no activity */
flags |= I_D_ZERO_OMIT;
/* Print version number and exit */
print_version();
break;
-
+
default:
usage(argv[0]);
}
* then don't apply this rule any more.
*/
flags |= I_D_UNFILTERED;
-
+
if (strcmp(argv[opt], K_ALL)) {
/* Store device name entered on the command line */
devname = device_name(argv[opt++]);
if (!interval) {
count = 1;
}
-
+
/* Default: Display CPU and DISK reports */
if (!report_set) {
flags |= I_D_CPU + I_D_DISK;
/* Free structures */
io_sys_free();
sfree_dev_list();
-
+
return 0;
}
}
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
-
+
scc = (struct stats_cpu *) ((char *) a->buf[curr] + i * a->msize);
scp = (struct stats_cpu *) ((char *) a->buf[!curr] + i * a->msize);
/* Should current CPU (including CPU "all") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
/* Yes: Display current CPU stats */
if (sep) {
printf(",\n");
}
sep = TRUE;
-
+
if (!i) {
/* This is CPU "all" */
strcpy(cpuno, "all");
g_itv = get_per_cpu_interval(scc, scp);
cpu_offline = FALSE;
}
-
+
if (!g_itv) {
/* Current CPU is offline or tickless */
if (DISPLAY_CPU_DEF(a->opt_flags)) {
struct stats_irq *sic, *sip;
int sep = FALSE;
char irqno[8];
-
+
xprintf(tab++, "\"interrupts\": [");
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
sic = (struct stats_irq *) ((char *) a->buf[curr] + i * a->msize);
sip = (struct stats_irq *) ((char *) a->buf[!curr] + i * a->msize);
-
+
/* Should current interrupt (including int "sum") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
/* Yes: Display it */
if (sep) {
struct stats_swap
*ssc = (struct stats_swap *) a->buf[curr],
*ssp = (struct stats_swap *) a->buf[!curr];
-
+
xprintf0(tab, "\"swap-pages\": {"
"\"pswpin\": %.2f, "
"\"pswpout\": %.2f}",
int sep = FALSE;
xprintf0(tab, "\"memory\": {");
-
+
if (DISPLAY_MEM_AMT(a->opt_flags)) {
sep = TRUE;
if (sep) {
printf(", ");
}
-
+
printf("\"frmpg\": %.2f, "
"\"bufpg\": %.2f, "
"\"campg\": %.2f",
{
struct stats_ktables
*skc = (struct stats_ktables *) a->buf[curr];
-
+
xprintf0(tab, "\"kernel\": {"
"\"dentunusd\": %u, "
"\"file-nr\": %u, "
{
struct stats_queue
*sqc = (struct stats_queue *) a->buf[curr];
-
+
xprintf0(tab, "\"queue\": {"
"\"runq-sz\": %lu, "
"\"plist-sz\": %u, "
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"line\": %d, "
"\"rcvin\": %.2f, "
"\"xmtin\": %.2f, "
/* Compute extended statistics values */
compute_ext_disk_stats(sdc, sdp, itv, &xds);
-
+
dev_name = NULL;
persist_dev_name = NULL;
if (DISPLAY_PERSIST_NAME_S(flags)) {
persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
}
-
+
if (persist_dev_name) {
dev_name = persist_dev_name;
}
USE_PRETTY_OPTION(flags));
}
}
-
+
if (sep) {
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"disk-device\": \"%s\", "
"\"tps\": %.2f, "
"\"rd_sec\": %.2f, "
json_markup_network(tab, OPEN_JSON_MARKUP);
tab++;
-
+
xprintf(tab++, "\"net-dev\": [");
for (i = 0; i < a->nr; i++) {
if (!strcmp(sndc->interface, ""))
continue;
-
+
j = check_net_dev_reg(a, curr, !curr, i);
sndp = (struct stats_net_dev *) ((char *) a->buf[!curr] + j * a->msize);
printf(",\n");
}
sep = TRUE;
-
+
rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
txkb = S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv);
ifutil = compute_ifutil(sndc, rxkb, txkb);
json_markup_network(tab, OPEN_JSON_MARKUP);
tab++;
-
+
xprintf(tab++, "\"net-edev\": [");
for (i = 0; i < a->nr; i++) {
if (!strcmp(snedc->interface, ""))
continue;
-
+
j = check_net_edev_reg(a, curr, !curr, i);
snedp = (struct stats_net_edev *) ((char *) a->buf[!curr] + j * a->msize);
-
+
if (sep) {
printf(",\n");
}
struct stats_net_nfs
*snnc = (struct stats_net_nfs *) a->buf[curr],
*snnp = (struct stats_net_nfs *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
{
struct stats_net_sock
*snsc = (struct stats_net_sock *) a->buf[curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_ip
*snic = (struct stats_net_ip *) a->buf[curr],
*snip = (struct stats_net_ip *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_eip
*sneic = (struct stats_net_eip *) a->buf[curr],
*sneip = (struct stats_net_eip *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_icmp
*snic = (struct stats_net_icmp *) a->buf[curr],
*snip = (struct stats_net_icmp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_eicmp
*sneic = (struct stats_net_eicmp *) a->buf[curr],
*sneip = (struct stats_net_eicmp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_tcp
*sntc = (struct stats_net_tcp *) a->buf[curr],
*sntp = (struct stats_net_tcp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_etcp
*snetc = (struct stats_net_etcp *) a->buf[curr],
*snetp = (struct stats_net_etcp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_udp
*snuc = (struct stats_net_udp *) a->buf[curr],
*snup = (struct stats_net_udp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
{
struct stats_net_sock6
*snsc = (struct stats_net_sock6 *) a->buf[curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_ip6
*snic = (struct stats_net_ip6 *) a->buf[curr],
*snip = (struct stats_net_ip6 *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_eip6
*sneic = (struct stats_net_eip6 *) a->buf[curr],
*sneip = (struct stats_net_eip6 *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_icmp6
*snic = (struct stats_net_icmp6 *) a->buf[curr],
*snip = (struct stats_net_icmp6 *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_eicmp6
*sneic = (struct stats_net_eicmp6 *) a->buf[curr],
*sneip = (struct stats_net_eicmp6 *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
struct stats_net_udp6
*snuc = (struct stats_net_udp6 *) a->buf[curr],
*snup = (struct stats_net_udp6 *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_json_markup;
tab++;
xprintf(tab++, "\"cpu-frequency\": [");
-
+
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
-
+
spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr] + i * a->msize);
-
+
/* Should current CPU (including CPU "all") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"number\": \"%s\", "
"\"frequency\": %.2f}",
cpuno,
((double) spc->cpufreq) / 100);
}
}
-
+
printf("\n");
xprintf0(--tab, "]");
tab--;
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"number\": %d, "
"\"rpm\": %llu, "
"\"drpm\": %llu, "
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"number\": %d, "
"\"degC\": %.2f, "
"\"percent-temp\": %.2f, "
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"number\": %d, "
"\"inV\": %.2f, "
"\"percent-in\": %.2f, "
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"bus_number\": %d, "
"\"idvendor\": \"%x\", "
"\"idprod\": \"%x\", "
printf(",\n");
}
sep = TRUE;
-
+
xprintf0(tab, "{\"filesystem\": \"%s\", "
"\"MBfsfree\": %.0f, "
"\"MBfsused\": %.0f, "
/* Check if we want stats about this proc */
if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))))
continue;
-
+
/*
* If the CPU is offline then it is omited from /proc/stat
* and the sum of all values is zero.
/* Recalculate itv for current proc */
pc_itv = get_per_cpu_interval(scc, scp);
-
+
if (!pc_itv) {
/*
* If the CPU is tickless then there is no change in CPU values
scc->cpu_hardirq + scc->cpu_softirq) == 0) {
/* This is an offline CPU */
-
+
if (!DISPLAY_ONLINE_CPU(flags)) {
printf("%-11s %4d"
" %9.2f\n",
cp++;
p = st_ic[curr] + irq;
-
+
li = line;
while (*li == ' ')
li++;
-
+
len = strcspn(li, ":");
if (len >= MAX_IRQ_LEN) {
len = MAX_IRQ_LEN - 1;
}
fclose(fp);
-
+
free(line);
}
/* Read this file to display int per CPU or total nr of int per CPU */
read_interrupts_stat(INTERRUPTS, st_irqcpu, irqcpu_nr, 0);
}
-
+
if (DISPLAY_SOFTIRQS(actflags)) {
read_interrupts_stat(SOFTIRQS, st_softirqcpu, softirqcpu_nr, 0);
}
sigaction(SIGINT, &int_act, NULL);
pause();
-
+
if (sigint_caught)
/* SIGINT signal caught during first interval: Exit immediately */
return;
if (count > 0) {
count--;
}
-
+
if (count) {
-
+
pause();
-
+
if (sigint_caught) {
/* SIGINT signal caught => Display average stats */
count = 0;
/* What is the highest processor number on this machine? */
cpu_nr = get_cpu_nr(~0, TRUE);
-
+
/* Calculate number of interrupts per processor */
irqcpu_nr = get_irqcpu_nr(INTERRUPTS, NR_IRQS, cpu_nr) +
NR_IRQCPU_PREALLOC;
if (argv[++opt]) {
flags |= F_P_OPTION;
dis_hdr++;
-
+
for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
if (!strcmp(t, K_ALL) || !strcmp(t, K_ON)) {
if (cpu_nr) {
flags |= F_P_OPTION;
memset(cpu_bitmap, 0xff, ((cpu_nr + 1) >> 3) + 1);
break;
-
+
case 'u':
/* Display CPU */
actflags |= M_D_CPU;
if (count_bits(&actflags, sizeof(unsigned int)) > 1) {
dis_hdr = 9;
}
-
+
if (!USE_P_OPTION(flags)) {
/* Option -P not used: Set bit 0 (global stats among all proc) */
*cpu_bitmap = 1;
void io_sys_init(void)
{
int i;
-
+
/* How many processors on this machine? */
cpu_nr = get_cpu_nr(~0, FALSE);
perror("malloc");
exit(4);
}
-
+
/* Allocate structures for number of NFS directories found */
for (i = 0; i < 2; i++) {
if ((st_ionfs[i] =
for (i = 0; i < 2; i++) {
free(st_ionfs[i]);
}
-
+
free(st_hdr_ionfs);
}
/* Don't buffer data if redirected to a pipe */
setbuf(stdout, NULL);
-
+
do {
if (cpu_nr > 1) {
/*
/* Display an easy-to-read NFS report */
flags |= I_D_HUMAN_READ;
break;
-
+
case 'k':
if (DISPLAY_MEGABYTES(flags)) {
usage(argv[0]);
/* Print version number and exit */
print_version();
break;
-
+
default:
usage(argv[0]);
}
void sfree_pid(void)
{
int i;
-
+
for (i = 0; i < 3; i++) {
free(st_pid_list[i]);
}
void print_comm(struct pid_stats *pst)
{
char *p;
-
+
if (DISPLAY_CMDLINE(pidflag) && strlen(pst->cmdline)) {
p = pst->cmdline;
}
return 1;
memset(line, 0, MAX_CMDLINE_LEN);
-
+
if ((len = fread(line, 1, MAX_CMDLINE_LEN - 1, fp)) < 0) {
/* Nothing to read doesn't mean that process no longer exists */
fclose(fp);
return 1;
}
-
+
for (i = 0; i < len; i++) {
if (line[i] == '\0') {
line[i] = ' ';
pst->flags |= F_NO_PID_FD;
return 0;
}
-
+
pst->fd_nr = 0;
/* Count number of entries if fd directory */
if (read_proc_pid_cmdline(pid, pst, tgid))
return 1;
}
-
+
if (read_proc_pid_status(pid, pst, tgid))
return 1;
if (read_proc_pid_smap(pid, pst, tgid))
return 1;
}
-
+
if (DISPLAY_KTAB(actflag)) {
if (read_proc_pid_fd(pid, pst, tgid))
return 1;
if (drp) {
pst = st_pid_list[curr] + p++;
pid = atoi(drp->d_name);
-
+
if (read_pid_stats(pid, pst, &thr_nr, 0)) {
/* Process has terminated */
pst->pid = 0;
}
-
+
else if (DISPLAY_TID(pidflag)) {
/* Read stats for threads in task subdirectory */
read_task_stats(curr, pid, &p);
if (p >= pid_nr)
break;
pst = st_pid_list[curr] + p++;
-
+
if (pid_array[op]) {
/* PID should still exist. So read its stats */
if (read_pid_stats(pid_array[op], pst, &thr_nr, 0)) {
pst = st_pid_list[curr] + q;
pst->pid = 0;
}
-
+
}
/* else unknown command */
}
/* Look for previous stats for same PID */
q = p;
-
+
do {
*pstp = st_pid_list[prev] + q;
if (((*pstp)->pid == (*pstc)->pid) &&
if (DISPLAY_ACTIVE_PID(pidflag)) {
int isActive = FALSE;
-
+
/* Check that it's an "active" process */
if (DISPLAY_CPU(activity)) {
/* User time already includes guest time */
}
}
}
-
+
if (DISPLAY_MEM(activity) && (!isActive)) {
if (((*pstc)->minflt != (*pstp)->minflt) ||
((*pstc)->majflt != (*pstp)->majflt)) {
isActive = TRUE;
}
}
-
+
if (DISPLAY_KTAB(activity) && (!isActive) &&
/* /proc/#/fd directory should be readable */
!(NO_PID_FD((*pstc)->flags))) {
isActive = TRUE;
}
}
-
+
/* If PID isn't active for any of the activities then return */
if (!isActive)
return -1;
}
}
-
+
else if (DISPLAY_PID(pidflag)) {
*pstp = st_pid_list[prev] + p;
if (!(*pstp)->pid) {
if (regcomp(®ex, commstr, REG_EXTENDED | REG_NOSUB) != 0)
/* Error in preparing regex structure */
return -1;
-
+
rc = regexec(®ex, (*pstc)->comm, 0, NULL, 0);
regfree(®ex);
/* regex pattern not found in command name */
return -1;
}
-
+
if (USER_STRING(pidflag)) {
if ((pwdent = getpwuid((*pstc)->uid)) != NULL) {
if (strcmp(pwdent->pw_name, userstr))
else {
printf(" %5d", pst->uid);
}
-
+
if (DISPLAY_TID(pidflag)) {
-
+
if (pst->tgid) {
/* This is a TID */
sprintf(format, " %c %%9u", c);
void print_line_id(char *timestamp, struct pid_stats *pst)
{
printf("%-11s", timestamp);
-
+
__print_line_id(pst, '-');
}
printf(" %7u", pstc->fd_nr);
}
}
-
+
print_comm(pstc);
again = 1;
}
}
for (p = 0; p < pid_nr; p++) {
-
+
if (get_pid_to_display(prev, curr, p, P_A_CPU, P_TASK,
&pstc, &pstp) <= 0)
continue;
-
+
print_line_id(curr_string, pstc);
printf(" %7.2f %7.2f %7.2f %7.2f",
(pstc->utime - pstc->gtime) < (pstp->utime - pstp->gtime) ?
}
for (p = 0; p < pid_nr; p++) {
-
+
if ((rc = get_pid_to_display(prev, curr, p, P_A_CPU, P_CHILD,
&pstc, &pstp)) == 0)
/* PID no longer exists */
continue;
-
+
/* This will be used to compute average */
if (!disp_avg) {
pstc->uc_asum_count = pstp->uc_asum_count + 1;
}
-
+
if (rc < 0)
/* PID should not be displayed */
continue;
print_comm(pstc);
again = 1;
}
-
+
return again;
}
PRINT_ID_HDR(prev_string, pidflag);
printf(" minflt/s majflt/s VSZ RSS %%MEM Command\n");
}
-
+
for (p = 0; p < pid_nr; p++) {
-
+
if ((rc = get_pid_to_display(prev, curr, p, P_A_MEM, P_TASK,
&pstc, &pstp)) == 0)
/* PID no longer exists */
continue;
-
+
/* This will be used to compute average */
if (!disp_avg) {
pstc->total_vsz = pstp->total_vsz + pstc->vsz;
continue;
print_line_id(curr_string, pstc);
-
+
printf(" %9.2f %9.2f ",
S_VALUE(pstp->minflt, pstc->minflt, itv),
S_VALUE(pstp->majflt, pstc->majflt, itv));
pstc->rss,
tlmkb ? SP_VALUE(0, pstc->rss, tlmkb) : 0.0);
}
-
+
print_comm(pstc);
again = 1;
}
PRINT_ID_HDR(prev_string, pidflag);
printf(" minflt-nr majflt-nr Command\n");
}
-
+
for (p = 0; p < pid_nr; p++) {
-
+
if ((rc = get_pid_to_display(prev, curr, p, P_A_MEM, P_CHILD,
&pstc, &pstp)) == 0)
/* PID no longer exists */
if (!disp_avg) {
pstc->rc_asum_count = pstp->rc_asum_count + 1;
}
-
+
if (rc < 0)
/* PID should not be displayed */
continue;
PRINT_ID_HDR(prev_string, pidflag);
printf(" StkSize StkRef Command\n");
}
-
+
for (p = 0; p < pid_nr; p++) {
-
+
if ((rc = get_pid_to_display(prev, curr, p, P_A_STACK, P_NULL,
&pstc, &pstp)) == 0)
/* PID no longer exists */
continue;
-
+
/* This will be used to compute average */
if (!disp_avg) {
pstc->total_stack_size = pstp->total_stack_size + pstc->stack_size;
continue;
print_line_id(curr_string, pstc);
-
+
if (disp_avg) {
printf(" %7.0f %7.0f",
(double) pstc->total_stack_size / pstc->sk_asum_count,
&pstc, &pstp)) == 0)
/* PID no longer exists */
continue;
-
+
/* This will be used to compute average delays */
if (!disp_avg) {
pstc->delay_asum_count = pstp->delay_asum_count + 1;
}
-
+
if (rc < 0)
/* PID should not be displayed */
continue;
-
+
print_line_id(curr_string, pstc);
if (!NO_PID_IO(pstc->flags)) {
printf(" %9.2f %9.2f %9.2f",
else {
printf(" %7llu", pstc->blkio_swapin_delays - pstp->blkio_swapin_delays);
}
-
+
print_comm(pstc);
again = 1;
}
}
for (p = 0; p < pid_nr; p++) {
-
+
if (get_pid_to_display(prev, curr, p, P_A_CTXSW, P_NULL,
&pstc, &pstp) <= 0)
continue;
-
+
print_line_id(curr_string, pstc);
printf(" %9.2f %9.2f",
S_VALUE(pstp->nvcsw, pstc->nvcsw, itv),
printf(" threads fd-nr");
printf(" Command\n");
}
-
+
for (p = 0; p < pid_nr; p++) {
-
+
if ((rc = get_pid_to_display(prev, curr, p, P_A_KTAB, P_NULL,
&pstc, &pstp)) == 0)
/* PID no longer exists */
continue;
-
+
/* This will be used to compute average */
if (!disp_avg) {
pstc->total_threads = pstp->total_threads + pstc->threads;
/* Don't buffer data if redirected to a pipe */
setbuf(stdout, NULL);
-
+
if (cpu_nr > 1) {
/*
* Read system uptime (only for SMP machines).
if (sigint_caught)
/* SIGINT signal caught during first interval: Exit immediately */
return;
-
+
do {
/* Get time */
get_localtime(&ps_tstamp[curr], 0);
}
if (count) {
-
+
pause();
-
+
if (sigint_caught) {
/* SIGINT signal caught => Display average stats */
count = 0;
/* Init National Language Support */
init_nls();
#endif
-
+
/* Get HZ */
get_HZ();
/* Compute page shift in kB */
get_kb_shift();
-
+
/* Allocate structures for device list */
if (argc > 1) {
salloc_pid_array((argc / 2) + count_csvalues(argc, argv));
usage(argv[0]);
}
}
-
+
/* Option used individually. See below for grouped option */
else if (!strcmp(argv[opt], "-U")) {
/* Display username instead of UID */
actflag |= P_A_IO;
dis_hdr++;
break;
-
+
case 'h':
/* Display stats on one line */
pidflag |= P_D_ONELINE;
/* IRIX mode off */
pidflag |= P_F_IRIX_MODE;
break;
-
+
case 'l':
/* Display whole command line */
pidflag |= P_D_CMDLINE;
break;
-
+
case 'r':
/* Display memory usage */
actflag |= P_A_MEM;
dis_hdr++;
break;
-
+
case 's':
/* Display stack sizes */
actflag |= P_A_STACK;
dis_hdr++;
break;
-
+
case 't':
/* Display stats for threads */
pidflag |= P_D_TID;
/* When option is grouped, it cannot take an arg */
pidflag |= P_D_USERNAME;
break;
-
+
case 'u':
/* Display CPU usage */
actflag |= P_A_CPU;
actflag |= P_A_CTXSW;
dis_hdr++;
break;
-
+
default:
usage(argv[0]);
}
/* Main loop */
rw_pidstat_loop(dis_hdr, rows);
-
+
/* Free structures */
free(pid_array);
sfree_pid();
timestamp[!curr]);
}
}
-
+
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
-
+
/*
* The size of a->buf[...] CPU structure may be different from the default
* sizeof(struct stats_cpu) value if data have been read from a file!
* used by sadc to create a file, and the version of sysstat
* used by sar to read it...
*/
-
+
/* Should current CPU (including CPU "all") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
/* Yes: Display it */
printf("%-11s", timestamp[curr]);
-
+
if (!i) {
/* This is CPU "all" */
printf(" all");
* jump from zero when the CPU comes back online.
*/
*scc = *scp;
-
+
/* %user, %nice, %system, %iowait, %steal, ..., %idle */
printf(" %6.2f %6.2f %6.2f"
" %6.2f %6.2f %6.2f",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-
+
if (DISPLAY_CPU_ALL(a->opt_flags)) {
/*
* Four additional fields to display:
printf("\n");
continue;
}
-
+
/* Recalculate interval for current proc */
g_itv = get_per_cpu_interval(scc, scp);
-
+
if (!g_itv) {
/*
* If the CPU is tickless then there is no change in CPU values
continue;
}
}
-
+
if (DISPLAY_CPU_DEF(a->opt_flags)) {
printf(" %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
struct stats_pcsw
*spc = (struct stats_pcsw *) a->buf[curr],
*spp = (struct stats_pcsw *) a->buf[prev];
-
+
if (dis) {
printf("\n%-11s proc/s cswch/s\n", timestamp[!curr]);
}
{
int i;
struct stats_irq *sic, *sip;
-
+
if (dis) {
printf("\n%-11s INTR intr/s\n", timestamp[!curr]);
}
-
+
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
sic = (struct stats_irq *) ((char *) a->buf[curr] + i * a->msize);
sip = (struct stats_irq *) ((char *) a->buf[prev] + i * a->msize);
-
+
/*
* Note: a->nr is in [0, NR_IRQS + 1].
* Bitmap size is provided for (NR_IRQS + 1) interrupts.
* used by sadc to create a file, and the version of sysstat
* used by sar to read it...
*/
-
+
/* Should current interrupt (including int "sum") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
/* Yes: Display it */
printf("%-11s", timestamp[curr]);
if (!i) {
struct stats_swap
*ssc = (struct stats_swap *) a->buf[curr],
*ssp = (struct stats_swap *) a->buf[prev];
-
+
if (dis) {
printf("\n%-11s pswpin/s pswpout/s\n", timestamp[!curr]);
}
avg_frskb = 0,
avg_tlskb = 0,
avg_caskb = 0;
-
+
if (DISPLAY_MEMORY(a->opt_flags)) {
if (dis) {
printf("\n%-11s frmpg/s bufpg/s campg/s\n",
S_VALUE((double) KB_TO_PG(smp->bufkb), (double) KB_TO_PG(smc->bufkb), itv),
S_VALUE((double) KB_TO_PG(smp->camkb), (double) KB_TO_PG(smc->camkb), itv));
}
-
+
if (DISPLAY_MEM_AMT(a->opt_flags)) {
if (dis) {
printf("\n%-11s kbmemfree kbmemused %%memused kbbuffers kbcached"
(double) avg_activekb / avg_count,
(double) avg_inactkb / avg_count,
(double) avg_dirtykb / avg_count);
-
+
/* Reset average counters */
avg_frmkb = avg_bufkb = avg_camkb = avg_comkb = 0;
avg_activekb = avg_inactkb = avg_dirtykb = 0;
}
}
-
+
if (DISPLAY_SWAP(a->opt_flags)) {
if (dis) {
printf("\n%-11s kbswpfree kbswpused %%swpused kbswpcad %%swpcad\n",
((double) avg_tlskb / avg_count) -
((double) avg_frskb / avg_count)) :
0.0);
-
+
/* Reset average counters */
avg_frskb = avg_tlskb = avg_caskb = 0;
}
avg_file_used = 0,
avg_inode_used = 0,
avg_pty_nr = 0;
-
-
+
+
if (dis) {
printf("\n%-11s dentunusd file-nr inode-nr pty-nr\n",
timestamp[!curr]);
avg_load_avg_5 = 0,
avg_load_avg_15 = 0,
avg_procs_blocked = 0;
-
+
if (dis) {
printf("\n%-11s runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked\n",
timestamp[!curr]);
/* Compute service time, etc. */
compute_ext_disk_stats(sdc, sdp, itv, &xds);
-
+
dev_name = NULL;
persist_dev_name = NULL;
if (DISPLAY_PERSIST_NAME_S(flags)) {
persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
}
-
+
if (persist_dev_name) {
dev_name = persist_dev_name;
}
USE_PRETTY_OPTION(flags));
}
}
-
+
printf("%-11s %9s %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n",
timestamp[curr],
/* Confusion possible here between index and minor numbers */
if (!strcmp(sndc->interface, ""))
continue;
-
+
j = check_net_dev_reg(a, curr, prev, i);
sndp = (struct stats_net_dev *) ((char *) a->buf[prev] + j * a->msize);
rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
txkb = S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv);
-
+
printf(" %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f",
S_VALUE(sndp->rx_packets, sndc->rx_packets, itv),
S_VALUE(sndp->tx_packets, sndc->tx_packets, itv),
S_VALUE(sndp->rx_compressed, sndc->rx_compressed, itv),
S_VALUE(sndp->tx_compressed, sndc->tx_compressed, itv),
S_VALUE(sndp->multicast, sndc->multicast, itv));
-
+
ifutil = compute_ifutil(sndc, rxkb, txkb);
printf(" %6.2f\n", ifutil);
}
if (!strcmp(snedc->interface, ""))
continue;
-
+
j = check_net_edev_reg(a, curr, prev, i);
snedp = (struct stats_net_edev *) ((char *) a->buf[prev] + j * a->msize);
struct stats_net_nfs
*snnc = (struct stats_net_nfs *) a->buf[curr],
*snnp = (struct stats_net_nfs *) a->buf[prev];
-
+
if (dis) {
printf("\n%-11s call/s retrans/s read/s write/s access/s"
" getatt/s\n", timestamp[!curr]);
avg_raw_inuse = 0,
avg_frag_inuse = 0,
avg_tcp_tw = 0;
-
+
if (dis) {
printf("\n%-11s totsck tcpsck udpsck rawsck ip-frag tcp-tw\n",
timestamp[!curr]);
avg_udp6_inuse = 0,
avg_raw6_inuse = 0,
avg_frag6_inuse = 0;
-
+
if (dis) {
printf("\n%-11s tcp6sck udp6sck raw6sck ip6-frag\n",
timestamp[!curr]);
struct stats_pwr_cpufreq *spc;
static unsigned long long
*avg_cpufreq = NULL;
-
+
if (!avg_cpufreq) {
/* Allocate array of CPU frequency */
if ((avg_cpufreq = (unsigned long long *) malloc(sizeof(unsigned long long) * a->nr))
}
memset(avg_cpufreq, 0, sizeof(unsigned long long) * a->nr);
}
-
+
if (dis) {
printf("\n%-11s CPU MHz\n",
timestamp[!curr]);
}
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
-
+
/*
* The size of a->buf[...] CPU structure may be different from the default
* sizeof(struct stats_pwr_cpufreq) value if data have been read from a file!
* used by sadc to create a file, and the version of sysstat
* used by sar to read it...
*/
-
+
/* Should current CPU (including CPU "all") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
/* Yes: Display it */
printf("%-11s", timestamp[curr]);
-
+
if (!i) {
/* This is CPU "all" */
printf(" all");
else {
printf(" %3d", i - 1);
}
-
+
if (!dispavg) {
/* Display instantaneous values */
printf(" %9.2f\n",
else {
/* Display average values */
printf(" %9.2f\n",
- (double) avg_cpufreq[i] / (100 * avg_count));
+ (double) avg_cpufreq[i] / (100 * avg_count));
}
}
}
-
+
if (dispavg) {
/* Array of CPU frequency no longer needed: Free it! */
if (avg_cpufreq) {
avg_temp_min[i] = spc->temp_min;
avg_temp_max[i] = spc->temp_max;
}
-
+
printf(" %*s\n", MAX_SENSORS_DEV_LEN, spc->device);
}
printf(" %*s", MAX_MANUF_LEN - 1, "manufact");
printf(" %*s\n", MAX_PROD_LEN - 1, "product");
}
-
+
for (i = 0; i < a->nr; i++) {
suc = (struct stats_pwr_usb *) ((char *) a->buf[curr] + i * a->msize);
if (!suc->bus_nr)
/* Bus#0 doesn't exist: We are at the end of the list */
break;
-
+
printf("%-11s %6d %9x %9x %9u",
(dispavg ? _("Summary") : timestamp[curr]),
suc->bus_nr,
}
}
}
-}
+}
/*
***************************************************************************
int i, j;
struct stats_filesystem *sfc, *sfm;
-
+
if (dis) {
printf("\n%-11s MBfsfree MBfsused %%fsused %%ufsused"
" Ifree Iused %%Iused FILESYSTEM\n",
for (i = 0; i < a->nr; i++) {
sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize);
-
+
if (!sfc->f_blocks)
/* Size of filesystem is null: We are at the end of the list */
break;
-
+
printf("%-11s %9.0f %9.0f %6.2f %6.2f"
" %9llu %9llu %6.2f %s\n",
(dispavg ? _("Summary") : timestamp[curr]),
sfc->f_files ? SP_VALUE(sfc->f_ffree, sfc->f_files, sfc->f_files)
: 0.0,
sfc->fs_name);
-
+
if (!dispavg) {
/* Save current filesystem in summary list */
for (j = 0; j < a->nr; j++) {
sfm = (struct stats_filesystem *) ((char *) a->buf[2] + j * a->msize);
-
+
if (!strcmp(sfm->fs_name, sfc->fs_name) ||
!sfm->f_blocks) {
/*
j = 0;
st_pwr_fan_i = st_pwr_fan + count;
sensors_snprintf_chip_name(st_pwr_fan_i->device, MAX_SENSORS_DEV_LEN, chip);
-
+
while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
if ((sub->type == SENSORS_SUBFEATURE_FAN_INPUT) &&
(sub->flags & SENSORS_MODE_R)) {
j = 0;
st_pwr_temp_i = st_pwr_temp + count;
sensors_snprintf_chip_name(st_pwr_temp_i->device, MAX_SENSORS_DEV_LEN, chip);
-
+
while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
if ((sub->type == SENSORS_SUBFEATURE_TEMP_INPUT) &&
(sub->flags & SENSORS_MODE_R)) {
if ((fp = fopen(STAT, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "intr ", 5)) {
{
FILE *fp;
char line[128];
-
+
if ((fp = fopen(MEMINFO, "r")) == NULL)
return;
{
int i = 0;
int j, len;
-
+
len = strlen(str);
-
+
while (i < len - 3) {
if ((str[i] == '\\') &&
(str[i + 1] >= '0') && (str[i + 1] <= '3') &&
if ((fp = fopen(LOADAVG, "r")) == NULL)
return;
-
+
/* Read load averages and queue length */
fscanf(fp, "%d.%d %d.%d %d.%d %ld/%d %*d\n",
&load_tmp[0], &st_queue->load_avg_1,
sscanf(line + 8, "%lu", &st_swap->pswpout);
}
}
-
+
fclose(fp);
}
st_paging->pgscan_direct += pgtmp;
}
}
-
+
fclose(fp);
}
if (sscanf(line, "%u %u %s %lu %*u %lu %*u %lu %*u %lu",
&major, &minor, dev_name,
&rd_ios, &rd_sec, &wr_ios, &wr_sec) == 7) {
-
+
if (is_device(dev_name, IGNORE_VIRTUAL_DEVICES)) {
/*
* OK: It's a (real) device and not a partition.
}
}
}
-
+
fclose(fp);
}
&major, &minor, dev_name,
&rd_ios, &rd_sec, &rd_ticks, &wr_ios, &wr_sec, &wr_ticks,
&tot_ticks, &rq_ticks) == 11) {
-
+
if (!rd_ios && !wr_ios)
/* Unused device: Ignore it */
continue;
if ((p = strstr(line, "oe:")) != NULL) {
sscanf(p + 3, "%u", &st_serial_i->overrun);
}
-
+
sl++;
}
}
{
FILE *fp;
unsigned int parm;
-
+
/* Open /proc/sys/fs/dentry-state file */
if ((fp = fopen(FDENTRY_STATE, "r")) != NULL) {
fscanf(fp, "%*d %u",
if ((fp = fopen(NET_DEV, "r")) == NULL)
return 0;
-
+
while ((fgets(line, sizeof(line), fp) != NULL) && (dev < nbr)) {
pos = strcspn(line, ":");
}
fclose(fp);
-
+
return dev;
}
struct stats_net_dev *st_net_dev_i;
char filename[128], duplex[32];
int dev, n;
-
+
for (dev = 0; dev < nbr; dev++) {
-
+
st_net_dev_i = st_net_dev + dev;
-
+
/* Read speed info */
sprintf(filename, IF_DUPLEX, st_net_dev_i->interface);
-
+
if ((fp = fopen(filename, "r")) == NULL)
/* Cannot read NIC duplex */
continue;
-
+
n = fscanf(fp, "%s", duplex);
-
+
fclose(fp);
-
+
if (n != 1)
/* Cannot read NIC duplex */
continue;
-
+
if (!strcmp(duplex, K_DUPLEX_FULL)) {
st_net_dev_i->duplex = C_DUPLEX_FULL;
}
}
else
continue;
-
+
/* Read speed info */
sprintf(filename, IF_SPEED, st_net_dev_i->interface);
-
+
if ((fp = fopen(filename, "r")) == NULL)
/* Cannot read NIC speed */
continue;
-
+
fscanf(fp, "%u", &st_net_dev_i->speed);
-
+
fclose(fp);
}
}
return;
memset(st_net_nfs, 0, STATS_NET_NFS_SIZE);
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "rpc ", 4)) {
else if (!strncmp(line, "proc3 ", 6)) {
sscanf(line + 6, "%*u %*u %u %*u %*u %u %*u %u %u",
&getattcnt, &accesscnt, &readcnt, &writecnt);
-
+
st_net_nfs->nfs_getattcnt += getattcnt;
st_net_nfs->nfs_accesscnt += accesscnt;
st_net_nfs->nfs_readcnt += readcnt;
sscanf(line + 6, "%*u %*u %u %u "
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %u %u",
&readcnt, &writecnt, &accesscnt, &getattcnt);
-
+
st_net_nfs->nfs_getattcnt += getattcnt;
st_net_nfs->nfs_accesscnt += accesscnt;
st_net_nfs->nfs_readcnt += readcnt;
if ((fp = fopen(NET_RPC_NFSD, "r")) == NULL)
return;
-
+
memset(st_net_nfsd, 0, STATS_NET_NFSD_SIZE);
while (fgets(line, sizeof(line), fp) != NULL) {
st_net_nfsd->nfsd_accesscnt += accesscnt;
st_net_nfsd->nfsd_readcnt += readcnt;
st_net_nfsd->nfsd_writecnt += writecnt;
-
+
}
else if (!strncmp(line, "proc4ops ", 9)) {
sscanf(line + 9, "%*u %*u %*u %*u %u "
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %u "
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %u",
&accesscnt, &getattcnt, &readcnt, &writecnt);
-
+
st_net_nfsd->nfsd_getattcnt += getattcnt;
st_net_nfsd->nfsd_accesscnt += accesscnt;
st_net_nfsd->nfsd_readcnt += readcnt;
if ((fp = fopen(NET_SOCKSTAT, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "sockets:", 8)) {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Ip:", 3)) {
&st_net_ip->ReasmOKs,
&st_net_ip->FragOKs,
&st_net_ip->FragCreates);
-
+
break;
}
else {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Ip:", 3)) {
&st_net_eip->OutNoRoutes,
&st_net_eip->ReasmFails,
&st_net_eip->FragFails);
-
+
break;
}
else {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Icmp:", 5)) {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Icmp:", 5)) {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Tcp:", 4)) {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Tcp:", 4)) {
if ((fp = fopen(NET_SNMP, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "Udp:", 4)) {
if ((fp = fopen(NET_SOCKSTAT6, "r")) == NULL)
return;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
if (!strncmp(line, "TCP6:", 5)) {
sscanf(line + 15, "%llu", &st_net_ip6->FragCreates6);
}
}
-
+
fclose(fp);
}
sscanf(line + 19, "%llu", &st_net_eip6->InTruncatedPkts6);
}
}
-
+
fclose(fp);
}
sscanf(line + 31, "%lu", &st_net_icmp6->OutNeighborAdvertisements6);
}
}
-
+
fclose(fp);
}
sscanf(line + 19, "%lu", &st_net_eicmp6->OutPktTooBigs6);
}
}
-
+
fclose(fp);
}
sscanf(line + 13, "%lu", &st_net_udp6->InErrors6);
}
}
-
+
fclose(fp);
}
char line[1024];
int proc_nb = 0, nr = 0;
unsigned int ifreq, dfreq;
-
+
if ((fp = fopen(CPUINFO, "r")) == NULL)
return;
-
+
st_pwr_cpufreq->cpufreq = 0;
-
+
while (fgets(line, sizeof(line), fp) != NULL) {
-
+
if (!strncmp(line, "processor\t", 10)) {
sscanf(strchr(line, ':') + 1, "%d", &proc_nb);
}
-
+
else if (!strncmp(line, "cpu MHz\t", 8)) {
sscanf(strchr(line, ':') + 1, "%u.%u", &ifreq, &dfreq);
-
+
if (proc_nb < (nbr - 1)) {
/* Save current CPU frequency */
st_pwr_cpufreq_i = st_pwr_cpufreq + proc_nb + 1;
st_pwr_cpufreq_i->cpufreq = ifreq * 100 + dfreq / 10;
-
+
/* Also save it to compute an average CPU frequency */
st_pwr_cpufreq->cpufreq += st_pwr_cpufreq_i->cpufreq;
nr++;
}
}
}
-
+
fclose(fp);
-
+
if (nr) {
/* Compute average CPU frequency for this machine */
st_pwr_cpufreq->cpufreq /= nr;
&st_pwr_usb->product_id);
fclose(fp);
}
-
+
/* Read USB device max power consumption */
snprintf(filename, MAX_PF_NAME, "%s/%s/%s",
SYSFS_USBDEV, usb_device, SYSFS_BMAXPOWER);
while ((fgets(line, sizeof(line), fp) != NULL) && (fs < nbr)) {
if (line[0] == '/') {
-
+
/* Read current filesystem name and mount point */
sscanf(line, "%71s %127s", fs_name, mountp);
-
+
/* Replace octal codes */
oct2chr(mountp);
-
+
if ((statfs(mountp, &buf) < 0) || (!buf.f_blocks))
continue;
-
+
st_filesystem_i = st_filesystem + fs++;
st_filesystem_i->f_blocks = buf.f_blocks * buf.f_bsize;
st_filesystem_i->f_bfree = buf.f_bfree * buf.f_bsize;
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
-
+
scc = (struct stats_cpu *) ((char *) a->buf[curr] + i * a->msize);
scp = (struct stats_cpu *) ((char *) a->buf[!curr] + i * a->msize);
/* Should current CPU (including CPU "all") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
if (!i) {
/* This is CPU "all" */
if (DISPLAY_CPU_DEF(a->opt_flags)) {
g_itv),
NULL);
}
-
+
if (DISPLAY_CPU_DEF(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"all\t%%nice", NULL, NULL,
scc->cpu_nice - scc->cpu_guest_nice,
g_itv),
NULL);
- }
+ }
if (DISPLAY_CPU_DEF(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
NULL);
}
-
+
render(isdb, pre, PT_NOFLAG,
"all\t%%iowait", NULL, NULL,
NOVAL,
* jump from zero when the CPU comes back online.
*/
*scc = *scp;
-
+
g_itv = 0;
cpu_offline = TRUE;
}
scc->cpu_user - scc->cpu_guest, g_itv),
NULL);
}
-
+
if (DISPLAY_CPU_DEF(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%nice", NULL, cons(iv, i - 1, NOVAL),
ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
NULL);
}
-
+
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%iowait", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
0.0 :
ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"cpu%d\t%%guest", NULL, cons(iv, i - 1, NOVAL),
NOVAL,
ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
NULL);
}
-
+
if (!g_itv) {
/* CPU is offline or tickless */
render(isdb, pre, pt_newlin,
*spp = (struct stats_pcsw *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
/* The first one as an example */
render(isdb, /* db/ppc flag */
pre, /* the preformatted line leader */
struct stats_irq *sic, *sip;
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
sic = (struct stats_irq *) ((char *) a->buf[curr] + i * a->msize);
sip = (struct stats_irq *) ((char *) a->buf[!curr] + i * a->msize);
-
+
/* Should current interrupt (including int "sum") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
/* Yes: Display it */
if (!i) {
/* This is interrupt "sum" */
*ssp = (struct stats_swap *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tpswpin/s", NULL, NULL,
NOVAL,
*smp = (struct stats_memory *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
if (DISPLAY_MEMORY(a->opt_flags)) {
render(isdb, pre, PT_NOFLAG,
"-\tkbdirty", NULL, NULL,
smc->dirtykb, DNOVAL, NULL);
}
-
+
if (DISPLAY_SWAP(a->opt_flags)) {
render(isdb, pre, PT_USEINT,
*skc = (struct stats_ktables *) a->buf[curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_USEINT,
"-\tdentunusd", NULL, NULL,
skc->dentry_stat, DNOVAL, NULL);
*sqc = (struct stats_queue *) a->buf[curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_USEINT,
"-\trunq-sz", NULL, NULL,
sqc->nr_running, DNOVAL, NULL);
NOVAL,
(double) sqc->load_avg_15 / 100,
NULL);
-
+
render(isdb, pre, PT_USEINT | pt_newlin,
"-\tblocked", NULL, NULL,
sqc->procs_blocked, DNOVAL, NULL);
j = check_disk_reg(a, curr, !curr, i);
sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize);
-
+
/* Compute extended stats (service time, etc.) */
compute_ext_disk_stats(sdc, sdp, itv, &xds);
if (DISPLAY_PERSIST_NAME_S(flags)) {
persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
}
-
+
if (persist_dev_name) {
dev_name = persist_dev_name;
}
if (!strcmp(sndc->interface, ""))
continue;
-
+
j = check_net_dev_reg(a, curr, !curr, i);
sndp = (struct stats_net_dev *) ((char *) a->buf[!curr] + j * a->msize);
NOVAL,
S_VALUE(sndp->multicast, sndc->multicast, itv),
NULL);
-
+
ifutil = compute_ifutil(sndc, rxkb, txkb);
render(isdb, pre, pt_newlin,
"%s\t%%ifutil", NULL,
if (!strcmp(snedc->interface, ""))
continue;
-
+
j = check_net_edev_reg(a, curr, !curr, i);
snedp = (struct stats_net_edev *) ((char *) a->buf[!curr] + j * a->msize);
*snnp = (struct stats_net_nfs *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tcall/s", NULL, NULL,
NOVAL,
*snip = (struct stats_net_ip *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tirec/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->ReasmOKs, snic->ReasmOKs, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tfragok/s", NULL, NULL,
NOVAL,
*sneip = (struct stats_net_eip *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tihdrerr/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(sneip->OutNoRoutes, sneic->OutNoRoutes, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tasmf/s", NULL, NULL,
NOVAL,
*snip = (struct stats_net_icmp *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\timsg/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->OutMsgs, snic->OutMsgs, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tiech/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->InTimestamps, snic->InTimestamps, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\titmr/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->OutTimestamps, snic->OutTimestamps, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\totmr/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->InAddrMasks, snic->InAddrMasks, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tiadrmkr/s", NULL, NULL,
NOVAL,
S_VALUE(snip->InAddrMaskReps, snic->InAddrMaskReps, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\toadrmk/s", NULL, NULL,
NOVAL,
S_VALUE(snip->OutAddrMasks, snic->OutAddrMasks, itv),
NULL);
-
+
render(isdb, pre, pt_newlin,
"-\toadrmkr/s", NULL, NULL,
NOVAL,
*sneip = (struct stats_net_eicmp *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tierr/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(sneip->OutErrors, sneic->OutErrors, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tidstunr/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(sneip->InParmProbs, sneic->InParmProbs, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\toparmpb/s", NULL, NULL,
NOVAL,
*sntp = (struct stats_net_tcp *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tactive/s", NULL, NULL,
NOVAL,
*snetp = (struct stats_net_etcp *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tatmptf/s", NULL, NULL,
NOVAL,
S_VALUE(snetp->AttemptFails, snetc->AttemptFails, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\testres/s", NULL, NULL,
NOVAL,
S_VALUE(snetp->EstabResets, snetc->EstabResets, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tretrans/s", NULL, NULL,
NOVAL,
*snup = (struct stats_net_udp *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tidgm/s", NULL, NULL,
NOVAL,
*snip = (struct stats_net_ip6 *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tirec6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->OutMcastPkts6, snic->OutMcastPkts6, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tfragok6/s", NULL, NULL,
NOVAL,
*sneip = (struct stats_net_eip6 *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tihdrer6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(sneip->OutNoRoutes6, sneic->OutNoRoutes6, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tasmf6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(sneip->FragFails6, sneic->FragFails6, itv),
NULL);
-
+
render(isdb, pre, pt_newlin,
"-\titrpck6/s", NULL, NULL,
NOVAL,
*snip = (struct stats_net_icmp6 *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\timsg6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->OutMsgs6, snic->OutMsgs6, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tiech6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->OutRouterSolicits6, snic->OutRouterSolicits6, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tirtad6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(snip->OutNeighborSolicits6, snic->OutNeighborSolicits6, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tinbad6/s", NULL, NULL,
NOVAL,
*sneip = (struct stats_net_eicmp6 *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tierr6/s", NULL, NULL,
NOVAL,
NOVAL,
S_VALUE(sneip->InParmProblems6, sneic->InParmProblems6, itv),
NULL);
-
+
render(isdb, pre, PT_NOFLAG,
"-\toprmpb6/s", NULL, NULL,
NOVAL,
*snup = (struct stats_net_udp6 *) a->buf[!curr];
int pt_newlin
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
-
+
render(isdb, pre, PT_NOFLAG,
"-\tidgm6/s", NULL, NULL,
NOVAL,
= (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
-
+
spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr] + i * a->msize);
/* Should current CPU (including CPU "all") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
-
+
if (!i) {
/* This is CPU "all" */
render(isdb, pre, pt_newlin,
(spc_k->time_in_state - spp_k->time_in_state);
tis += (spc_k->time_in_state - spp_k->time_in_state);
}
-
+
if (!i) {
/* This is CPU "all" */
render(isdb, pre, pt_newlin,
wrap_get_usb_nr(struct activity *);
extern __nr_t
wrap_get_filesystem_nr(struct activity *);
-
+
/* Functions used to read activities statistics */
extern __read_funct_t
wrap_read_stat_cpu(struct activity *);
name = get_devname_from_sysfs(major, minor);
if (name != NULL)
return (name);
-
+
name = ioc_name(major, minor);
if ((name != NULL) && strcmp(name, K_NODEV))
return (name);
(act[p]->nr < 1) || (act[p]->nr2 < 1)) {
PANIC(1);
}
-
+
memcpy(act[p]->buf[dest], act[p]->buf[src], act[p]->msize * act[p]->nr * act[p]->nr2);
}
}
/* Open sa data file */
if ((*ifd = open(dfile, O_RDONLY)) < 0) {
int saved_errno = errno;
-
+
fprintf(stderr, _("Cannot open %s: %s\n"), dfile, strerror(errno));
-
+
if ((saved_errno == ENOENT) && default_file_used) {
fprintf(stderr, _("Please check if data collecting is enabled\n"));
}
}
SREALLOC(buffer, char, file_magic->header_size);
-
+
/* Read sa data file standard header and allocate activity list */
sa_fread(*ifd, buffer, file_magic->header_size, HARD_SIZE);
memcpy(file_hdr, buffer, MINIMUM(file_magic->header_size, FILE_HEADER_SIZE));
free(buffer);
-
+
SREALLOC(*file_actlst, struct file_activity, FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
fal = *file_actlst;
if ((p = get_activity_position(act, fal->id)) < 0)
/* Unknown activity */
continue;
-
+
if (act[p]->magic != fal->magic) {
/* Bad magical number */
if (ignore) {
unsigned int act_id)
{
int j, p;
-
+
if ((p = get_activity_position(act, act_id)) < 0)
/* Ignore unknown activity */
return -1;
-
+
act[p]->nr = act_nr;
for (j = 0; j < 3; j++) {
SREALLOC(act[p]->buf[j], void, act[p]->msize * act[p]->nr * act[p]->nr2);
}
-
+
return 0;
}
struct file_activity file_act;
int item_nr = 0;
int i, rc;
-
+
for (i = 0; i < vol_act_nr; i++) {
-
+
sa_fread(ifd, &file_act, FILE_ACTIVITY_SIZE, HARD_SIZE);
-
+
if (file_act.id) {
rc = reallocate_vol_act_structures(act, file_act.nr, file_act.id);
if ((rc == 0) && !item_nr) {
}
/* else ignore empty structures that may exist */
}
-
+
if (!item_nr) {
/* All volatile activities structures cannot be empty */
handle_invalid_sa_file(&ifd, file_magic, file, 0);
case 'F':
SELECT_ACTIVITY(A_FILESYSTEM);
break;
-
+
case 'H':
p = get_activity_position(act, A_HUGE);
act[p]->options |= AO_SELECTED;
break;
-
+
case 'j':
if (argv[*opt + 1]) {
(*opt)++;
return 1;
}
break;
-
+
case 'p':
*flags |= S_F_DEV_PRETTY;
break;
double compute_ifutil(struct stats_net_dev *st_net_dev, double rx, double tx)
{
unsigned long long speed;
-
+
if (st_net_dev->speed) {
-
+
speed = st_net_dev->speed * 1000000;
-
+
if (st_net_dev->duplex == C_DUPLEX_FULL) {
/* Full duplex */
if (rx > tx) {
return ((rx + tx) * 800 / speed);
}
}
-
+
return 0;
}
{
struct stats_cpu *st_cpu
= (struct stats_cpu *) a->_buf0;
-
+
/* Read CPU statistics */
read_stat_cpu(st_cpu, a->nr, &record_hdr.uptime, &record_hdr.uptime0);
-
+
return;
}
/* Read process and context switch stats */
read_stat_pcsw(st_pcsw);
-
+
return;
}
/* Read interrupts stats */
read_stat_irq(st_irq, a->nr);
-
+
return;
}
/* Read queue and load stats */
read_loadavg(st_queue);
-
+
return;
}
/* Read memory stats */
read_meminfo(st_memory);
-
+
return;
}
/* Read stats from /proc/vmstat */
read_vmstat_swap(st_swap);
-
+
return;
}
/* Read stats from /proc/vmstat */
read_vmstat_paging(st_paging);
-
+
return;
}
/* Read serial lines stats */
read_tty_driver_serial(st_serial, a->nr);
-
+
return;
}
/* Read kernel tables stats */
read_kernel_tables(st_ktables);
-
+
return;
}
if (!dev)
/* No data read. Exit */
return;
-
+
/* Read duplex and speed info for each interface */
read_if_info(st_net_dev, dev);
-
+
return;
}
/* Read network interfaces errors stats */
read_net_edev(st_net_edev, a->nr);
-
+
return;
}
/* Read NFS client stats */
read_net_nfs(st_net_nfs);
-
+
return;
}
/* Read NFS server stats */
read_net_nfsd(st_net_nfsd);
-
+
return;
}
/* Read network sockets stats */
read_net_sock(st_net_sock);
-
+
return;
}
/* Read IP stats */
read_net_ip(st_net_ip);
-
+
return;
}
/* Read IP error stats */
read_net_eip(st_net_eip);
-
+
return;
}
/* Read ICMP stats */
read_net_icmp(st_net_icmp);
-
+
return;
}
/* Read ICMP error stats */
read_net_eicmp(st_net_eicmp);
-
+
return;
}
/* Read TCP stats */
read_net_tcp(st_net_tcp);
-
+
return;
}
/* Read TCP error stats */
read_net_etcp(st_net_etcp);
-
+
return;
}
/* Read UDP stats */
read_net_udp(st_net_udp);
-
+
return;
}
/* Read IPv6 network sockets stats */
read_net_sock6(st_net_sock6);
-
+
return;
}
/* Read IPv6 stats */
read_net_ip6(st_net_ip6);
-
+
return;
}
/* Read IPv6 error stats */
read_net_eip6(st_net_eip6);
-
+
return;
}
/* Read ICMPv6 stats */
read_net_icmp6(st_net_icmp6);
-
+
return;
}
/* Read ICMPv6 error stats */
read_net_eicmp6(st_net_eicmp6);
-
+
return;
}
/* Read UDPv6 stats */
read_net_udp6(st_net_udp6);
-
+
return;
}
/* Read CPU frequency stats */
read_cpuinfo(st_pwr_cpufreq, a->nr);
-
+
return;
}
if ((n = get_usb_nr()) >= 0)
/* Return a positive number even if no USB devices have been found */
return n + NR_USB_PREALLOC;
-
+
return 0;
}
/* sadc hasn't been called by sar */
exit(1);
}
-
+
/*
* When starting sar then pressing ctrl/c, SIGINT is received
* by sadc, not sar. So send SIGINT to sar so that average stats
act[i]->nr2 = (*act[i]->f_count2)(act[i]);
}
/* else act[i]->nr2 is a constant and doesn't need to be calculated */
-
+
if (!act[i]->nr2) {
act[i]->nr = 0;
}
memset(file_magic, 0, FILE_MAGIC_SIZE);
file_magic->header_size = FILE_HEADER_SIZE;
-
+
file_magic->sysstat_magic = SYSSTAT_MAGIC;
file_magic->format_magic = FORMAT_MAGIC;
file_magic->sysstat_extraversion = 0;
file_hdr.sa_month = rectime.tm_mon;
file_hdr.sa_year = rectime.tm_year;
file_hdr.sa_sizeof_long = sizeof(long);
-
+
/*
* This is a new file (or stdout): Field sa_last_cpu_nr is set to the number
* of CPU items of the machine (1 .. CPU_NR + 1).
if ((n = write_all(fd, &file_act, FILE_ACTIVITY_SIZE))
!= FILE_ACTIVITY_SIZE)
goto write_error;
-
+
/* Create sequence of volatile activities */
if (IS_VOLATILE(act[p]->options)) {
vol_id_seq[i] = act[p]->id;
{
struct file_activity file_act;
int i, p, n;
-
+
memset(&file_act, 0, FILE_ACTIVITY_SIZE);
for (i = 0; i < file_hdr.sa_vol_act_nr; i++) {
}
else {
p = get_activity_position(act, vol_id_seq[i]);
-
+
/*
* All the fields in file_activity structure are not used.
* In particular, act[p]->nr2 is left unmodified.
void rewrite_file_hdr(int *ofd, off_t fpos, struct file_magic *file_magic)
{
int n;
-
+
/* Remove O_APPEND status flag */
if (fcntl(*ofd, F_SETFL, 0) < 0) {
perror("fcntl");
exit(2);
}
-
+
/* Now rewrite file's header with its new CPU number value */
if (lseek(*ofd, fpos, SEEK_SET) < fpos) {
perror("lseek");
exit(2);
}
-
+
n = MINIMUM(file_magic->header_size, FILE_HEADER_SIZE);
if (write_all(*ofd, &file_hdr, n) != n) {
p_write_error();
}
-
+
/* Restore O_APPEND status flag */
if (fcntl(*ofd, F_SETFL, O_APPEND) < 0) {
perror("fcntl");
if (!ofile[0])
return;
-
+
/* Does file exist? */
if (access(ofile, F_OK) < 0) {
/* NO: Create it */
id_seq[i] = file_act[i].id;
act[p]->options |= AO_COLLECTED;
}
-
+
while (j < file_hdr.sa_vol_act_nr) {
vol_id_seq[j++] = 0;
}
char new_ofile[MAX_FILE_LEN];
new_ofile[0] = '\0';
-
+
/* Set a handler for SIGINT */
memset(&int_act, 0, sizeof(int_act));
int_act.sa_handler = (void *) int_handler;
/* Get HZ */
get_HZ();
-
+
/* Compute page shift in kB */
get_kb_shift();
fprintf(stderr, "sensors_init: %s\n", sensors_strerror(err));
}
#endif /* HAVE_SENSORS */
-
+
#ifdef USE_NLS
/* Init National Language Support */
init_nls();
else {
restart_mark = FALSE;
}
-
+
/*
* Open output file then STDOUT. Write header for each of them.
* NB: Output file must be opened first, because we may change
void init_structures(void)
{
int i;
-
+
for (i = 0; i < 3; i++) {
memset(&record_hdr[i], 0, RECORD_HEADER_SIZE);
}
/* Get format position in array */
f_position = get_format_position(fmt, format);
-
+
/* Check options consistency wrt output format */
if (!ACCEPT_HEADER_ONLY(fmt[f_position]->options)) {
/* Remove option -H */
if (ltm) {
*rectime = *ltm;
}
-
+
if (PRINT_TRUE_TIME(flags)) {
/* Option -t */
rectime->tm_hour = record_hdr[curr].hour;
unsigned int msk;
char *hl;
char hline[HEADER_LINE_LEN];
-
+
printf("# hostname;interval;timestamp");
-
+
for (i = 0; i < NR_ACT; i++) {
-
+
if ((act_id != ALL_ACTIVITIES) && (act[i]->id != act_id))
continue;
-
+
if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
if (!HAS_MULTIPLE_OUTPUTS(act[i]->options)) {
printf(";%s", act[i]->hdr_line);
int i;
char pre[80], temp[80]; /* Text at beginning of each line */
int isdb = (format == F_DB_OUTPUT);
-
+
/* This substring appears on every output line, preformat it here */
snprintf(pre, 80, "%s%s%ld%s",
file_hdr.sa_nodename, seps[isdb], dt, seps[isdb]);
}
for (i = 0; i < NR_ACT; i++) {
-
+
if ((act_id != ALL_ACTIVITIES) && (act[i]->id != act_id))
continue;
-
+
if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
(*act[i]->f_render)(act[i], isdb, pre, curr,
NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
/* JSON output */
if (CLOSE_MARKUP(act[i]->options) ||
(IS_SELECTED(act[i]->options) && (act[i]->nr > 0))) {
-
+
if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
printf(",");
/* Don't forget to read the volatile activities structures */
new_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic,
file_hdr.sa_vol_act_nr);
-
+
if (!dp)
return;
perror("lseek");
exit(2);
}
-
+
if (DISPLAY_FIELD_LIST(fmt[f_position]->options)) {
/* Print field list */
list_fields(act_id);
void sr_act_nr(__nr_t save_act_nr[], int action)
{
int i;
-
+
if (action == DO_SAVE) {
/* Save number of items for all activities */
for (i = 0; i < NR_ACT; i++) {
/* Read new CPU count */
new_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic,
file_hdr.sa_vol_act_nr);
-
+
/* Display RESTART records */
write_textual_restarts(0, tm_start.use, tm_end.use, tab,
rectime, loctime, new_cpu_nr);
int eosaf = TRUE, reset = FALSE;
long cnt = 1;
off_t fpos;
-
+
/* Read system statistics from file */
do {
/*
else {
/* For each requested activity... */
for (i = 0; i < NR_ACT; i++) {
-
+
if (!id_seq[i])
continue;
-
+
if ((p = get_activity_position(act, id_seq[i])) < 0) {
/* Should never happen */
PANIC(1);
}
else {
unsigned int optf, msk;
-
+
optf = act[p]->opt_flags;
-
+
for (msk = 1; msk < 0x10; msk <<= 1) {
if (act[p]->opt_flags & msk) {
act[p]->opt_flags &= msk;
-
+
rw_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf,
act[p]->id, &reset, file_actlst,
cpu_nr, rectime, loctime, file,
}
close(ifd);
-
+
free(file_actlst);
free_structures(act);
}
#endif
tm_start.use = tm_end.use = FALSE;
-
+
/* Allocate and init activity bitmaps */
allocate_bitmaps(act);
case 't':
flags |= S_F_TRUE_TIME;
break;
-
+
case 'U':
flags |= S_F_SEC_EPOCH;
break;
PRINT_SEC_EPOCH(flags)) > 1) {
usage(argv[0]);
}
-
+
/*
* Display all the contents of the daily data file if the count parameter
* was not set on the command line.
unsigned int cpu_nr)
{
static int sep = FALSE;
-
+
if (action & F_BEGIN) {
printf(",\n");
xprintf((*tab)++, "\"restarts\": [");
struct file_header *file_hdr)
{
static int sep = FALSE;
-
+
if (action & F_BEGIN) {
printf(",\n");
xprintf((*tab)++, "\"comments\": [");
__printf_funct_t print_json_statistics(int *tab, int action)
{
static int sep = FALSE;
-
+
if (action & F_BEGIN) {
printf(",\n");
xprintf((*tab)++, "\"statistics\": [");
XML_DTD_VERSION);
printf("\"http://pagesperso-orange.fr/sebastien.godard/sysstat-%s.dtd\">\n",
XML_DTD_VERSION);
-
+
xprintf(*tab, "<sysstat>");
xprintf(++(*tab), "<sysdata-version>%s</sysdata-version>",
get_file_timestamp_struct(flags, &rectime, file_hdr);
strftime(cur_time, sizeof(cur_time), "%Y-%m-%d", &rectime);
xprintf0(*tab, "\"file-date\": \"%s\"", cur_time);
-
+
if ((loc_t = gmtime((const time_t *) &file_hdr->sa_ust_time)) != NULL) {
strftime(cur_time, sizeof(cur_time), "%T", loc_t);
printf(",\n");
file_hdr->sa_sysname, file_hdr->sa_release,
file_hdr->sa_nodename, file_hdr->sa_machine,
cpu_nr > 1 ? cpu_nr - 1 : 1);
-
+
printf(_("Number of CPU for last samples in file: %u\n"),
file_hdr->sa_last_cpu_nr > 1 ? file_hdr->sa_last_cpu_nr - 1 : 1);
-
+
if ((loc_t = gmtime((const time_t *) &file_hdr->sa_ust_time)) != NULL) {
printf(_("File time: "));
strftime(cur_time, sizeof(cur_time), "%T", loc_t);
}
printf(_("Size of a long int: %d\n"), file_hdr->sa_sizeof_long);
-
+
/* Number of activities (number of volatile activities) in file */
printf("sa_act_nr (sa_vol_act_nr): %u (%u)\n",
file_hdr->sa_act_nr, file_hdr->sa_vol_act_nr);
void init_structures(void)
{
int i;
-
+
for (i = 0; i < 3; i++)
memset(&record_hdr[i], 0, RECORD_HEADER_SIZE);
}
void reverse_check_act(unsigned int act_nr)
{
int i, j;
-
+
for (i = 0; i < NR_ACT; i++) {
-
+
if (IS_SELECTED(act[i]->options)) {
-
+
for (j = 0; j < act_nr; j++) {
if (id_seq[j] == act[i]->id)
break;
* The rectime structure has NOT been updated.
*/
return 1;
-
+
rectime = *ltm;
}
-
+
return 0;
}
/* Get number of options entered on the command line */
if (get_activity_nr(act, AO_SELECTED, COUNT_OUTPUTS) > 1)
return TRUE;
-
+
for (i = 0; i < NR_ACT; i++) {
if (IS_SELECTED(act[i]->options)) {
/* Special processing for activities using a bitmap */
int i;
unsigned long long itv, g_itv;
static __nr_t cpu_nr = -1;
-
+
if (cpu_nr < 0)
cpu_nr = act[get_activity_position(act, A_CPU)]->nr;
strncpy(timestamp[curr], _("Average:"), TIMESTAMP_LEN);
timestamp[curr][TIMESTAMP_LEN - 1] = '\0';
strcpy(timestamp[!curr], timestamp[curr]);
-
+
/* Test stdout */
TEST_STDOUT(STDOUT_FILENO);
-
+
for (i = 0; i < NR_ACT; i++) {
-
+
if ((act_id != ALL_ACTIVITIES) && (act[i]->id != act_id))
continue;
-
+
if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
/* Display current average activity statistics */
(*act[i]->f_print_avg)(act[i], 2, curr,
}
avg_count++;
-
+
/* Test stdout */
TEST_STDOUT(STDOUT_FILENO);
memset(act[i]->buf[!curr], 0, act[i]->msize * act[i]->nr * act[i]->nr2);
}
}
-
+
flags |= S_F_SINCE_BOOT;
dis = TRUE;
-
+
write_stats(curr, USE_SADC, &count, NO_TM_START, NO_TM_END, NO_RESET, ALL_ACTIVITIES);
-
+
exit(0);
}
/* Don't forget to read the volatile activities structures */
new_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic,
file_hdr.sa_vol_act_nr);
-
+
if (dp) {
printf("\n%-11s LINUX RESTART\t(%d CPU)\n",
cur_time, new_cpu_nr > 1 ? new_cpu_nr - 1 : 1);
if (sa_read(&record_hdr[curr], RECORD_HEADER_SIZE)) {
print_read_error();
}
-
+
for (i = 0; i < NR_ACT; i++) {
-
+
if (!id_seq[i])
continue;
if ((p = get_activity_position(act, id_seq[i])) < 0) {
if (sa_read(&file_hdr, FILE_HEADER_SIZE)) {
print_read_error();
}
-
+
/* Read activity list */
for (i = 0; i < file_hdr.sa_act_nr; i++) {
-
+
if (sa_read(&file_act, FILE_ACTIVITY_SIZE)) {
print_read_error();
}
while (i < NR_ACT) {
id_seq[i++] = 0;
}
-
+
/* Check that all selected activties are actually sent by sadc */
reverse_check_act(file_hdr.sa_act_nr);
}
if (!id_seq[i])
continue;
-
+
if ((p = get_activity_position(act, id_seq[i])) < 0) {
/* Should never happen */
PANIC(1);
}
if (!IS_SELECTED(act[p]->options))
continue;
-
+
if (!HAS_MULTIPLE_OUTPUTS(act[p]->options)) {
handle_curr_act_stats(ifd, fpos, &curr, &cnt, &eosaf, rows,
act[p]->id, &reset, file_actlst,
}
else {
unsigned int optf, msk;
-
+
optf = act[p]->opt_flags;
-
+
for (msk = 1; msk < 0x10; msk <<= 1) {
if (act[p]->opt_flags & msk) {
act[p]->opt_flags &= msk;
-
+
handle_curr_act_stats(ifd, fpos, &curr, &cnt,
&eosaf, rows, act[p]->id,
&reset, file_actlst,
while (!eosaf);
close(ifd);
-
+
free(file_actlst);
}
#endif
tm_start.use = tm_end.use = FALSE;
-
+
/* Allocate and init activity bitmaps */
allocate_bitmaps(act);
usage(argv[0]);
}
}
-
+
else if ((strlen(argv[opt]) > 1) &&
(strlen(argv[opt]) < 4) &&
!strncmp(argv[opt], "-", 1) &&
if (!interval && (from_file[0] || to_file[0])) {
usage(argv[0]);
}
-
+
/* Cannot enter a day shift with -o option */
if (to_file[0] && day_offset) {
usage(argv[0]);
if (USE_PRETTY_OPTION(flags)) {
dm_major = get_devmap_major();
}
-
+
if (!count) {
/*
* count parameter not set: Display all the contents of the file
/* Default is CPU activity... */
select_default_activity(act);
-
+
/* Reading stats from file: */
if (from_file[0]) {
if (interval < 0) {
/* Read stats from file */
read_stats_from_file(from_file);
-
+
/* Free stuctures and activity bitmaps */
free_bitmaps(act);
free_structures(act);
/* Flags to be passed to sadc */
salloc(args_idx++, "-z");
-
+
/* Writing data to a file (option -o) */
if (to_file[0]) {
/* Collect all possible activities (option -S XALL for sadc) */
* to collect only activities that will be displayed.
*/
int act_id = 0;
-
+
for (i = 0; i < NR_ACT; i++) {
if (IS_SELECTED(act[i]->options)) {
act_id |= act[i]->group;
sic = (struct stats_irq *) ((char *) a->buf[curr] + i * a->msize);
sip = (struct stats_irq *) ((char *) a->buf[!curr] + i * a->msize);
-
+
/* Should current interrupt (including int "sum") be displayed? */
if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
struct stats_swap
*ssc = (struct stats_swap *) a->buf[curr],
*ssp = (struct stats_swap *) a->buf[!curr];
-
+
xprintf(tab, "<swap-pages per=\"second\" "
"pswpin=\"%.2f\" "
"pswpout=\"%.2f\"/>",
xprintf(tab, "<inactive>%lu</inactive>",
smc->inactkb);
-
+
xprintf(tab--, "<dirty>%lu</dirty>",
smc->dirtykb);
}
{
struct stats_ktables
*skc = (struct stats_ktables *) a->buf[curr];
-
+
xprintf(tab, "<kernel "
"dentunusd=\"%u\" "
"file-nr=\"%u\" "
{
struct stats_queue
*sqc = (struct stats_queue *) a->buf[curr];
-
+
xprintf(tab, "<queue "
"runq-sz=\"%lu\" "
"plist-sz=\"%u\" "
if (DISPLAY_PERSIST_NAME_S(flags)) {
persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
}
-
+
if (persist_dev_name) {
dev_name = persist_dev_name;
}
struct stats_net_etcp
*snetc = (struct stats_net_etcp *) a->buf[curr],
*snetp = (struct stats_net_etcp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_xml_markup;
struct stats_net_udp
*snuc = (struct stats_net_udp *) a->buf[curr],
*snup = (struct stats_net_udp *) a->buf[!curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_xml_markup;
{
struct stats_net_sock6
*snsc = (struct stats_net_sock6 *) a->buf[curr];
-
+
if (!IS_SELECTED(a->options) || (a->nr <= 0))
goto close_xml_markup;
tab++;
xprintf(tab++, "<cpu-frequency unit=\"MHz\">");
-
+
for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr] + i * a->msize);