Commit | Line | Data |
---|---|---|
42a58cd1 JA |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <fcntl.h> | |
212421d8 | 4 | #include <string.h> |
42a58cd1 | 5 | #include <unistd.h> |
28fa9f69 | 6 | #include <errno.h> |
ced8a9bf | 7 | |
42a58cd1 JA |
8 | int main(int argc, char *argv[]) |
9 | { | |
10 | double this_time, last_time; | |
212421d8 | 11 | char line[256], last_line[256], *p; |
b444507c | 12 | int major, minor, cpu, nr, alias; |
28fa9f69 | 13 | long MAX_CPUS; |
fd8a68ba | 14 | unsigned long long total_entries; |
28fa9f69 NZ |
15 | unsigned int *last_seq; |
16 | unsigned int seq; | |
42a58cd1 JA |
17 | FILE *f; |
18 | ||
80c4041b AA |
19 | #ifdef _SC_NPROCESSORS_ONLN |
20 | MAX_CPUS = sysconf(_SC_NPROCESSORS_ONLN); | |
28fa9f69 NZ |
21 | if (MAX_CPUS < 1) |
22 | { | |
23 | fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", | |
24 | strerror (errno)); | |
25 | fprintf(stderr, "Assuming 1024\n"); | |
26 | MAX_CPUS = 1024; | |
27 | } | |
28 | #else | |
29 | MAX_CPUS = CPU_SETSIZE; | |
30 | #endif | |
31 | ||
32 | last_seq = malloc( sizeof(unsigned int) * MAX_CPUS ); | |
ced8a9bf JA |
33 | for (nr = 0; nr < MAX_CPUS; nr++) |
34 | last_seq[nr] = -1; | |
35 | ||
42a58cd1 JA |
36 | if (argc < 2) { |
37 | fprintf(stderr, "%s: file\n", argv[0]); | |
38 | return 1; | |
39 | } | |
40 | ||
41 | f = fopen(argv[1], "r"); | |
42 | if (!f) { | |
43 | perror("fopen"); | |
44 | return 1; | |
45 | } | |
46 | ||
47 | last_time = 0; | |
8c0221bf | 48 | alias = nr = 0; |
fd8a68ba | 49 | total_entries = 0; |
42a58cd1 | 50 | while ((p = fgets(line, sizeof(line), f)) != NULL) { |
28fa9f69 | 51 | if (sscanf(p, "%3d,%3d %5d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5) |
42a58cd1 JA |
52 | break; |
53 | ||
cf4b68a5 | 54 | if (this_time < last_time) { |
212421d8 JA |
55 | fprintf(stdout, "last: %s", last_line); |
56 | fprintf(stdout, "this: %s", p); | |
cf4b68a5 | 57 | nr++; |
212421d8 JA |
58 | } |
59 | ||
60 | last_time = this_time; | |
63c7bd75 | 61 | |
ced8a9bf JA |
62 | if (cpu >= MAX_CPUS) { |
63 | fprintf(stderr, "cpu%d too large\n", cpu); | |
64 | break; | |
65 | } | |
66 | ||
67 | if (last_seq[cpu] == seq) { | |
b99d1637 | 68 | fprintf(stdout, "alias on sequence %u\n", seq); |
63c7bd75 | 69 | alias++; |
b99d1637 | 70 | } |
63c7bd75 | 71 | |
ced8a9bf | 72 | last_seq[cpu] = seq; |
fd8a68ba | 73 | total_entries++; |
212421d8 | 74 | strcpy(last_line, line); |
42a58cd1 JA |
75 | } |
76 | ||
fd8a68ba | 77 | fprintf(stdout, "Events %Lu: %d unordered, %d aliases\n", total_entries, nr, alias); |
42a58cd1 | 78 | fclose(f); |
cf4b68a5 JA |
79 | |
80 | return nr != 0; | |
42a58cd1 | 81 | } |