From 842c2b97eab577484edae763770dfd1440490818 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Mon, 30 Jan 2012 17:25:50 -0500 Subject: [PATCH] API : trace_handle Add the trace_handle structure to allow the user to manipulate a trace. Will be useful for getting information on specific trace files and remove traces from a trace_collection without rebuilding the trace_collection entirely. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- include/Makefile.am | 6 +- include/babeltrace/context.h | 1 + include/babeltrace/trace-handle-internal.h | 53 ++++++++++++++++ include/babeltrace/trace-handle.h | 53 ++++++++++++++++ lib/Makefile.am | 3 +- lib/context.c | 1 + lib/trace-handle.c | 70 ++++++++++++++++++++++ 7 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 include/babeltrace/trace-handle-internal.h create mode 100644 include/babeltrace/trace-handle.h create mode 100644 lib/trace-handle.c diff --git a/include/Makefile.am b/include/Makefile.am index b5d26808..1dfa218b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -2,7 +2,8 @@ babeltraceinclude_HEADERS = \ babeltrace/babeltrace.h \ babeltrace/format.h \ babeltrace/context.h \ - babeltrace/iterator.h + babeltrace/iterator.h \ + babeltrace/trace-handle.h noinst_HEADERS = \ @@ -18,4 +19,5 @@ noinst_HEADERS = \ babeltrace/ctf-ir/metadata.h \ babeltrace/ctf/metadata.h \ babeltrace/ctf-text/types.h \ - babeltrace/ctf/types.h + babeltrace/ctf/types.h \ + babeltrace/trace-handle-internal.h diff --git a/include/babeltrace/context.h b/include/babeltrace/context.h index 55fe2313..445af4f3 100644 --- a/include/babeltrace/context.h +++ b/include/babeltrace/context.h @@ -35,6 +35,7 @@ struct trace_collection; struct bt_context { struct trace_collection *tc; int refcount; + int last_trace_handle_id; }; /* diff --git a/include/babeltrace/trace-handle-internal.h b/include/babeltrace/trace-handle-internal.h new file mode 100644 index 00000000..9351367d --- /dev/null +++ b/include/babeltrace/trace-handle-internal.h @@ -0,0 +1,53 @@ +#ifndef _BABELTRACE_TRACE_HANDLE_INTERNAL_H +#define _BABELTRACE_TRACE_HANDLE_INTERNAL_H + +/* + * BabelTrace + * + * Internal trace handle header + * + * Copyright 2012 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers + * Julien Desfossez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include +#include + +/* + * trace_handle : unique identifier of a trace + * + * The trace_handle allows the user to manipulate a trace file directly. + * It is a unique identifier representing a trace file. + */ +struct bt_trace_handle { + int id; + char *path; + uint64_t timestamp_begin; + uint64_t timestamp_end; +}; + +/* + * bt_trace_handle_create : allocates a trace_handle + * + * Returns a newly allocated trace_handle or NULL on error + */ +struct bt_trace_handle *bt_trace_create_handle(struct bt_context *ctx); + +/* + * bt_trace_handle_destroy : free a trace_handle + */ +void bt_trace_handle_destroy(struct bt_trace_handle *bt); + +#endif /* _BABELTRACE_TRACE_HANDLE_INTERNAL_H */ diff --git a/include/babeltrace/trace-handle.h b/include/babeltrace/trace-handle.h new file mode 100644 index 00000000..5900cc14 --- /dev/null +++ b/include/babeltrace/trace-handle.h @@ -0,0 +1,53 @@ +#ifndef _BABELTRACE_TRACE_HANDLE_H +#define _BABELTRACE_TRACE_HANDLE_H + +/* + * BabelTrace + * + * trace_handle header + * + * Copyright 2012 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers + * Julien Desfossez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include + +/* + * trace_handle : unique identifier of a trace + * + * The trace_handle allows the user to manipulate a trace file directly. + * It is a unique identifier representing a trace file. + */ +struct bt_trace_handle; + +/* + * bt_trace_handle_get_path : returns the path of a trace_handle or + * NULL on error + */ +char *bt_trace_handle_get_path(struct bt_trace_handle *th); + +/* + * bt_trace_handle_get_timestamp_begin : returns the beginning timestamp + * of a trace or -1ULL on error + */ +uint64_t bt_trace_handle_get_timestamp_begin(struct bt_trace_handle *th); + +/* + * bt_trace_handle_get_timestamp_end : returns the end timestamp of a trace + * or -1ULL on error + */ +uint64_t bt_trace_handle_get_timestamp_end(struct bt_trace_handle *th); + +#endif /* _BABELTRACE_TRACE_HANDLE_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index cb3597d7..26f024b4 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,7 +7,8 @@ lib_LTLIBRARIES = libbabeltrace.la libbabeltrace_la_SOURCES = babeltrace.c \ callbacks.c \ iterator.c \ - context.c + context.c \ + trace-handle.c libbabeltrace_la_LIBADD = \ $(top_builddir)/types/libbabeltrace_types.la \ diff --git a/lib/context.c b/lib/context.c index 36efc9d0..48cf216e 100644 --- a/lib/context.c +++ b/lib/context.c @@ -35,6 +35,7 @@ struct bt_context *bt_context_create(struct trace_collection *tc) ctx->tc = tc; ctx->refcount = 1; + ctx->last_trace_handle_id = 0; return ctx; diff --git a/lib/trace-handle.c b/lib/trace-handle.c new file mode 100644 index 00000000..fce2397c --- /dev/null +++ b/lib/trace-handle.c @@ -0,0 +1,70 @@ +/* + * trace_handle.c + * + * Babeltrace Library + * + * Copyright 2012 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers + * Julien Desfossez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include +#include +#include +#include +#include +#include + +struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx) +{ + struct bt_trace_handle *th; + + th = calloc(1, sizeof(struct bt_trace_handle)); + if (!th) { + perror("allocating trace_handle"); + return NULL; + } + if (!ctx) + return NULL; + + th->id = ctx->last_trace_handle_id++; + return th; +} + +void bt_trace_handle_destroy(struct bt_trace_handle *bt) +{ + if (bt) + free(bt); +} + +char *bt_trace_handle_get_path(struct bt_trace_handle *th) +{ + if (th && th->path) + return th->path; + return NULL; +} + +uint64_t bt_trace_handle_get_timestamp_begin(struct bt_trace_handle *th) +{ + if (th) + return th->timestamp_begin; + return -1ULL; +} + +uint64_t bt_trace_handle_get_timestamp_end(struct bt_trace_handle *th) +{ + if (th) + return th->timestamp_end; + return -1ULL; +} -- 2.34.1