aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-05-21 23:59:53 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-05-21 23:59:53 -0400
commit889a3c1661c870ad3742614d42ec19b0bff0230f (patch)
tree8558718210d7856ff0e4fedb2f49b160547a3e4b
parent65d2e481b266c51c5efcc4808be258ef7a13d039 (diff)
add new time stamps and drain on SIGUSR1
-rw-r--r--Makefile6
-rw-r--r--include/timestamp.h13
-rw-r--r--src/ftcat.c49
-rw-r--r--src/timestamp.c2
4 files changed, 53 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 0bea02f..9927dc4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
1CFLAGS=-Wall -g -Iinclude/ 1CFLAGS=-Wall -g -Iinclude/ -m64
2CPPFLAGS=-Wall -g 2CPPFLAGS=-Wall -g
3 3
4vpath %.h include/ 4vpath %.h include/
@@ -12,11 +12,11 @@ all: ${TOOLS}
12 12
13FTCAT_OBJ = ftcat.o timestamp.o 13FTCAT_OBJ = ftcat.o timestamp.o
14ftcat: ${FTCAT_OBJ} 14ftcat: ${FTCAT_OBJ}
15 ${CC} -o ftcat ${FTCAT_OBJ} 15 ${CC} ${CFLAGS} -o ftcat ${FTCAT_OBJ}
16 16
17FT2CSV_OBJ = ft2csv.o mapping.o timestamp.o 17FT2CSV_OBJ = ft2csv.o mapping.o timestamp.o
18ft2csv: ${FT2CSV_OBJ} 18ft2csv: ${FT2CSV_OBJ}
19 ${CC} -o ft2csv ${FT2CSV_OBJ} 19 ${CC} ${CFLAGS} -o ft2csv ${FT2CSV_OBJ}
20 20
21clean: 21clean:
22 rm -rf *.o ${TOOLS} 22 rm -rf *.o ${TOOLS}
diff --git a/include/timestamp.h b/include/timestamp.h
index 423a20e..7517bab 100644
--- a/include/timestamp.h
+++ b/include/timestamp.h
@@ -11,14 +11,21 @@ struct timestamp {
11int str2event(const char* str, unsigned long *id); 11int str2event(const char* str, unsigned long *id);
12const char* event2str(unsigned long id); 12const char* event2str(unsigned long id);
13 13
14#define ENABLE_CMD 0L 14#define ENABLE_CMD 0L
15#define DISABLE_CMD 1L
15 16
16#define TIMESTAMP(id) id 17#define TIMESTAMP(id) id
17 18
18#define TS_SCHED_START TIMESTAMP(100) 19#define TS_SCHED_START TIMESTAMP(100)
19#define TS_SCHED_END TIMESTAMP(101) 20#define TS_SCHED_END TIMESTAMP(101)
20#define TS_CXS_START TIMESTAMP(102) 21#define TS_SCHED2_START TIMESTAMP(102)
21#define TS_CXS_END TIMESTAMP(103) 22#define TS_SCHED2_END TIMESTAMP(103)
23
24#define TS_CXS_START TIMESTAMP(104)
25#define TS_CXS_END TIMESTAMP(105)
26
27#define TS_RELEASE_START TIMESTAMP(106)
28#define TS_RELEASE_END TIMESTAMP(107)
22 29
23#define TS_TICK_START TIMESTAMP(110) 30#define TS_TICK_START TIMESTAMP(110)
24#define TS_TICK_END TIMESTAMP(111) 31#define TS_TICK_END TIMESTAMP(111)
diff --git a/src/ftcat.c b/src/ftcat.c
index 4d83f56..0afba87 100644
--- a/src/ftcat.c
+++ b/src/ftcat.c
@@ -7,25 +7,37 @@
7 7
8#include "timestamp.h" 8#include "timestamp.h"
9 9
10#define MAX_EVENTS 128
11
10static int fd; 12static int fd;
13static int event_count = 1;
14static unsigned long ids[MAX_EVENTS];
11 15
12static void on_sigint(int sig) 16static int disable_all(int fd)
13{ 17{
14 close(fd); 18 int ret, size;
15 exit(0); 19 ids[0] = DISABLE_CMD;
20 fprintf(stderr, "Disabling %d events.\n", event_count - 1);
21 size = event_count * sizeof(long);
22 ret = write(fd, ids, size);
23 //fprintf(stderr, "write = %d, meant to write %d (%m)\n", ret, size);
24 return size == ret;
16} 25}
17 26
18static int enable_events(int fd, char* str) 27static int enable_events(int fd, char* str)
19{ 28{
20 unsigned long id; 29 unsigned long *id;
21 unsigned long cmd[3]; 30 unsigned long cmd[3];
22 31
23 if (!str2event(str, &id)) 32 id = ids + event_count;
33 if (!str2event(str, id))
24 return 0; 34 return 0;
25 35
36 event_count += 2;
37 id[1] = id[0] + 1;
26 cmd[0] = ENABLE_CMD; 38 cmd[0] = ENABLE_CMD;
27 cmd[1] = id; 39 cmd[1] = id[0];
28 cmd[2] = id + 1; 40 cmd[2] = id[1];
29 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long); 41 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long);
30} 42}
31 43
@@ -34,8 +46,8 @@ static void cat2stdout(int fd)
34{ 46{
35 static char buf[4096]; 47 static char buf[4096];
36 int rd; 48 int rd;
37 while ((rd = read(fd, buf, 4096))) 49 while ((rd = read(fd, buf, 4096)) > 0)
38 fwrite(buf, 1, rd, stdout); 50 fwrite(buf, 1, rd, stdout);
39} 51}
40 52
41 53
@@ -49,6 +61,20 @@ static void usage(void)
49 exit(1); 61 exit(1);
50} 62}
51 63
64static void on_sigint(int sig)
65{
66 close(fd);
67 exit(0);
68}
69
70static void on_sigusr1(int sig)
71{
72 int ok;
73 ok = disable_all(fd);
74 if (!ok)
75 fprintf(stderr, "disable_all: %m\n");
76}
77
52int main(int argc, char** argv) 78int main(int argc, char** argv)
53{ 79{
54 if (argc < 3) 80 if (argc < 3)
@@ -61,10 +87,11 @@ int main(int argc, char** argv)
61 } 87 }
62 argc -= 2; 88 argc -= 2;
63 argv += 2; 89 argv += 2;
64 signal(SIGINT,on_sigint); 90 signal(SIGINT, on_sigint);
91 signal(SIGUSR1, on_sigusr1);
65 while (argc--) { 92 while (argc--) {
66 if (!enable_events(fd, *argv)) { 93 if (!enable_events(fd, *argv)) {
67 fprintf(stderr, "Enabling %s failed.\n", *argv); 94 fprintf(stderr, "Enabling %s failed: %m\n", *argv);
68 return 2; 95 return 2;
69 } 96 }
70 argv++; 97 argv++;
diff --git a/src/timestamp.c b/src/timestamp.c
index ca03393..b495603 100644
--- a/src/timestamp.c
+++ b/src/timestamp.c
@@ -12,7 +12,9 @@ struct event_name {
12static struct event_name event_table[] = 12static struct event_name event_table[] =
13{ 13{
14 EVENT(SCHED), 14 EVENT(SCHED),
15 EVENT(SCHED2),
15 EVENT(TICK), 16 EVENT(TICK),
17 EVENT(RELEASE),
16 EVENT(PLUGIN_SCHED), 18 EVENT(PLUGIN_SCHED),
17 EVENT(PLUGIN_TICK), 19 EVENT(PLUGIN_TICK),
18 EVENT(CXS), 20 EVENT(CXS),