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_epoch_time_save(void)
104 struct trace *trace = trace_obj_get();
105 struct timespec epoch = { 0, 0 };
106 uint64_t avg, start, end;
108 start = rte_get_tsc_cycles();
109 if (clock_gettime(CLOCK_REALTIME, &epoch) < 0) {
110 trace_err("failed to get the epoch time");
113 end = rte_get_tsc_cycles();
114 avg = (start + end) >> 1;
116 trace->epoch_sec = (uint64_t) epoch.tv_sec;
117 trace->epoch_nsec = (uint64_t) epoch.tv_nsec;
118 trace->uptime_ticks = avg;
124 trace_dir_default_path_get(char *dir_path)
126 struct trace *trace = trace_obj_get();
127 uint32_t size = sizeof(trace->dir);
131 /* First check for shell environment variable */
132 home_dir = getenv("HOME");
133 if (home_dir == NULL) {
134 /* Fallback to password file entry */
135 pwd = getpwuid(getuid());
139 home_dir = pwd->pw_dir;
142 /* Append dpdk-traces to directory */
143 if (snprintf(dir_path, size, "%s/dpdk-traces/", home_dir) < 0)
144 return -ENAMETOOLONG;
152 struct trace *trace = trace_obj_get();
153 char session[TRACE_DIR_STR_LEN];
157 if (!trace->dir_offset) {
158 dir_path = calloc(1, sizeof(trace->dir));
159 if (dir_path == NULL) {
160 trace_err("fail to allocate memory");
164 rc = trace_dir_default_path_get(dir_path);
166 trace_err("fail to get default path");
173 /* Create the path if it t exist, no "mkdir -p" available here */
174 rc = mkdir(trace->dir, 0700);
175 if (rc < 0 && errno != EEXIST) {
176 trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno));
181 rc = trace_session_name_generate(session);
185 rc = mkdir(trace->dir, 0700);
187 trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno));
192 RTE_LOG(INFO, EAL, "Trace dir: %s\n", trace->dir);