aboutsummaryrefslogtreecommitdiff
path: root/trace.c
diff options
context:
space:
mode:
authorTuukka Tikkanen <tuukka.tikkanen@linaro.org>2015-01-21 00:44:32 +0200
committerTuukka Tikkanen <tuukka.tikkanen@linaro.org>2015-01-21 00:44:32 +0200
commit6efac9bed0ec6b7a2e9abc8872e03245d4918f06 (patch)
tree37455aa61d15feed236f2db5e7e12b25c0981de5 /trace.c
parent7d3394ec671ee1f4a80080dcdaac31ed2247a24d (diff)
Idlestat: Add command line options for managing trace buffer
As the kernel trace buffer is a finite resource, the default trace buffer size idlestat sets may either be impossibly large or insufficient to hold the data. This patch adds two new command line options to control buffer size and whether or not it will be polled during the trace period. The polling functionality while tracing is not yet implemented. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
Diffstat (limited to 'trace.c')
-rw-r--r--trace.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/trace.c b/trace.c
index 09f9573..f365032 100644
--- a/trace.c
+++ b/trace.c
@@ -36,6 +36,7 @@
#include <fts.h>
#include "trace.h"
+#include "idlestat.h"
#include "utils.h"
#include "list.h"
@@ -163,9 +164,13 @@ cannot_get_event_options:
return ptrerror(NULL);
}
-int idlestat_init_trace(unsigned int duration)
+int calculate_buffer_parameters(unsigned int duration,
+ struct trace_buffer_settings *tbs)
{
- int bufsize;
+ unsigned int def_bufsize;
+
+ if (tbs->poll_interval == 0)
+ tbs->poll_interval = duration;
/* Assuming the worst case where we can have for cpuidle,
* TRACE_IDLE_NRHITS_PER_SEC. Each state enter/exit line are
@@ -175,17 +180,50 @@ int idlestat_init_trace(unsigned int duration)
* Divide by 2^10 to have Kb. We add 1Kb to be sure to round up.
*/
- bufsize = 2 * TRACE_IDLE_LENGTH * TRACE_IDLE_NRHITS_PER_SEC;
- bufsize += TRACE_CPUFREQ_LENGTH * TRACE_CPUFREQ_NRHITS_PER_SEC;
- bufsize = (bufsize * duration / (1 << 10)) + 1;
+ if (tbs->percpu_buffer_size == 0) {
+ def_bufsize = 2 * TRACE_IDLE_LENGTH;
+ def_bufsize *= TRACE_IDLE_NRHITS_PER_SEC;
+ def_bufsize += TRACE_CPUFREQ_LENGTH *
+ TRACE_CPUFREQ_NRHITS_PER_SEC;
+ def_bufsize = (def_bufsize * tbs->poll_interval / (1 << 10));
+ def_bufsize += 1;
+
+ tbs->percpu_buffer_size = def_bufsize;
+ }
+
+ if (tbs->poll_interval >= duration) {
+ verbose_printf(1,
+ "Polling is disabled during trace "
+ "(polling interval exceeds trace duration).\n");
+ } else {
+ verbose_printf(1, "Polling interval: %u s\n",
+ tbs->poll_interval);
+ }
+ verbose_printf(1, "Per cpu trace buffer: %u kB\n",
+ tbs->percpu_buffer_size);
+
+ return 0;
+}
- if (write_int(TRACE_BUFFER_SIZE_PATH, bufsize))
+int idlestat_init_trace(unsigned int percpu_bufsize)
+{
+ int bufsize = (int)percpu_bufsize;
+
+ if (write_int(TRACE_BUFFER_SIZE_PATH, bufsize)) {
+ fprintf(stderr,
+ "Failed to set trace buffer to desired size. If the "
+ "error was caused by failure in memory allocation, "
+ "try to increase buffer size (-S, --buffer-size) "
+ "or decrease polling interval "
+ "(-I, --polling-interval).\n"
+ "Increase verbosity (-v) to see current values\n");
return -1;
+ }
if (read_int(TRACE_BUFFER_TOTAL_PATH, &bufsize))
return -1;
- printf("Total trace buffer: %d kB\n", bufsize);
+ verbose_printf(1, "Total trace buffer: %d kB\n", bufsize);
/* Disable all the traces */
if (write_int(TRACE_EVENT_PATH, 0))