Complete dummy trace creation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 16:50:14 +0000 (12:50 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 16:50:14 +0000 (12:50 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
.gitignore
include/babeltrace/babeltrace.h
tests/test-dummytrace.c

index 846a20c183f2379b5b4175c4c14c4c73a1fdcc63..8e953fa4fe3ee486ded321ab6b09f7786717431b 100644 (file)
@@ -1,4 +1,4 @@
-tests/test-bitfield
+/tests/test-bitfield
 *.o
 *.a
 *.la
@@ -10,7 +10,7 @@ ctf-lexer.c
 ctf-parser.c
 ctf-parser.h
 ctf-parser-test
-babeltrace
+/converter/babeltrace
 /config.h
 /config.h.in
 /config.status
index fe23fefd7f2730005231ced58fd43a7b59308b42..b4de12f5e973ffcda399545233dae14c12ab6219 100644 (file)
@@ -6,6 +6,11 @@
 #define BABELTRACE_VERSION_MAJOR       0
 #define BABELTRACE_VERSION_MINOR       1
 
+#ifndef __stringify
+#define __stringify_1(a...)    #a
+#define __stringify(a...)      __stringify_1(a)
+#endif
+
 extern int babeltrace_verbose, babeltrace_debug;
 
 #define printf_verbose(fmt, args...)                           \
index 49a650e46ac7ef897fd697e529c83294f0f67732..aa855cc7cd95a2a9a62430e995a20399364d49fd 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * text-to-ctf.c
+ * babeltrace-log.c
  *
- * BabelTrace - Convert Text to CTF
+ * BabelTrace - Convert Text Log to CTF
  *
  * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
 #include <babeltrace/babeltrace.h>
 #include <babeltrace/ctf/types.h>
 
-static const char metadata[] =
+#ifndef UUID_STR_LEN
+#define UUID_STR_LEN   37      /* With \0 */
+#endif
+
+/* Metadata format string */
+static const char metadata_fmt[] =
 "typealias integer { size = 8; align = 8; signed = false; } := uint8_t;\n"
 "typealias integer { size = 32; align = 32; signed = false; } := uint32_t;\n"
 "\n"
 "trace {\n"
 "      major = %s;\n"                  /* major (e.g. 0) */
 "      minor = %s;\n"                  /* minor (e.g. 1) */
-"      uuid = %s;\n"                   /* UUID */
+"      uuid = \"%s\";\n"               /* UUID */
 "      byte_order = %s;\n"             /* be or le */
 "      packet.header := struct {\n"
 "              uint32_t magic;\n"
@@ -66,6 +71,20 @@ int babeltrace_debug, babeltrace_verbose;
 
 static uuid_t s_uuid;
 
+static
+void print_metadata(FILE *fp)
+{
+       char uuid_str[UUID_STR_LEN];
+
+       uuid_unparse(s_uuid, uuid_str);
+       fprintf(fp, metadata_fmt,
+               __stringify(BABELTRACE_VERSION_MAJOR),
+               __stringify(BABELTRACE_VERSION_MINOR),
+               uuid_str,
+               BYTE_ORDER == LITTLE_ENDIAN ? "le" : "be");
+}
+
+
 static
 void write_packet_header(struct ctf_stream_pos *pos, uuid_t uuid)
 {
@@ -188,10 +207,11 @@ static void usage(FILE *fp)
 
 int main(int argc, char **argv)
 {
-       int fd, ret;
+       int fd, metadata_fd, ret;
        char *outputname;
        DIR *dir;
        int dir_fd;
+       FILE *metadata_fp;
 
        if (argc < 2) {
                usage(stdout);
@@ -223,12 +243,34 @@ int main(int argc, char **argv)
                goto error_closedirfd;
        }
 
+       metadata_fd = openat(dir_fd, "metadata", O_RDWR|O_CREAT,
+                            S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+       if (fd < 0) {
+               perror("openat");
+               goto error_closedatastream;
+       }
+       metadata_fp = fdopen(metadata_fd, "w");
+       if (!metadata_fp) {
+               perror("fdopen");
+               goto error_closemetadatafd;
+       }
+
+       uuid_generate(s_uuid);
+       print_metadata(metadata_fp);
        trace_text(stdin, fd);
 
        close(fd);
        exit(EXIT_SUCCESS);
 
        /* error handling */
+error_closemetadatafd:
+       ret = close(metadata_fd);
+       if (ret)
+               perror("close");
+error_closedatastream:
+       ret = close(fd);
+       if (ret)
+               perror("close");
 error_closedirfd:
        ret = close(dir_fd);
        if (ret)
This page took 0.037487 seconds and 4 git commands to generate.