iowatcher: don't add Q events to the io hash
[blktrace.git] / verify_blkparse.c
index aae8d7c99dc842df9d98500682d36fd6b676f44d..3f3e92a563c9a50d7168cc498eecc2ff30525053 100644 (file)
@@ -3,18 +3,33 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
-
-#define MAX_CPUS       (512)
+#include <errno.h>
 
 int main(int argc, char *argv[])
 {
        double this_time, last_time;
        char line[256], last_line[256], *p;
        int major, minor, cpu, nr, alias;
+       long  MAX_CPUS;
        unsigned long long total_entries;
-       unsigned int last_seq[MAX_CPUS], seq;
+       unsigned int *last_seq;
+       unsigned int seq;
        FILE *f;
 
+#ifdef _SC_NPROCESSORS_ONLN
+       MAX_CPUS = sysconf(_SC_NPROCESSORS_ONLN);
+       if (MAX_CPUS < 1)
+       {
+               fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", 
+                       strerror (errno));
+               fprintf(stderr, "Assuming 1024\n");
+               MAX_CPUS = 1024;
+       }
+#else
+       MAX_CPUS = CPU_SETSIZE;
+#endif 
+       
+       last_seq = malloc( sizeof(unsigned int) * MAX_CPUS );
        for (nr = 0; nr < MAX_CPUS; nr++)
                last_seq[nr] = -1;
 
@@ -33,7 +48,7 @@ int main(int argc, char *argv[])
        alias = nr = 0;
        total_entries = 0;
        while ((p = fgets(line, sizeof(line), f)) != NULL) {
-               if (sscanf(p, "%3d,%3d %2d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5)
+               if (sscanf(p, "%3d,%3d %5d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5)
                        break;
 
                if (this_time < last_time) {