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@polymtl.ca>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
} else {
close(fd);
close(dirfd);
} 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);
if (!td_read) {
fprintf(stdout, "Error opening trace \"%s\" "
"for reading.\n\n", fpath);
- 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>");
if (!td_write) {
fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n",
opt_output_path ? : "<none>");
-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;
{
struct ctf_text_stream_pos *pos;
#include <unistd.h>
#include <stdlib.h>
#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
void ctf_text_close_trace(struct trace_descriptor *descriptor);
static
-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;
{
struct ctf_text_stream_pos *pos;
FILE *fp;
extern int yydebug;
static
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);
static
void ctf_close_trace(struct trace_descriptor *descriptor);
-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;
{
struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_stream;
int ret = 0;
metadata_stream = g_new0(struct ctf_file_stream, 1);
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) {
td->metadata = &metadata_stream->parent;
metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
if (metadata_stream->pos.fd < 0) {
* description (metadata).
*/
static
* 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;
{
int ret;
struct ctf_file_stream *file_stream;
if (ret < 0)
goto error;
file_stream = g_new0(struct ctf_file_stream, 1);
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)
ctf_init_pos(&file_stream->pos, ret, flags);
ret = create_trace_definitions(td, &file_stream->parent);
if (ret)
-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;
{
int ret;
struct dirent *dirent;
* Keep the metadata file separate.
*/
* 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;
}
if (ret) {
goto error_metadata;
}
|| !strcmp(diriter->d_name, "..")
|| !strcmp(diriter->d_name, "metadata"))
continue;
|| !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;
if (ret) {
fprintf(stdout, "[error] Open file stream error.\n");
goto readdir_error;
-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;
{
struct ctf_trace *td;
int ret;
fprintf(stdout, "[error] Path missing for input CTF trace.\n");
goto error;
}
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;
if (ret)
goto error;
break;
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 */
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. */
int dummy; /* dummy position, for length calculation */
struct bt_stream_callbacks *cb; /* Callbacks registered for iterator. */
*/
#include <babeltrace/types.h>
*/
#include <babeltrace/types.h>
+#include <babeltrace/ctf/types.h>
#include <stdint.h>
#include <stdio.h>
#include <glib.h>
#include <stdint.h>
#include <stdio.h>
#include <glib.h>
struct format {
GQuark name;
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);
};
void (*close_trace)(struct trace_descriptor *descriptor);
};