acrntrace: Add opt to specify the cpus where we should capture the data

This patch adds one new option '-a' to specify the cpus where we should
capture the trace data. If the this option is not set or set with wrong
optarg, we will capture the trace data of all possible cpus.

The set of the cpus can be specified as A,B,C, or A-C, or A,D-F, and so on.

Tracked-On: #4175
Acked-by: Yan, Like <like.yan@intel.com>
Signed-off-by: Kaige Fu <kaige.fu@intel.com>
This commit is contained in:
Kaige Fu 2019-11-29 11:00:34 +00:00 committed by wenlingz
parent 366f4be454
commit 9e9e1f61ad
3 changed files with 32 additions and 9 deletions

View File

@ -11,6 +11,7 @@ TRACE_CFLAGS += -Werror
TRACE_CFLAGS += -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
TRACE_CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing
TRACE_CFLAGS += -fpie -fpic
TRACE_CFLAGS += -lnuma
TRACE_CFLAGS += $(CFLAGS)
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)

View File

@ -24,6 +24,7 @@ Options:
-i period specify polling interval in milliseconds [1-999]
-t max_time max time to capture trace data (in second)
-c clear the buffered old data
-a cpu-set only capture the trace data on these configured cpu-set
acrntrace_format.py
===================

View File

@ -19,6 +19,7 @@
#include <pthread.h>
#include <string.h>
#include <signal.h>
#include <numa.h>
#include "acrntrace.h"
@ -29,7 +30,7 @@ static int exiting = 0;
/* for opt */
static uint64_t period = 10000;
static const char optString[] = "i:hct:";
static const char optString[] = "i:hct:a:";
static const char dev_prefix[] = "acrn_trace_";
static uint32_t flags;
@ -38,6 +39,8 @@ static char trace_file_dir[TRACE_FILE_DIR_LEN];
static reader_struct *reader;
static int dev_cnt = 0; /* Count of /dev/acrn_trace_xxx devices */
static struct bitmask *cpu_bitmask = NULL;
static void display_usage(void)
{
printf("acrntrace - tool to collect ACRN trace data\n"
@ -46,7 +49,8 @@ static void display_usage(void)
"\t-h: print this message\n"
"\t-i: period_in_ms: specify polling interval [1-999]\n"
"\t-t: max time to capture trace data (in second)\n"
"\t-c: clear the buffered old data\n");
"\t-c: clear the buffered old data\n"
"\t-a: cpu-set: only capture the trace data on these configured cpu-set\n");
}
static void timer_handler(union sigval sv)
@ -116,6 +120,9 @@ static int parse_opt(int argc, char *argv[])
case 'c':
flags |= FLAG_CLEAR_BUF;
break;
case 'a':
cpu_bitmask = numa_parse_cpustring_all(optarg);
break;
case 'h':
display_usage();
return -EINVAL;
@ -316,8 +323,10 @@ static void handle_on_exit(void)
pr_info("exiting - to release resources...\n");
foreach_dev(dev_id)
destory_reader(&reader[dev_id]);
foreach_dev(dev_id) {
if (numa_bitmask_isbitset(cpu_bitmask, dev_id))
destory_reader(&reader[dev_id]);
}
}
static void signal_exit_handler(int sig)
@ -341,6 +350,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* if we don't set the -a option or set it by mistake, capture the trace on all possible dev */
if (!cpu_bitmask) {
/* numa_bitmask_alloc will cause the process exiting on failure */
cpu_bitmask = numa_bitmask_alloc(dev_cnt);
foreach_dev(dev_id)
numa_bitmask_setbit(cpu_bitmask, dev_id);
}
reader = calloc(1, sizeof(reader_struct) * dev_cnt);
if (!reader) {
pr_err("Failed to allocate reader memory\n");
@ -366,9 +383,11 @@ int main(int argc, char *argv[])
/* acquair res for each trace dev */
flags |= FLAG_TO_REL;
foreach_dev(dev_id)
if (create_reader(&reader[dev_id], dev_id) < 0)
goto out_free;
foreach_dev(dev_id) {
if (numa_bitmask_isbitset(cpu_bitmask, dev_id))
if (create_reader(&reader[dev_id], dev_id) < 0)
goto out_free;
}
/* for kill exit handling */
signal(SIGTERM, signal_exit_handler);
@ -380,8 +399,10 @@ int main(int argc, char *argv[])
printf("q <enter> to quit:\n");
out_free:
foreach_dev(dev_id)
destory_reader(&reader[dev_id]);
foreach_dev(dev_id) {
if (numa_bitmask_isbitset(cpu_bitmask, dev_id))
destory_reader(&reader[dev_id]);
}
free(reader);
flags &= ~FLAG_TO_REL;