aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 02:49:16 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 02:49:16 -0400
commitd4f334c3e019d4fa1f50e33c51146dd469ee4178 (patch)
treec9c98ed4bf8b1078967720f63557535f86108d5e
Initial commit
-rw-r--r--Makefile13
-rw-r--r--ftcat.c74
-rw-r--r--timestamp.h31
3 files changed, 118 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f00bcd4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
1CFLAGS=-Wall -g
2CPPFLAGS=-Wall -g
3
4.PHONY: clean
5
6all: ftcat
7
8
9ftcat: ftcat.o
10 cc -o ftcat ftcat.o
11
12clean:
13 rm -rf *.o ftcat
diff --git a/ftcat.c b/ftcat.c
new file mode 100644
index 0000000..f706ef5
--- /dev/null
+++ b/ftcat.c
@@ -0,0 +1,74 @@
1#include <stdio.h>
2#include <unistd.h>
3#include <fcntl.h>
4#include <string.h>
5
6#include "timestamp.h"
7
8
9static int enable_events(int fd, char* str)
10{
11 long id;
12 long cmd[3];
13
14 if (!strcmp(str, "sched")) {
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
25 cmd[0] = ENABLE_CMD;
26 cmd[1] = id;
27 cmd[2] = id + 2;
28 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long);
29}
30
31
32
33static void cat2stdout(int fd)
34{
35 static char buf[4096];
36 int rd;
37 while (rd = read(fd, buf, 4096))
38 fwrite(buf, 1, rd, stdout);
39}
40
41
42static void usage(void)
43{
44 fprintf(stderr, "Usage: ftcat <ft device> TS1 TS2 ....\n\n");
45 exit(1);
46}
47
48int main(int argc, char** argv)
49{
50 int fd;
51
52 if (argc < 3)
53 usage();
54
55 fd = open(argv[1], O_RDWR);
56 if (fd < 0) {
57 perror("could not open feathertrace");
58 return 1;
59 }
60 argc -= 2;
61 argv += 2;
62 while (argc--) {
63 if (!enable_events(fd, *argv)) {
64 fprintf(stderr, "Enabling %s failed.\n", *argv);
65 return 2;
66 }
67 argv++;
68 }
69
70 cat2stdout(fd);
71 close(fd);
72 return 0;
73}
74
diff --git a/timestamp.h b/timestamp.h
new file mode 100644
index 0000000..ae50ae1
--- /dev/null
+++ b/timestamp.h
@@ -0,0 +1,31 @@
1#ifndef TIMESTAMP_H
2#define TIMESTAMP_H
3
4struct timestamp {
5 unsigned long event;
6 unsigned long long timestamp;
7 unsigned int seq_no;
8 int cpu;
9};
10
11#define ENABLE_CMD 0L
12
13#define TIMESTAMP(id) id ## L
14
15#define TS_SCHED_START TIMESTAMP(100)
16#define TS_SCHED_END TIMESTAMP(101)
17
18#define TS_TICK_START TIMESTAMP(110)
19#define TS_TICK_END TIMESTAMP(111)
20
21#define TS_PLUGIN_SCHED_START TIMESTAMP(120)
22#define TS_PLUGIN_SCHED_END TIMESTAMP(121)
23
24#define TS_PLUGIN_TICK_START TIMESTAMP(130)
25#define TS_PLUGIN_TICK_END TIMESTAMP(131)
26
27
28
29
30
31#endif