• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24 
25 /* Simple tool to print statistics on incoming line buffers intervals */
26 
27 #define _ISOC99_SOURCE
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <stdint.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <unistd.h>
35 
36 #include "igt_stats.h"
37 
statify(FILE * file,const char * name)38 static void statify(FILE *file, const char *name)
39 {
40 	igt_stats_t stats;
41 	char *line = NULL;
42 	size_t line_len = 0;
43 
44 	igt_stats_init(&stats);
45 	while (getline(&line, &line_len, file) != -1) {
46 		char *end, *start = line;
47 		union {
48 			unsigned long long u64;
49 			double fp;
50 		} u;
51 		int is_float;
52 
53 		is_float = 0;
54 		u.u64 = strtoull(start, &end, 0);
55 		if (*end == '.') {
56 			u.fp = strtod(start, &end);
57 			is_float = 1;
58 		}
59 		while (start != end) {
60 			if (is_float)
61 				igt_stats_push_float(&stats, u.fp);
62 			else
63 				igt_stats_push(&stats, u.u64);
64 
65 			is_float = 0;
66 			u.u64 = strtoull(start = end, &end, 0);
67 			if (*end == '.') {
68 				u.fp = strtod(start, &end);
69 				is_float = 1;
70 			}
71 		}
72 	}
73 	free(line);
74 
75 	if (name)
76 		printf("%s: ", name);
77 
78 	printf("%f\n", igt_stats_get_trimean(&stats));
79 
80 	igt_stats_fini(&stats);
81 }
82 
main(int argc,char ** argv)83 int main(int argc, char **argv)
84 {
85 	if (argc == 1) {
86 		statify(stdin, NULL);
87 	} else {
88 		int i;
89 
90 		for (i = 1; i < argc; i++) {
91 			FILE *file;
92 
93 			file = fopen(argv[i], "r");
94 			if (file == NULL) {
95 				perror(argv[i]);
96 				continue;
97 			}
98 
99 			statify(file, argv[i]);
100 			fclose(file);
101 		}
102 	}
103 
104 	return 0;
105 }
106