Commit 6da17199 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

trace: add size field to spdk_trace_file



This is more straightforward than using an extra entry in the
lcore_history_offsets array to store the file size. This will also make
more sense if/when we add other types of variable sized data to the trace
files in the future.

The bulk of the changes here are in the trace_record app. We now need to
write out the file_size explicitly to the out_fd.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: I3f22359b23ae5915146142b76e38924568782334
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21791


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 23dbcec5
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -438,7 +438,7 @@ trace_files_aggregate(struct aggr_trace_record_ctx *ctx)
	int flags = O_CREAT | O_EXCL | O_RDWR;
	struct lcore_trace_record_ctx *lcore_port;
	char copy_buff[TRACE_FILE_COPY_SIZE];
	uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE + 1];
	uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE];
	int rc, i;
	ssize_t len = 0;
	uint64_t current_offset;
@@ -454,15 +454,7 @@ trace_files_aggregate(struct aggr_trace_record_ctx *ctx)
		printf("Create trace file %s for output\n", ctx->out_file);
	}

	/* Write flags of histories into head of converged trace file, except num_entriess */
	rc = cont_write(ctx->out_fd, ctx->trace_file,
			sizeof(struct spdk_trace_file) - sizeof(lcore_offsets));
	if (rc < 0) {
		fprintf(stderr, "Failed to write trace header into trace file\n");
		goto out;
	}

	/* Update and append lcore offsets converged trace file */
	/* Calculate lcore offsets for converged trace file */
	current_offset = sizeof(struct spdk_trace_file);
	for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
		lcore_port = &ctx->lcore_ports[i];
@@ -473,8 +465,24 @@ trace_files_aggregate(struct aggr_trace_record_ctx *ctx)
			lcore_offsets[i] = 0;
		}
	}
	lcore_offsets[SPDK_TRACE_MAX_LCORE] = current_offset;

	/* Write size of converged trace file */
	rc = cont_write(ctx->out_fd, &current_offset, sizeof(ctx->trace_file->file_size));
	if (rc < 0) {
		fprintf(stderr, "Failed to write file size into trace file\n");
		goto out;
	}

	/* Write rest of metadata (spdk_trace_file) of converged trace file */
	rc = cont_write(ctx->out_fd, &ctx->trace_file->tsc_rate,
			sizeof(struct spdk_trace_file) - sizeof(lcore_offsets) -
			sizeof(ctx->trace_file->file_size));
	if (rc < 0) {
		fprintf(stderr, "Failed to write metadata into trace file\n");
		goto out;
	}

	/* Write lcore offsets of converged trace file */
	rc = cont_write(ctx->out_fd, lcore_offsets, sizeof(lcore_offsets));
	if (rc < 0) {
		fprintf(stderr, "Failed to write lcore offsets into trace file\n");
+4 −5
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ struct spdk_trace_history {
#define SPDK_TRACE_MAX_LCORE		128

struct spdk_trace_file {
	uint64_t			file_size;
	uint64_t			tsc_rate;
	uint64_t			tpoint_mask[SPDK_TRACE_MAX_GROUP_ID];
	char				tname[SPDK_TRACE_MAX_LCORE][SPDK_TRACE_THREAD_NAME_LEN];
@@ -123,10 +124,8 @@ struct spdk_trace_file {
	struct spdk_trace_object	object[UCHAR_MAX + 1];
	struct spdk_trace_tpoint	tpoint[SPDK_TRACE_MAX_TPOINT_ID];

	/** Offset of each trace_history from the beginning of this data structure.
	 * The last one is the offset of the file end.
	 */
	uint64_t			lcore_history_offsets[SPDK_TRACE_MAX_LCORE + 1];
	/** Offset of each trace_history from the beginning of this data structure. */
	uint64_t			lcore_history_offsets[SPDK_TRACE_MAX_LCORE];

	/**
	 * struct spdk_trace_history has a dynamic size determined by num_entries
@@ -147,7 +146,7 @@ spdk_get_trace_history_size(uint64_t num_entries)
static inline uint64_t
spdk_get_trace_file_size(struct spdk_trace_file *trace_file)
{
	return trace_file->lcore_history_offsets[SPDK_TRACE_MAX_LCORE];
	return trace_file->file_size;
}

static inline struct spdk_trace_history *
+3 −5
Original line number Diff line number Diff line
@@ -229,8 +229,8 @@ int
spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads)
{
	uint32_t i = 0, max_dedicated_cpu = 0;
	int file_size;
	uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE + 1] = { 0 };
	uint64_t file_size;
	uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE] = { 0 };
	struct spdk_cpuset cpuset = {};

	/* 0 entries requested - skip trace initialization */
@@ -271,8 +271,6 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
		file_size += spdk_get_trace_history_size(num_entries);
	}

	lcore_offsets[SPDK_TRACE_MAX_LCORE] = file_size;

	snprintf(g_shm_name, sizeof(g_shm_name), "%s", shm_name);

	g_trace_fd = shm_open(shm_name, O_RDWR | O_CREAT, 0600);
@@ -329,7 +327,7 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
		lcore_history->lcore = i;
		lcore_history->num_entries = num_entries;
	}
	g_trace_file->lcore_history_offsets[SPDK_TRACE_MAX_LCORE] = lcore_offsets[SPDK_TRACE_MAX_LCORE];
	g_trace_file->file_size = file_size;

	spdk_trace_flags_init();

+3 −2
Original line number Diff line number Diff line
@@ -301,8 +301,9 @@ class CTracepoint(ct.Structure):
                ('related_objects', CTpointRelatedObject * TRACE_MAX_RELATIONS)]


class CTraceFlags(ct.Structure):
    _fields_ = [('tsc_rate', ct.c_uint64),
class CTraceFile(ct.Structure):
    _fields_ = [('file_size', ct.c_uint64),
                ('tsc_rate', ct.c_uint64),
                ('tpoint_mask', ct.c_uint64 * TRACE_MAX_GROUP_ID),
                ('owner', CTraceOwner * (UCHAR_MAX + 1)),
                ('object', CTraceObject * (UCHAR_MAX + 1)),