Trace library exposes --trace EAL parameter to enable trace points.
Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Acked-by: David Marchand <david.marchand@redhat.com>
Can be specified multiple times.
+* ``--trace=<regex-match>``
+
+ Enable trace based on regular expression trace name. By default, the trace is
+ disabled. User must specify this option to enable trace.
+ For example:
+
+ Global trace configuration for EAL only::
+
+ --trace=eal
+
+ Global trace configuration for ALL the components::
+
+ --trace=.*
+
+ Can be specified multiple times up to 32 times.
+
Other options
~~~~~~~~~~~~~
#include "eal_options.h"
#include "eal_filesystem.h"
#include "eal_private.h"
+#include "eal_trace.h"
#define BITS_PER_HEX 4
#define LCORE_OPT_LST 1
{OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
{OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
{OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
+ {OPT_TRACE, 1, NULL, OPT_TRACE_NUM },
{OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
{OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
}
break;
}
+
+ case OPT_TRACE_NUM: {
+ if (eal_trace_args_save(optarg) < 0) {
+ RTE_LOG(ERR, EAL, "invalid parameters for --"
+ OPT_TRACE "\n");
+ return -1;
+ }
+ break;
+ }
+
case OPT_LCORES_NUM:
if (eal_parse_lcores(optarg) < 0) {
RTE_LOG(ERR, EAL, "invalid parameter for --"
" --"OPT_LOG_LEVEL"=<int> Set global log level\n"
" --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
" Set specific log level\n"
+ " --"OPT_TRACE"=<regex-match>\n"
+ " Enable trace based on regular expression trace name.\n"
+ " By default, the trace is disabled.\n"
+ " User must specify this option to enable trace.\n"
" -v Display version information on startup\n"
" -h, --help This help\n"
" --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
int
eal_trace_init(void)
{
+ uint8_t i;
+
/* Trace memory should start with 8B aligned for natural alignment */
RTE_BUILD_BUG_ON((offsetof(struct __rte_trace_header, mem) % 8) != 0);
goto fail;
}
+ if (trace.args.nb_args)
+ trace.status = true;
+
if (!rte_trace_is_enabled())
return 0;
if (trace_epoch_time_save() < 0)
goto fail;
+ /* Apply global configurations */
+ for (i = 0; i < trace.args.nb_args; i++)
+ trace_args_apply(trace.args.args[i]);
+
rte_trace_mode_set(trace.mode);
return 0;
return;
trace_mem_per_thread_free();
trace_metadata_destroy();
+ eal_trace_args_free();
}
bool
return -rte_errno;
}
+int
+eal_trace_args_save(const char *optarg)
+{
+ struct trace *trace = trace_obj_get();
+ char *trace_args;
+ uint8_t nb_args;
+
+ nb_args = trace->args.nb_args;
+
+ if (nb_args >= TRACE_MAX_ARGS) {
+ trace_err("ignoring trace %s as limit exceeds", optarg);
+ return 0;
+ }
+
+ trace_args = calloc(1, (strlen(optarg) + 1));
+ if (trace_args == NULL) {
+ trace_err("fail to allocate memory for %s", optarg);
+ return -ENOMEM;
+ }
+
+ memcpy(trace_args, optarg, strlen(optarg));
+ trace->args.args[nb_args++] = trace_args;
+ trace->args.nb_args = nb_args;
+ return 0;
+}
+
+void
+eal_trace_args_free(void)
+{
+ struct trace *trace = trace_obj_get();
+ int i;
+
+ for (i = 0; i < trace->args.nb_args; i++) {
+ if (trace->args.args[i]) {
+ free((void *)trace->args.args[i]);
+ trace->args.args[i] = NULL;
+ }
+ }
+}
+
+int
+trace_args_apply(const char *arg)
+{
+ char *str;
+
+ str = strdup(arg);
+ if (str == NULL)
+ return -1;
+
+ if (rte_trace_regexp(str, true) < 0) {
+ trace_err("cannot enable trace for %s", str);
+ free(str);
+ return -1;
+ }
+
+ free(str);
+ return 0;
+}
+
int
trace_epoch_time_save(void)
{
OPT_LCORES_NUM,
#define OPT_LOG_LEVEL "log-level"
OPT_LOG_LEVEL_NUM,
+#define OPT_TRACE "trace"
+ OPT_TRACE_NUM,
#define OPT_MASTER_LCORE "master-lcore"
OPT_MASTER_LCORE_NUM,
#define OPT_MBUF_POOL_OPS_NAME "mbuf-pool-ops-name"
#define TRACE_CTF_FIELD_SIZE 384
#define TRACE_POINT_NAME_SIZE 64
#define TRACE_CTF_MAGIC 0xC1FC1FC1
-
+#define TRACE_MAX_ARGS 32
struct trace_point {
STAILQ_ENTRY(trace_point) next;
enum trace_area_e area;
};
+struct trace_args {
+ uint8_t nb_args;
+ char *args[TRACE_MAX_ARGS];
+};
+
struct trace {
char dir[PATH_MAX];
int dir_offset;
enum rte_trace_mode mode;
rte_uuid_t uuid;
uint32_t buff_len;
+ struct trace_args args;
uint32_t nb_trace_points;
uint32_t nb_trace_mem_list;
struct thread_mem_meta *lcore_meta;
/* Util functions */
const char *trace_mode_to_string(enum rte_trace_mode mode);
const char *trace_area_to_string(enum trace_area_e area);
+int trace_args_apply(const char *arg);
bool trace_has_duplicate_entry(void);
void trace_uuid_generate(void);
int trace_metadata_create(void);
/* EAL interface */
int eal_trace_init(void);
void eal_trace_fini(void);
+int eal_trace_args_save(const char *optarg);
+void eal_trace_args_free(void);
#endif /* __EAL_TRACE_H */