diff -Nru cpustat-0.01.01~l/cpustat.8 cpustat-0.01.02~l/cpustat.8 --- cpustat-0.01.01~l/cpustat.8 2011-12-26 10:25:31.000000000 +0000 +++ cpustat-0.01.02~l/cpustat.8 2011-12-27 11:46:59.000000000 +0000 @@ -34,6 +34,9 @@ .B \-h show help .TP +.B \-i +ignore cpustat in the statistics +.TP .B \-n task_count only display the first task_count number of top tasks. .TP diff -Nru cpustat-0.01.01~l/cpustat.c cpustat-0.01.02~l/cpustat.c --- cpustat-0.01.01~l/cpustat.c 2011-12-26 10:25:31.000000000 +0000 +++ cpustat-0.01.02~l/cpustat.c 2011-12-27 11:46:59.000000000 +0000 @@ -1,6 +1,5 @@ /* * Copyright (C) 2011 Canonical - * Hugely modified parts from powertop-1.13, Copyright 2007, Intel Corporation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,6 +32,7 @@ #define APP_NAME "cpustat" #define TABLE_SIZE (32999) /* Should be a prime */ #define OPT_QUIET (0x00000001) +#define OPT_IGNORE_SELF (0x00000002) typedef struct link { void *data; @@ -410,13 +410,12 @@ h = hash_pjw(ident); cs = cpu_stats[h]; - while (cs) { + for (cs = cpu_stats[h]; cs; cs = cs->next) { if (strcmp(cs->info->ident, ident) == 0) { cs->utime += utime; cs->stime += stime; return; } - cs = cs->next; } /* Not found, it is new! */ @@ -467,7 +466,7 @@ cpu_stat_t **sorted, /* CPU stat sorted list */ cpu_stat_t *new) /* CPU stat to add */ { - while (*sorted != NULL) { + while (*sorted) { if ((*sorted)->delta < new->delta) { new->sorted_usage_next = *(sorted); break; @@ -498,8 +497,9 @@ unsigned long nr_ticks = sysconf(_SC_NPROCESSORS_CONF) * clock_ticks; for (i=0; inext) { cpu_stat_t *found = cpu_stat_find(cpu_stats_old, cs); if (found) { @@ -518,7 +518,6 @@ sample_add(cs, whence); } } - cs = cs->next; } } @@ -552,6 +551,10 @@ { DIR *dir; struct dirent *entry; + static pid_t my_pid; + + if ((opt_flags & OPT_IGNORE_SELF) && (my_pid == 0)) + my_pid = getpid(); if ((dir = opendir("/proc")) == NULL) { fprintf(stderr, "Cannot read directory /proc\n"); @@ -576,9 +579,12 @@ /* 3173 (a.out) R 3093 3173 3093 34818 3173 4202496 165 0 0 0 3194 0 */ fscanf(fp, "%d (%[^)]) %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu", &pid, comm, &utime, &stime); + fclose(fp); + + if ((opt_flags & OPT_IGNORE_SELF) && (my_pid == pid)) + continue; cpu_stat_add(cpu_stats, pid, comm, utime, stime); - fclose(fp); } closedir(dir); @@ -592,6 +598,7 @@ { printf("Usage: %s [-q] [-r csv_file] [-n task_count] [duration] [count]\n", APP_NAME); printf("\t-h help\n"); + printf("\t-i ignore %s in the statistics\n", APP_NAME); printf("\t-n specifies number of tasks to display\n"); printf("\t-q run quietly, useful with option -r\n"); printf("\t-r specifies a comma separated values output file to dump samples into.\n"); @@ -614,13 +621,16 @@ clock_ticks = sysconf(_SC_CLK_TCK); for (;;) { - int c = getopt(argc, argv, "hn:qr:t:"); + int c = getopt(argc, argv, "hin:qr:t:"); if (c == -1) break; switch (c) { case 'h': show_usage(); exit(EXIT_SUCCESS); + case 'i': + opt_flags |= OPT_IGNORE_SELF; + break; case 'n': n_lines = atoi(optarg); if (n_lines < 1) { diff -Nru cpustat-0.01.01~l/debian/changelog cpustat-0.01.02~l/debian/changelog --- cpustat-0.01.01~l/debian/changelog 2011-12-26 10:25:31.000000000 +0000 +++ cpustat-0.01.02~l/debian/changelog 2011-12-27 11:46:59.000000000 +0000 @@ -1,3 +1,10 @@ +cpustat (0.01.02~l) lucid; urgency=low + + * Tidy up lists + * Add -i option + + -- Colin King Tue, 27 Dec 2011 11:43:00 +0000 + cpustat (0.01.01~l) lucid; urgency=low * Init lists