[ltt-dev] [BABELTRACE PATCH v2] Optional file pointer to metadata
Julien Desfossez
julien.desfossez at polymtl.ca
Tue Sep 13 21:36:06 EDT 2011
For some use-cases it may be useful to control the file pointer to the
metadata instead of lookup absolutely for a file named "metadata" in the
trace directory. If the pointer is NULL, we fallback to the original
mode.
Signed-off-by: Julien Desfossez <julien.desfossez at polymtl.ca>
---
converter/babeltrace.c | 5 +++--
formats/bt-dummy/bt-dummy.c | 2 +-
formats/ctf-text/ctf-text.c | 4 ++--
formats/ctf/ctf.c | 41 ++++++++++++++++++++++-------------------
include/babeltrace/format.h | 2 +-
5 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/converter/babeltrace.c b/converter/babeltrace.c
index a39c1c4..be54675 100644
--- a/converter/babeltrace.c
+++ b/converter/babeltrace.c
@@ -212,7 +212,8 @@ static int traverse_dir(const char *fpath, const struct stat *sb,
} else {
close(fd);
close(dirfd);
- td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow);
+ td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow,
+ NULL);
if (!td_read) {
fprintf(stdout, "Error opening trace \"%s\" "
"for reading.\n\n", fpath);
@@ -290,7 +291,7 @@ int main(int argc, char **argv)
return 0;
}
- td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL);
+ td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL, NULL);
if (!td_write) {
fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n",
opt_output_path ? : "<none>");
diff --git a/formats/bt-dummy/bt-dummy.c b/formats/bt-dummy/bt-dummy.c
index 0850abb..d7f75fb 100644
--- a/formats/bt-dummy/bt-dummy.c
+++ b/formats/bt-dummy/bt-dummy.c
@@ -41,7 +41,7 @@ int bt_dummy_write_event(struct stream_pos *ppos,
static
struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence))
+ int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c
index fa46a92..f1c1f03 100644
--- a/formats/ctf-text/ctf-text.c
+++ b/formats/ctf-text/ctf-text.c
@@ -36,7 +36,7 @@
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence));
+ int whence), FILE *metadata_fp);
void ctf_text_close_trace(struct trace_descriptor *descriptor);
static
@@ -229,7 +229,7 @@ error:
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence))
+ int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
FILE *fp;
diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
index 93d13e8..f9f9e47 100644
--- a/formats/ctf/ctf.c
+++ b/formats/ctf/ctf.c
@@ -57,7 +57,7 @@ extern int yydebug;
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence));
+ int whence), FILE *metadata_fp);
static
void ctf_close_trace(struct trace_descriptor *descriptor);
@@ -613,7 +613,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence))
+ int whence), FILE *metadata_fp)
{
struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_stream;
@@ -631,23 +631,26 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td,
goto end_stream;
}
- td->metadata = &metadata_stream->parent;
- metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
- if (metadata_stream->pos.fd < 0) {
- fprintf(stdout, "Unable to open metadata.\n");
- return metadata_stream->pos.fd;
- }
+ if (metadata_fp) {
+ fp = metadata_fp;
+ } else {
+ td->metadata = &metadata_stream->parent;
+ metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
+ if (metadata_stream->pos.fd < 0) {
+ fprintf(stdout, "Unable to open metadata.\n");
+ return metadata_stream->pos.fd;
+ }
+ fp = fdopen(metadata_stream->pos.fd, "r");
+ if (!fp) {
+ fprintf(stdout, "[error] Unable to open metadata stream.\n");
+ ret = -errno;
+ goto end_stream;
+ }
+ }
if (babeltrace_debug)
yydebug = 1;
- fp = fdopen(metadata_stream->pos.fd, "r");
- if (!fp) {
- fprintf(stdout, "[error] Unable to open metadata stream.\n");
- ret = -errno;
- goto end_stream;
- }
-
if (packet_metadata(td, fp)) {
ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf);
if (ret)
@@ -1142,7 +1145,7 @@ error:
static
int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence))
+ int whence), FILE *metadata_fp)
{
int ret;
struct dirent *dirent;
@@ -1170,7 +1173,7 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
* Keep the metadata file separate.
*/
- ret = ctf_open_trace_metadata_read(td, move_pos_slow);
+ ret = ctf_open_trace_metadata_read(td, move_pos_slow, metadata_fp);
if (ret) {
goto error_metadata;
}
@@ -1222,7 +1225,7 @@ error:
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence))
+ int whence), FILE *metadata_fp)
{
struct ctf_trace *td;
int ret;
@@ -1235,7 +1238,7 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags,
fprintf(stdout, "[error] Path missing for input CTF trace.\n");
goto error;
}
- ret = ctf_open_trace_read(td, path, flags, move_pos_slow);
+ ret = ctf_open_trace_read(td, path, flags, move_pos_slow, metadata_fp);
if (ret)
goto error;
break;
diff --git a/include/babeltrace/format.h b/include/babeltrace/format.h
index 1b45b4b..5b2f694 100644
--- a/include/babeltrace/format.h
+++ b/include/babeltrace/format.h
@@ -36,7 +36,7 @@ struct format {
struct trace_descriptor *(*open_trace)(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
- int whence));
+ int whence), FILE *metadata_fp);
void (*close_trace)(struct trace_descriptor *descriptor);
};
--
1.7.5.4
More information about the lttng-dev
mailing list