[v1,10/32] eal/trace: implement debug dump function
diff mbox series

Message ID 20200318190241.3150971-11-jerinj@marvell.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • DPDK Trace support
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Jerin Jacob Kollanukkaran March 18, 2020, 7:02 p.m. UTC
From: Jerin Jacob <jerinj@marvell.com>

Implement rte_trace_metadata_dump() and rte_trace_dump()
functions. Former one used to dump the CTF metadata file and
the latter one to dump all the registered events and its status.

Signed-off-by: Jerin Jacob <jerinj@marvell.com>
Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
 lib/librte_eal/common/eal_common_log.c       |  9 +--
 lib/librte_eal/common/eal_common_trace.c     | 63 ++++++++++++++++++
 lib/librte_eal/common/eal_common_trace_ctf.c | 67 ++++++++++++++++++++
 lib/librte_eal/common/eal_private.h          |  3 +
 lib/librte_eal/rte_eal_version.map           |  2 +
 5 files changed, 140 insertions(+), 4 deletions(-)

Comments

Morten Brørup March 23, 2020, 10:56 a.m. UTC | #1
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of jerinj@marvell.com
> Sent: Wednesday, March 18, 2020 8:02 PM
> 
> From: Jerin Jacob <jerinj@marvell.com>
> 
> Implement rte_trace_metadata_dump() and rte_trace_dump()
> functions. Former one used to dump the CTF metadata file and
> the latter one to dump all the registered events and its status.
> 
> Signed-off-by: Jerin Jacob <jerinj@marvell.com>
> Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
> ---
>  lib/librte_eal/common/eal_common_log.c       |  9 +--
>  lib/librte_eal/common/eal_common_trace.c     | 63 ++++++++++++++++++
>  lib/librte_eal/common/eal_common_trace_ctf.c | 67 ++++++++++++++++++++
>  lib/librte_eal/common/eal_private.h          |  3 +
>  lib/librte_eal/rte_eal_version.map           |  2 +
>  5 files changed, 140 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_log.c
> b/lib/librte_eal/common/eal_common_log.c
> index c0efd5214..d8f7feb32 100644
> --- a/lib/librte_eal/common/eal_common_log.c
> +++ b/lib/librte_eal/common/eal_common_log.c
> @@ -372,8 +372,8 @@ RTE_INIT_PRIO(rte_log_init, LOG)
>  	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
>  }
> 
> -static const char *
> -loglevel_to_string(uint32_t level)
> +const char *
> +eal_loglevel_to_string(uint32_t level)

Making this function public, rte_ is probably a better prefix than eal_.

There are some functions missing rte_ prefix in eal_private.h, but there's no need to add more.

-Morten
Jerin Jacob March 23, 2020, 11:08 a.m. UTC | #2
On Mon, Mar 23, 2020 at 4:26 PM Morten Brørup <mb@smartsharesystems.com> wrote:
>
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of jerinj@marvell.com
> > Sent: Wednesday, March 18, 2020 8:02 PM
> >
> > From: Jerin Jacob <jerinj@marvell.com>
> >
> > Implement rte_trace_metadata_dump() and rte_trace_dump()
> > functions. Former one used to dump the CTF metadata file and
> > the latter one to dump all the registered events and its status.
> >
> > Signed-off-by: Jerin Jacob <jerinj@marvell.com>
> > Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
> > ---
> >  lib/librte_eal/common/eal_common_log.c       |  9 +--
> >  lib/librte_eal/common/eal_common_trace.c     | 63 ++++++++++++++++++
> >  lib/librte_eal/common/eal_common_trace_ctf.c | 67 ++++++++++++++++++++
> >  lib/librte_eal/common/eal_private.h          |  3 +
> >  lib/librte_eal/rte_eal_version.map           |  2 +
> >  5 files changed, 140 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_eal/common/eal_common_log.c
> > b/lib/librte_eal/common/eal_common_log.c
> > index c0efd5214..d8f7feb32 100644
> > --- a/lib/librte_eal/common/eal_common_log.c
> > +++ b/lib/librte_eal/common/eal_common_log.c
> > @@ -372,8 +372,8 @@ RTE_INIT_PRIO(rte_log_init, LOG)
> >       rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
> >  }
> >
> > -static const char *
> > -loglevel_to_string(uint32_t level)
> > +const char *
> > +eal_loglevel_to_string(uint32_t level)
>
> Making this function public, rte_ is probably a better prefix than eal_.

