• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <string.h>
5 #include <unistd.h>
6 
7 #define MAX_CPUS	(512)
8 
main(int argc,char * argv[])9 int main(int argc, char *argv[])
10 {
11 	double this_time, last_time;
12 	char line[256], last_line[256], *p;
13 	int major, minor, cpu, nr, alias;
14 	unsigned long long total_entries;
15 	unsigned int last_seq[MAX_CPUS], seq;
16 	FILE *f;
17 
18 	for (nr = 0; nr < MAX_CPUS; nr++)
19 		last_seq[nr] = -1;
20 
21 	if (argc < 2) {
22 		fprintf(stderr, "%s: file\n", argv[0]);
23 		return 1;
24 	}
25 
26 	f = fopen(argv[1], "r");
27 	if (!f) {
28 		perror("fopen");
29 		return 1;
30 	}
31 
32 	last_time = 0;
33 	alias = nr = 0;
34 	total_entries = 0;
35 	while ((p = fgets(line, sizeof(line), f)) != NULL) {
36 		if (sscanf(p, "%3d,%3d %2d %8d %lf", &major, &minor, &cpu, &seq, &this_time) != 5)
37 			break;
38 
39 		if (this_time < last_time) {
40 			fprintf(stdout, "last: %s", last_line);
41 			fprintf(stdout, "this: %s", p);
42 			nr++;
43 		}
44 
45 		last_time = this_time;
46 
47 		if (cpu >= MAX_CPUS) {
48 			fprintf(stderr, "cpu%d too large\n", cpu);
49 			break;
50 		}
51 
52 		if (last_seq[cpu] == seq) {
53 			fprintf(stdout, "alias on sequence %u\n", seq);
54 			alias++;
55 		}
56 
57 		last_seq[cpu] = seq;
58 		total_entries++;
59 		strcpy(last_line, line);
60 	}
61 
62 	fprintf(stdout, "Events %Lu: %d unordered, %d aliases\n", total_entries, nr, alias);
63 	fclose(f);
64 
65 	return nr != 0;
66 }
67