1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2020 Marvell International Ltd.
10 #include <rte_common.h>
11 #include <rte_errno.h>
12 #include <rte_string_fns.h>
14 #include "eal_filesystem.h"
15 #include "eal_trace.h"
18 trace_entry_compare(const char *name)
20 struct trace_point_head *tp_list = trace_list_head_get();
21 struct trace_point *tp;
24 STAILQ_FOREACH(tp, tp_list, next) {
25 if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0)
28 trace_err("found duplicate entry %s", name);
37 trace_has_duplicate_entry(void)
39 struct trace_point_head *tp_list = trace_list_head_get();
40 struct trace_point *tp;
42 /* Is duplicate trace name registered */
43 STAILQ_FOREACH(tp, tp_list, next)
44 if (trace_entry_compare(tp->name))
51 trace_uuid_generate(void)
53 struct trace_point_head *tp_list = trace_list_head_get();
54 struct trace *trace = trace_obj_get();
55 struct trace_point *tp;
56 uint64_t sz_total = 0;
58 /* Go over the registered trace points to get total size of events */
59 STAILQ_FOREACH(tp, tp_list, next) {
60 const uint16_t sz = *tp->handle & __RTE_TRACE_FIELD_SIZE_MASK;
64 rte_uuid_t uuid = RTE_UUID_INIT(sz_total, trace->nb_trace_points,
65 0x4370, 0x8f50, 0x222ddd514176ULL);
66 rte_uuid_copy(trace->uuid, uuid);
70 trace_session_name_generate(char *trace_dir)
80 tm_result = localtime(&tm);
81 if (tm_result == NULL)
84 rc = rte_strscpy(trace_dir, eal_get_hugefile_prefix(),
87 rc = TRACE_PREFIX_LEN;
88 trace_dir[rc++] = '-';
90 rc = strftime(trace_dir + rc, TRACE_DIR_STR_LEN - rc,
91 "%Y-%m-%d-%p-%I-%M-%S", tm_result);
102 trace_dir_default_path_get(char *dir_path)
104 struct trace *trace = trace_obj_get();
105 uint32_t size = sizeof(trace->dir);
109 /* First check for shell environment variable */
110 home_dir = getenv("HOME");
111 if (home_dir == NULL) {
112 /* Fallback to password file entry */
113 pwd = getpwuid(getuid());
117 home_dir = pwd->pw_dir;
120 /* Append dpdk-traces to directory */
121 if (snprintf(dir_path, size, "%s/dpdk-traces/", home_dir) < 0)
122 return -ENAMETOOLONG;
130 struct trace *trace = trace_obj_get();
131 char session[TRACE_DIR_STR_LEN];
135 if (!trace->dir_offset) {
136 dir_path = calloc(1, sizeof(trace->dir));
137 if (dir_path == NULL) {
138 trace_err("fail to allocate memory");
142 rc = trace_dir_default_path_get(dir_path);
144 trace_err("fail to get default path");
151 /* Create the path if it t exist, no "mkdir -p" available here */
152 rc = mkdir(trace->dir, 0700);
153 if (rc < 0 && errno != EEXIST) {
154 trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno));
159 rc = trace_session_name_generate(session);
163 rc = mkdir(trace->dir, 0700);
165 trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno));
170 RTE_LOG(INFO, EAL, "Trace dir: %s\n", trace->dir);