Not making it as public function(i.e not updated in .map file). It is
an EAL private function, whose scope is limited only to the EAL
library.

>
> There are some functions missing rte_ prefix in eal_private.h, but there's no need to add more.
>
> -Morten

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c0efd5214..d8f7feb32 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -372,8 +372,8 @@  RTE_INIT_PRIO(rte_log_init, LOG)
 	rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID;
 }
 
-static const char *
-loglevel_to_string(uint32_t level)
+const char *
+eal_loglevel_to_string(uint32_t level)
 {
 	switch (level) {
 	case 0: return "disabled";
@@ -396,14 +396,15 @@  rte_log_dump(FILE *f)
 	size_t i;
 
 	fprintf(f, "global log level is %s\n",
-		loglevel_to_string(rte_log_get_global_level()));
+		eal_loglevel_to_string(rte_log_get_global_level()));
 
 	for (i = 0; i < rte_logs.dynamic_types_len; i++) {
 		if (rte_logs.dynamic_types[i].name == NULL)
 			continue;
 		fprintf(f, "id %zu: %s, level is %s\n",
 			i, rte_logs.dynamic_types[i].name,
-			loglevel_to_string(rte_logs.dynamic_types[i].loglevel));
+			eal_loglevel_to_string(
+					rte_logs.dynamic_types[i].loglevel));
 	}
 }
 
diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index 3a158b2ce..6cb724080 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -338,6 +338,69 @@  rte_trace_from_name(const char *name)
 	return NULL;
 }
 
+static void
+trace_point_dump(FILE *f, struct trace_point *tp)
+{
+	rte_trace_t handle = tp->handle;
+	uint32_t level;
+
+	level = rte_trace_level_get(handle);
+	fprintf(f, "\tid %d, %s, size is %d, level is %s, mode is %s, %s\n",
+		trace_id_get(handle), tp->name,
+		(uint16_t)(*handle & __RTE_TRACE_FIELD_SIZE_MASK),
+		eal_loglevel_to_string(level),
+		trace_mode_to_string(rte_trace_mode_get(handle)),
+		rte_trace_is_enabled(handle) ? "enabled" : "disabled");
+}
+
+static void
+trace_lcore_mem_dump(FILE *f)
+{
+	struct trace *trace = trace_obj_get();
+	struct __rte_trace_header *header;
+	uint32_t count;
+
+	if (trace->nb_trace_mem_list == 0)
+		return;
+
+	rte_spinlock_lock(&trace->lock);
+	fprintf(f, "nb_trace_mem_list = %d\n", trace->nb_trace_mem_list);
+	fprintf(f, "\nTrace mem info\n--------------\n");
+	for (count = 0; count < trace->nb_trace_mem_list; count++) {
+		header = trace->lcore_meta[count].mem;
+		fprintf(f, "\tid %d, mem=%p, area=%s, lcore_id=%d, name=%s\n",
+		count, header,
+		trace_area_to_string(trace->lcore_meta[count].area),
+		header->stream_header.lcore_id,
+		header->stream_header.thread_name);
+	}
+	rte_spinlock_unlock(&trace->lock);
+}
+
+void
+rte_trace_dump(FILE *f)
+{
+	struct trace_point_head *tp_list = trace_list_head_get();
+	struct trace *trace = trace_obj_get();
+	struct trace_point *tp;
+
+	fprintf(f, "\nGlobal info\n-----------\n");
+	fprintf(f, "status = %s\n",
+		rte_trace_global_is_enabled() ? "enabled" : "disabled");
+	fprintf(f, "log level = %s\n",
+		eal_loglevel_to_string(rte_trace_global_level_get()));
+	fprintf(f, "mode = %s\n",
+		trace_mode_to_string(rte_trace_global_mode_get()));
+	fprintf(f, "dir = %s\n", trace->dir);
+	fprintf(f, "buffer len = %d\n", trace->buff_len);
+	fprintf(f, "number of trace points = %d\n", trace->nb_trace_points);
+
+	trace_lcore_mem_dump(f);
+	fprintf(f, "\nTrace point info\n----------------\n");
+	STAILQ_FOREACH(tp, tp_list, next)
+		trace_point_dump(f, tp);
+}
+
 static inline size_t
 list_sz(uint32_t index)
 {
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index c4f00bf22..0dde8fe14 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -419,3 +419,70 @@  trace_metadata_destroy(void)
 	}
 }
 
