[ltt-dev] [BABELTRACE PATCH] Specify callback to move packet in open_trace

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Sep 13 17:54:04 EDT 2011


* Julien Desfossez (julien.desfossez at polymtl.ca) wrote:
> This patch adds a new parameter to open_trace to allow the user to
> specify the function to call when babeltrace needs to switch packet.
> This patch is a first step for the mmap reading code integration.
> 
> Signed-off-by: Julien Desfossez <julien.desfossez at polymtl.ca>

you are on fire today! ;)

Merged, thanks!

Mathieu


> ---
>  converter/babeltrace.c         |    4 +-
>  formats/bt-dummy/bt-dummy.c    |    4 ++-
>  formats/ctf-text/ctf-text.c    |    8 +++++-
>  formats/ctf/ctf.c              |   44 ++++++++++++++++++++++++++++++++-------
>  include/babeltrace/ctf/types.h |    2 +
>  include/babeltrace/format.h    |    5 +++-
>  6 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/converter/babeltrace.c b/converter/babeltrace.c
> index 5c37242..a39c1c4 100644
> --- a/converter/babeltrace.c
> +++ b/converter/babeltrace.c
> @@ -212,7 +212,7 @@ 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);
> +		td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow);
>  		if (!td_read) {
>  			fprintf(stdout, "Error opening trace \"%s\" "
>  					"for reading.\n\n", fpath);
> @@ -290,7 +290,7 @@ int main(int argc, char **argv)
>  		return 0;
>  	}
>  
> -	td_write = fmt_write->open_trace(opt_output_path, O_RDWR);
> +	td_write = fmt_write->open_trace(opt_output_path, O_RDWR, 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 41cfb74..0850abb 100644
> --- a/formats/bt-dummy/bt-dummy.c
> +++ b/formats/bt-dummy/bt-dummy.c
> @@ -39,7 +39,9 @@ int bt_dummy_write_event(struct stream_pos *ppos,
>  }
>  
>  static
> -struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags)
> +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))
>  {
>  	struct ctf_text_stream_pos *pos;
>  
> diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c
> index f1ddbaf..fa46a92 100644
> --- a/formats/ctf-text/ctf-text.c
> +++ b/formats/ctf-text/ctf-text.c
> @@ -34,7 +34,9 @@
>  #include <unistd.h>
>  #include <stdlib.h>
>  
> -struct trace_descriptor *ctf_text_open_trace(const char *path, int flags);
> +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));
>  void ctf_text_close_trace(struct trace_descriptor *descriptor);
>  
>  static
> @@ -225,7 +227,9 @@ error:
>  }
>  
>  
> -struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
> +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))
>  {
>  	struct ctf_text_stream_pos *pos;
>  	FILE *fp;
> diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
> index 0d1418c..93d13e8 100644
> --- a/formats/ctf/ctf.c
> +++ b/formats/ctf/ctf.c
> @@ -55,7 +55,9 @@
>  extern int yydebug;
>  
>  static
> -struct trace_descriptor *ctf_open_trace(const char *path, int flags);
> +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));
>  static
>  void ctf_close_trace(struct trace_descriptor *descriptor);
>  
> @@ -609,7 +611,9 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
>  }
>  
>  static
> -int ctf_open_trace_metadata_read(struct ctf_trace *td)
> +int ctf_open_trace_metadata_read(struct ctf_trace *td,
> +		void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
> +			int whence))
>  {
>  	struct ctf_scanner *scanner;
>  	struct ctf_file_stream *metadata_stream;
> @@ -618,6 +622,15 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td)
>  	int ret = 0;
>  
>  	metadata_stream = g_new0(struct ctf_file_stream, 1);
> +
> +	if (move_pos_slow) {
> +		metadata_stream->pos.move_pos_slow = move_pos_slow;
> +	} else {
> +		fprintf(stderr, "[error] move_pos_slow function undefined.\n");
> +		ret = -1;
> +		goto end_stream;
> +	}
> +
>  	td->metadata = &metadata_stream->parent;
>  	metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
>  	if (metadata_stream->pos.fd < 0) {
> @@ -1083,7 +1096,9 @@ error:
>   * description (metadata).
>   */
>  static
> -int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
> +int ctf_open_file_stream_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 ret;
>  	struct ctf_file_stream *file_stream;
> @@ -1092,6 +1107,15 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
>  	if (ret < 0)
>  		goto error;
>  	file_stream = g_new0(struct ctf_file_stream, 1);
> +
> +	if (move_pos_slow) {
> +		file_stream->pos.move_pos_slow = move_pos_slow;
> +	} else {
> +		fprintf(stderr, "[error] move_pos_slow function undefined.\n");
> +		ret = -1;
> +		goto error_def;
> +	}
> +
>  	ctf_init_pos(&file_stream->pos, ret, flags);
>  	ret = create_trace_definitions(td, &file_stream->parent);
>  	if (ret)
> @@ -1116,7 +1140,9 @@ error:
>  }
>  
>  static
> -int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
> +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 ret;
>  	struct dirent *dirent;
> @@ -1144,7 +1170,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);
> +	ret = ctf_open_trace_metadata_read(td, move_pos_slow);
>  	if (ret) {
>  		goto error_metadata;
>  	}
> @@ -1173,7 +1199,7 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
>  				|| !strcmp(diriter->d_name, "..")
>  				|| !strcmp(diriter->d_name, "metadata"))
>  			continue;
> -		ret = ctf_open_file_stream_read(td, diriter->d_name, flags);
> +		ret = ctf_open_file_stream_read(td, diriter->d_name, flags, move_pos_slow);
>  		if (ret) {
>  			fprintf(stdout, "[error] Open file stream error.\n");
>  			goto readdir_error;
> @@ -1194,7 +1220,9 @@ error:
>  }
>  
>  static
> -struct trace_descriptor *ctf_open_trace(const char *path, int flags)
> +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))
>  {
>  	struct ctf_trace *td;
>  	int ret;
> @@ -1207,7 +1235,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);
> +		ret = ctf_open_trace_read(td, path, flags, move_pos_slow);
>  		if (ret)
>  			goto error;
>  		break;
> diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h
> index 54fd846..60749a6 100644
> --- a/include/babeltrace/ctf/types.h
> +++ b/include/babeltrace/ctf/types.h
> @@ -60,6 +60,8 @@ struct ctf_stream_pos {
>  	char *base;		/* mmap base address */
>  	ssize_t offset;		/* offset from base, in bits. EOF for end of file. */
>  	size_t cur_index;	/* current index in packet index */
> +	void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
> +			int whence); /* function called to switch packet */
>  
>  	int dummy;		/* dummy position, for length calculation */
>  	struct bt_stream_callbacks *cb;	/* Callbacks registered for iterator. */
> diff --git a/include/babeltrace/format.h b/include/babeltrace/format.h
> index c50b28d..1b45b4b 100644
> --- a/include/babeltrace/format.h
> +++ b/include/babeltrace/format.h
> @@ -22,6 +22,7 @@
>   */
>  
>  #include <babeltrace/types.h>
> +#include <babeltrace/ctf/types.h>
>  #include <stdint.h>
>  #include <stdio.h>
>  #include <glib.h>
> @@ -33,7 +34,9 @@ struct trace_descriptor {
>  struct format {
>  	GQuark name;
>  
> -	struct trace_descriptor *(*open_trace)(const char *path, int flags);
> +	struct trace_descriptor *(*open_trace)(const char *path, int flags,
> +			void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
> +				int whence));
>  	void (*close_trace)(struct trace_descriptor *descriptor);
>  };
>  
> -- 
> 1.7.5.4
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list