예제 #1
0
파일: traceset.c 프로젝트: adannis/lttv
/*
 * lttv_trace_create : Create a trace from a path
 *
 * ts is the traceset in which will be contained the trace
 *
 * path is the path where to find a trace. It is not recursive.
 *
 * This function is static since a trace should always be contained in a
 * traceset.
 *
 * return the created trace or NULL on failure
 */
static LttvTrace *lttv_trace_create(LttvTraceset *ts, const char *path)
{
	int id = bt_context_add_trace(lttv_traceset_get_context(ts),
		path,
		"ctf",
		NULL,
		NULL,
		NULL);
	if (id < 0) {
		return NULL;
	}
	// Create the trace and save the trace handle id returned by babeltrace
	LttvTrace *new_trace;

	new_trace = g_new(LttvTrace, 1);
	new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
	new_trace->id = id;
	new_trace->ref_count = 0;
	new_trace->short_name[0] = '\0';
	new_trace->traceset = ts;
	new_trace->state = g_new(LttvTraceState,1);
	lttv_trace_state_init(new_trace->state,new_trace);

	/* Add the state to the trace_handle to state index */
	g_ptr_array_set_size(ts->state_trace_handle_index,id+1);
	g_ptr_array_index(ts->state_trace_handle_index,id) = new_trace->state;

	/* Find common path */
	if (ts->common_path == NULL) {
		ts->common_path = strdup(path);
	} else {
		/* TODO ybrosseau 2013-05-24: consider put that in a function */
		int i,j;
		for (i = 0; 
		     ts->common_path != '\0'; 
		     i++) {
			if (path[i] != ts->common_path[i]) {
				/* The common path has changed, redo the other traces */
				for(j = 0; j < ts->traces->len; j++) {
					LttvTrace *t = g_ptr_array_index(ts->traces, j);
					strncpy(t->short_name, t->full_path+i, TRACE_NAME_SIZE);
				}

				break;
			}	
		}
		strncpy(new_trace->short_name, path+i, TRACE_NAME_SIZE);
	}
	new_trace->full_path = strdup(path);

	return new_trace;
}
예제 #2
0
파일: ctf.c 프로젝트: phausler/binutils
static void
ctf_open_dir (const char *dirname)
{
  struct bt_iter_pos begin_pos;
  struct bt_iter_pos *pos;
  unsigned int count, i;
  struct bt_ctf_event_decl * const *list;

  ctx = bt_context_create ();
  if (ctx == NULL)
    error (_("Unable to create bt_context"));
  handle_id = bt_context_add_trace (ctx, dirname, "ctf", NULL, NULL, NULL);
  if (handle_id < 0)
    {
      ctf_destroy ();
      error (_("Unable to use libbabeltrace on directory \"%s\""),
	     dirname);
    }

  begin_pos.type = BT_SEEK_BEGIN;
  ctf_iter = bt_ctf_iter_create (ctx, &begin_pos, NULL);
  if (ctf_iter == NULL)
    {
      ctf_destroy ();
      error (_("Unable to create bt_iterator"));
    }

  /* Look for the declaration of register block.  Get the length of
     array "contents" to set trace_regblock_size.  */

  bt_ctf_get_event_decl_list (handle_id, ctx, &list, &count);
  for (i = 0; i < count; i++)
    if (strcmp ("register", bt_ctf_get_decl_event_name (list[i])) == 0)
      {
	unsigned int j;
	const struct bt_ctf_field_decl * const *field_list;
	const struct bt_declaration *decl;

	bt_ctf_get_decl_fields (list[i], BT_EVENT_FIELDS, &field_list,
				&count);

	gdb_assert (count == 1);
	gdb_assert (0 == strcmp ("contents",
				 bt_ctf_get_decl_field_name (field_list[0])));
	decl = bt_ctf_get_decl_from_field_decl (field_list[0]);
	trace_regblock_size = bt_ctf_get_array_len (decl);

	break;
      }
}
예제 #3
0
struct bt_context *create_context_with_path(const char *path)
{
	struct bt_context *ctx;
	int ret;

	ctx = bt_context_create();
	if (!ctx) {
		return NULL;
	}

	ret = bt_context_add_trace(ctx, path, "ctf", NULL, NULL, NULL);
	if (ret < 0) {
		bt_context_put(ctx);
		return NULL;
	}
	return ctx;
}
예제 #4
0
/*
 * bt_context_add_traces_recursive: Open a trace recursively
 *
 * Find each trace present in the subdirectory starting from the given
 * path, and add them to the context. The packet_seek parameter can be
 * NULL: this specify to use the default format packet_seek.
 *
 * Return: 0 on success, < 0 on failure, > 0 on partial failure.
 * Unable to open toplevel: failure.
 * Unable to open some subdirectory or file: warn and continue (partial
 * failure);
 */
int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path,
		const char *format_str,
		void (*packet_seek)(struct bt_stream_pos *pos,
			size_t offset, int whence))
{
	int ret = 0, trace_ids = 0;

	if ((strncmp(path, NET4_URL_PREFIX, sizeof(NET4_URL_PREFIX) - 1)) == 0 ||
			(strncmp(path, NET6_URL_PREFIX, sizeof(NET6_URL_PREFIX) - 1)) == 0 ||
			(strncmp(path, NET_URL_PREFIX, sizeof(NET_URL_PREFIX) - 1)) == 0) {
		ret = bt_context_add_trace(ctx,
				path, format_str, packet_seek, NULL, NULL);
		if (ret < 0) {
			fprintf(stderr, "[warning] [Context] cannot open trace \"%s\" "
					"for reading.\n", path);
		}
		return ret;
	}
	/* Should lock traversed_paths mutex here if used in multithread */

	traversed_paths = g_ptr_array_new();
	ret = nftw(path, traverse_trace_dir, 10, 0);

	/* Process the array if ntfw did not return a fatal error */
	if (ret >= 0) {
		int i;

		for (i = 0; i < traversed_paths->len; i++) {
			GString *trace_path = g_ptr_array_index(traversed_paths,
								i);
			int trace_id = bt_context_add_trace(ctx,
							    trace_path->str,
							    format_str,
							    packet_seek,
							    NULL,
							    NULL);
			if (trace_id < 0) {
				fprintf(stderr, "[warning] [Context] cannot open trace \"%s\" from %s "
					"for reading.\n", trace_path->str, path);
				/* Allow to skip erroneous traces. */
				ret = 1;	/* partial error */
			} else {
				trace_ids++;
			}
			g_string_free(trace_path, TRUE);
		}
	}

	g_ptr_array_free(traversed_paths, TRUE);
	traversed_paths = NULL;

	/* Should unlock traversed paths mutex here if used in multithread */

	/*
	 * Return an error if no trace can be opened.
	 */
	if (trace_ids == 0) {
		fprintf(stderr, "[error] Cannot open any trace for reading.\n\n");
		ret = -ENOENT;		/* failure */
	}
	return ret;
}