+static void
+meta_fix_freq(struct trace *trace, char *meta)
+{
+	char *str;
+	int rc;
+
+	str = RTE_PTR_ADD(meta, trace->ctf_meta_offset_freq);
+	rc = sprintf(str, "%20"PRIu64"", rte_get_timer_hz());
+	str[rc] = ';';
+}
+
+static void
+meta_fix_freq_offset(struct trace *trace, char *meta)
+{
+	uint64_t uptime_tickes_floor, uptime_ticks, freq, uptime_sec;
+	uint64_t offset, offset_s;
+	char *str;
+	int rc;
+
+	uptime_ticks = trace->uptime_ticks &
+			((1ULL << __RTE_TRACE_EVENT_HEADER_ID_SHIFT) - 1);
+	freq = rte_get_tsc_hz();
+	uptime_tickes_floor = RTE_ALIGN_MUL_FLOOR(uptime_ticks, freq);
+
+	uptime_sec = uptime_tickes_floor / freq;
+	offset_s = trace->epoch_sec - uptime_sec;
+
+	offset = uptime_ticks - uptime_tickes_floor;
+	offset += trace->epoch_nsec * (freq / NSEC_PER_SEC);
+
+	str = RTE_PTR_ADD(meta, trace->ctf_meta_offset_freq_off_s);
+	rc = sprintf(str, "%20"PRIu64"", offset_s);
+	str[rc] = ';';
+	str = RTE_PTR_ADD(meta, trace->ctf_meta_offset_freq_off);
+	rc = sprintf(str, "%20"PRIu64"", offset);
+	str[rc] = ';';
+}
+
+static void
+meta_fixup(struct trace *trace, char *meta)
+{
+	meta_fix_freq(trace, meta);
+	meta_fix_freq_offset(trace, meta);
+}
+
+int
+rte_trace_metadata_dump(FILE *f)
+{
+	struct trace *trace = trace_obj_get();
+	char *ctf_meta = trace->ctf_meta;
+	int rc;
+
+	if (rte_trace_global_is_disabled())
+		return 0;
+
+	if (ctf_meta == NULL)
+		return -EINVAL;
+
+	if (!__atomic_load_n(&trace->ctf_fixup_done, __ATOMIC_SEQ_CST) &&
+				rte_get_timer_hz()) {
+		meta_fixup(trace, ctf_meta);
+		__atomic_store_n(&trace->ctf_fixup_done, 1, __ATOMIC_SEQ_CST);
+	}
+
+	rc = fprintf(f, "%s", ctf_meta);
+	return rc < 0 ? rc : 0;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index ddcfbe2e4..81694616b 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -443,4 +443,7 @@  rte_option_usage(void);
 uint64_t
 eal_get_baseaddr(void);
 
+const char *
+eal_loglevel_to_string(uint32_t level);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 8999faeb7..cae358608 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -359,4 +359,6 @@  EXPERIMENTAL {
 	rte_trace_pattern;
 	rte_trace_regexp;
 	rte_trace_from_name;
+	rte_trace_metadata_dump;
+	rte_trace_dump;
 };