lin
2025-01-04 be45768b193281917003531c55e9ebda9d2c2f99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#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;
   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;
 
   if (argc < 2) {
       fprintf(stderr, "%s: file\n", argv[0]);
       return 1;
   }
 
   f = fopen(argv[1], "r");
   if (!f) {
       perror("fopen");
       return 1;
   }
 
   last_time = 0;
   alias = nr = 0;
   total_entries = 0;
   while ((p = fgets(line, sizeof(line), f)) != NULL) {
       if (sscanf(p, "%3d,%3d %5d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5)
           break;
 
       if (this_time < last_time) {
           fprintf(stdout, "last: %s", last_line);
           fprintf(stdout, "this: %s", p);
           nr++;
       }
 
       last_time = this_time;
 
       if (cpu >= MAX_CPUS) {
           fprintf(stderr, "cpu%d too large\n", cpu);
           break;
       }
 
       if (last_seq[cpu] == seq) {
           fprintf(stdout, "alias on sequence %u\n", seq);
           alias++;
       }
 
       last_seq[cpu] = seq;
       total_entries++;
       strcpy(last_line, line);
   }
 
   fprintf(stdout, "Events %Lu: %d unordered, %d aliases\n", total_entries, nr, alias);
   fclose(f);
 
   return nr != 0;
}