Commit ae9c7242 authored by Alexey Bayduraev's avatar Alexey Bayduraev Committed by Arnaldo Carvalho de Melo
Browse files

perf record: Introduce bytes written stats



Introduce a function to calculate the total amount of data written
and use it to support the --max-size option.

Reviewed-by: default avatarRiccardo Mancini <rickyman7@gmail.com>
Signed-off-by: default avatarAlexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Tested-by: default avatarJiri Olsa <jolsa@kernel.org>
Tested-by: default avatarRiccardo Mancini <rickyman7@gmail.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/3e2c69186641446f8ab003ec209bccc762b3394d.1642440724.git.alexey.v.bayduraev@linux.intel.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 56f735ff
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ struct record_thread {
	struct record		*rec;
	unsigned long long	samples;
	unsigned long		waking;
	u64			bytes_written;
};

static __thread struct record_thread *thread;
@@ -194,10 +195,22 @@ static bool switch_output_time(struct record *rec)
	       trigger_is_ready(&switch_output_trigger);
}

static u64 record__bytes_written(struct record *rec)
{
	int t;
	u64 bytes_written = rec->bytes_written;
	struct record_thread *thread_data = rec->thread_data;

	for (t = 0; t < rec->nr_threads; t++)
		bytes_written += thread_data[t].bytes_written;

	return bytes_written;
}

static bool record__output_max_size_exceeded(struct record *rec)
{
	return rec->output_max_size &&
	       (rec->bytes_written >= rec->output_max_size);
	       (record__bytes_written(rec) >= rec->output_max_size);
}

static int record__write(struct record *rec, struct mmap *map __maybe_unused,
@@ -213,13 +226,15 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,
		return -1;
	}

	if (!(map && map->file))
	if (map && map->file)
		thread->bytes_written += size;
	else
		rec->bytes_written += size;

	if (record__output_max_size_exceeded(rec) && !done) {
		fprintf(stderr, "[ perf record: perf size limit reached (%" PRIu64 " KB),"
				" stopping session ]\n",
				rec->bytes_written >> 10);
				record__bytes_written(rec) >> 10);
		done = 1;
	}