aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 14:53:42 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 14:53:42 -0400
commit4d337d4d7a3c1e6a65b090251c4e41592740b0d0 (patch)
tree11a951fbd6fd3cc3dea8e102bd57a00acc94e852
parent9bee556de7489579c3bdd0d2d4d457ffa72168eb (diff)
event naming
-rw-r--r--Makefile15
-rw-r--r--include/mapping.h8
-rw-r--r--include/timestamp.h2
-rw-r--r--src/ft2csv.c117
-rw-r--r--src/ftcat.c35
-rw-r--r--src/mapping.c35
-rw-r--r--src/timestamp.c31
7 files changed, 221 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index d87dd9b..0bea02f 100644
--- a/Makefile
+++ b/Makefile
@@ -6,10 +6,17 @@ vpath %.c src/
6 6
7.PHONY: clean 7.PHONY: clean
8 8
9all: ftcat 9TOOLS = ftcat ft2csv
10 10
11ftcat: ftcat.o 11all: ${TOOLS}
12 ${CC} -o ftcat ftcat.o 12
13FTCAT_OBJ = ftcat.o timestamp.o
14ftcat: ${FTCAT_OBJ}
15 ${CC} -o ftcat ${FTCAT_OBJ}
16
17FT2CSV_OBJ = ft2csv.o mapping.o timestamp.o
18ft2csv: ${FT2CSV_OBJ}
19 ${CC} -o ft2csv ${FT2CSV_OBJ}
13 20
14clean: 21clean:
15 rm -rf *.o ftcat 22 rm -rf *.o ${TOOLS}
diff --git a/include/mapping.h b/include/mapping.h
new file mode 100644
index 0000000..2a7b6a8
--- /dev/null
+++ b/include/mapping.h
@@ -0,0 +1,8 @@
1#ifndef _MAPPING_H_
2#define _MAPPING_H_
3
4int map_file(const char* filename, void **addr, size_t *size);
5
6
7#endif
8
diff --git a/include/timestamp.h b/include/timestamp.h
index ae50ae1..7874458 100644
--- a/include/timestamp.h
+++ b/include/timestamp.h
@@ -8,6 +8,8 @@ struct timestamp {
8 int cpu; 8 int cpu;
9}; 9};
10 10
11int str2event(const char* str, unsigned long *id);
12
11#define ENABLE_CMD 0L 13#define ENABLE_CMD 0L
12 14
13#define TIMESTAMP(id) id ## L 15#define TIMESTAMP(id) id ## L
diff --git a/src/ft2csv.c b/src/ft2csv.c
new file mode 100644
index 0000000..a5fdf0a
--- /dev/null
+++ b/src/ft2csv.c
@@ -0,0 +1,117 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5
6#include "mapping.h"
7
8#include "timestamp.h"
9
10static unsigned int incomplete = 0;
11
12static struct timestamp* next(struct timestamp** pos, size_t* count, int cpu)
13{
14 while (*count--)
15 if ((++(*pos))->cpu == cpu)
16 return *pos;
17 return NULL;
18}
19
20static struct timestamp* next_id(struct timestamp** pos, size_t* count,
21 int cpu, unsigned long id)
22{
23 struct timestamp* ret;
24 while ((ret = next(pos, count, cpu)) && (*pos)->event != id);
25 return ret;
26}
27
28static int find_pair(struct timestamp* start,
29 struct timestamp** end,
30 size_t count)
31{
32 struct timestamp *pos = start;
33 /* convention: the end->event is start->event + 1 */
34 *end = next_id(&pos, &count, start->cpu, start->event + 1);
35 return *end != NULL;
36}
37
38static void show_csv(struct timestamp* ts, size_t count)
39{
40 struct timestamp* start = ts;
41 struct timestamp* stop;
42
43 if (find_pair(start, &stop, count)) {
44 printf("%llu, %llu, %llu\n",
45 start->timestamp, stop->timestamp,
46 stop->timestamp - start->timestamp);
47 } else
48 incomplete++;
49
50}
51
52/*static void show_all_per_cpu(struct timestamp* ts, size_t count)
53{
54 struct timestamp* _ts = ts;
55 size_t _count = count;
56 int cpu;
57
58 for (cpu = 0; cpu < 4; cpu++) {
59 count = _count;
60 ts = _ts;
61 while (count--) {
62 if (ts->cpu == cpu)
63 show(ts, count);
64 ts++;
65 }
66 }
67}*/
68
69static void show_id(struct timestamp* ts, size_t count, unsigned long id)
70{
71 while (count--)
72 if (ts->event == id)
73 show_csv(ts++, count);
74 else
75 ts++;
76}
77
78
79static void dump(struct timestamp* ts, size_t count, unsigned long id)
80{
81 while (count--)
82 printf("%lu\n", (ts++)->event);
83}
84
85
86static void die(char* msg)
87{
88 if (errno)
89 perror("error: ");
90 fprintf(stderr, "%s\n", msg);
91 exit(1);
92}
93
94int main(int argc, char** argv)
95{
96 void* mapped;
97 size_t size, count;
98 struct timestamp* ts;
99 unsigned long id;
100
101 if (argc != 3)
102 die("Usage: ft2csv <event_name> <logfile>");
103 if (map_file(argv[2], &mapped, &size))
104 die("could not map file");
105
106 if (!str2event(argv[1], &id))
107 die("Unknown event!");
108
109 ts = (struct timestamp*) mapped;
110 count = size / sizeof(struct timestamp);
111
112 show_id(ts, count, id);
113
114 fprintf(stderr, "Incomplete: %d\n", incomplete);
115
116 return 0;
117}
diff --git a/src/ftcat.c b/src/ftcat.c
index bb7b3e6..151fa29 100644
--- a/src/ftcat.c
+++ b/src/ftcat.c
@@ -2,34 +2,34 @@
2#include <unistd.h> 2#include <unistd.h>
3#include <fcntl.h> 3#include <fcntl.h>
4#include <string.h> 4#include <string.h>
5#include <signal.h>
6#include <stdlib.h>
5 7
6#include "timestamp.h" 8#include "timestamp.h"
7 9
10static int fd;
11
12static void on_sigint(int sig)
13{
14 close(fd);
15 exit(0);
16}
8 17
9static int enable_events(int fd, char* str) 18static int enable_events(int fd, char* str)
10{ 19{
11 long id; 20 unsigned long id;
12 long cmd[3]; 21 unsigned long cmd[3];
13 22
14 if (!strcmp(str, "sched")) { 23 if (!str2event(str, &id))
15 id = TS_SCHED_START;
16 } else if (!strcmp(str, "tick")) {
17 id = TS_TICK_START;
18 } else if (!strcmp(str, "plug_tick")) {
19 id = TS_PLUGIN_TICK_START;
20 } else if (!strcmp(str, "plug_sched")) {
21 id = TS_PLUGIN_SCHED_START;
22 } else
23 return 0; 24 return 0;
24 25
25 cmd[0] = ENABLE_CMD; 26 cmd[0] = ENABLE_CMD;
26 cmd[1] = id; 27 cmd[1] = id;
27 cmd[2] = id + 2; 28 cmd[2] = id + 1;
28 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long); 29 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long);
29} 30}
30 31
31 32
32
33static void cat2stdout(int fd) 33static void cat2stdout(int fd)
34{ 34{
35 static char buf[4096]; 35 static char buf[4096];
@@ -43,19 +43,17 @@ static void usage(void)
43{ 43{
44 fprintf(stderr, 44 fprintf(stderr,
45 "Usage: ftcat <ft device> TS1 TS2 ....\n\n" 45 "Usage: ftcat <ft device> TS1 TS2 ....\n\n"
46 "where TS1, TS2, ... is one of " 46 // "where TS1, TS2, ... is one of "
47 " sched, tick, plug_tick, plug_sched" 47 // " sched, tick, plug_tick, plug_sche"
48 "\n"); 48 "\n");
49 exit(1); 49 exit(1);
50} 50}
51 51
52int main(int argc, char** argv) 52int main(int argc, char** argv)
53{ 53{
54 int fd;
55
56 if (argc < 3) 54 if (argc < 3)
57 usage(); 55 usage();
58 56
59 fd = open(argv[1], O_RDWR); 57 fd = open(argv[1], O_RDWR);
60 if (fd < 0) { 58 if (fd < 0) {
61 perror("could not open feathertrace"); 59 perror("could not open feathertrace");
@@ -63,6 +61,7 @@ int main(int argc, char** argv)
63 } 61 }
64 argc -= 2; 62 argc -= 2;
65 argv += 2; 63 argv += 2;
64 signal(SIGINT,on_sigint);
66 while (argc--) { 65 while (argc--) {
67 if (!enable_events(fd, *argv)) { 66 if (!enable_events(fd, *argv)) {
68 fprintf(stderr, "Enabling %s failed.\n", *argv); 67 fprintf(stderr, "Enabling %s failed.\n", *argv);
diff --git a/src/mapping.c b/src/mapping.c
new file mode 100644
index 0000000..19d7129
--- /dev/null
+++ b/src/mapping.c
@@ -0,0 +1,35 @@
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <sys/mman.h>
4#include <fcntl.h>
5#include <errno.h>
6#include <unistd.h>
7
8#include "mapping.h"
9
10int map_file(const char* filename, void **addr, size_t *size)
11{
12 struct stat info;
13 int error = 0;
14 int fd;
15
16 error = stat(filename, &info);
17 if (!error) {
18 *size = info.st_size;
19 if (info.st_size > 0) {
20 fd = open(filename, O_RDWR);
21 if (fd >= 0) {
22 *addr = mmap(NULL, *size,
23 PROT_READ | PROT_WRITE,
24 MAP_PRIVATE,
25 fd, 0);
26 if (*addr == MAP_FAILED)
27 error = -1;
28 close(fd);
29 } else
30 error = fd;
31 } else
32 *addr = NULL;
33 }
34 return error;
35}
diff --git a/src/timestamp.c b/src/timestamp.c
new file mode 100644
index 0000000..850e437
--- /dev/null
+++ b/src/timestamp.c
@@ -0,0 +1,31 @@
1#include <string.h>
2
3#include "timestamp.h"
4
5
6struct event_name {
7 const char* name;
8 unsigned long id;
9};
10
11#define EVENT(name) {#name, TS_ ## name ## _START}
12
13static struct event_name event_table[] =
14{
15 EVENT(SCHED),
16 EVENT(TICK),
17 EVENT(PLUGIN_SCHED),
18 EVENT(PLUGIN_TICK)
19};
20
21int str2event(const char* str, unsigned long *id)
22{
23 int i;
24
25 for (i = 0; i < sizeof(event_table) / sizeof(event_table[0]); i++)
26 if (!strcmp(str, event_table[i].name)) {
27 *id = event_table[i].id;
28 return 1;
29 }
30 return 0;
31}