Linux CXL
 help / color / mirror / Atom feed
From: alison.schofield@intel.com
To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Cc: Alison Schofield <alison.schofield@intel.com>,
	Dave Jiang <dave.jiang@intel.com>, Fan Ni <fan.ni@samsung.com>
Subject: [ndctl PATCH v13 4/8] util/trace: add helpers to retrieve tep fields by type
Date: Fri,  5 Jul 2024 23:24:50 -0700	[thread overview]
Message-ID: <b6089a98199539eca9c89f81de19cede18468408.1720241079.git.alison.schofield@intel.com> (raw)
In-Reply-To: <cover.1720241079.git.alison.schofield@intel.com>

From: Alison Schofield <alison.schofield@intel.com>

Add helpers to extract the value of an event record field given the
field name. This is useful when the user knows the name and format
of the field and simply needs to get it. The helpers also return
the 'type'_MAX of the type when the field is

Since this is in preparation for adding a cxl_poison private parser
for 'cxl list --media-errors' support those specific required
types: u8, u32, u64.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
---
 util/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++
 util/event_trace.h |  8 +++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/util/event_trace.c b/util/event_trace.c
index 1f5c180a030b..bde3a76adfbf 100644
--- a/util/event_trace.c
+++ b/util/event_trace.c
@@ -15,6 +15,43 @@
 #define _GNU_SOURCE
 #include <string.h>
 
+u64 trace_get_field_u64(struct tep_event *event, struct tep_record *record,
+			const char *name)
+{
+	unsigned long long val;
+
+	if (tep_get_field_val(NULL, event, name, record, &val, 0))
+		return ULLONG_MAX;
+
+	return val;
+}
+
+u32 trace_get_field_u32(struct tep_event *event, struct tep_record *record,
+			const char *name)
+{
+	char *val;
+	int len;
+
+	val = tep_get_field_raw(NULL, event, name, record, &len, 0);
+	if (!val)
+		return UINT_MAX;
+
+	return *(u32 *)val;
+}
+
+u8 trace_get_field_u8(struct tep_event *event, struct tep_record *record,
+		      const char *name)
+{
+	char *val;
+	int len;
+
+	val = tep_get_field_raw(NULL, event, name, record, &len, 0);
+	if (!val)
+		return UCHAR_MAX;
+
+	return *(u8 *)val;
+}
+
 static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags)
 {
 	bool sign = flags & TEP_FIELD_IS_SIGNED;
diff --git a/util/event_trace.h b/util/event_trace.h
index 9c53eba7533f..4d498577a00f 100644
--- a/util/event_trace.h
+++ b/util/event_trace.h
@@ -5,6 +5,7 @@
 
 #include <json-c/json.h>
 #include <ccan/list/list.h>
+#include <ccan/short_types/short_types.h>
 
 struct jlist_node {
 	struct json_object *jobj;
@@ -24,5 +25,10 @@ int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx);
 int trace_event_enable(struct tracefs_instance *inst, const char *system,
 		       const char *event);
 int trace_event_disable(struct tracefs_instance *inst);
-
+u8 trace_get_field_u8(struct tep_event *event, struct tep_record *record,
+		      const char *name);
+u32 trace_get_field_u32(struct tep_event *event, struct tep_record *record,
+			const char *name);
+u64 trace_get_field_u64(struct tep_event *event, struct tep_record *record,
+			const char *name);
 #endif
-- 
2.37.3


  parent reply	other threads:[~2024-07-06  6:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-06  6:24 [ndctl PATCH v13 0/8] Support poison list retrieval alison.schofield
2024-07-06  6:24 ` [ndctl PATCH v13 1/8] util/trace: move trace helpers from ndctl/cxl/ to ndctl/util/ alison.schofield
2024-07-24 20:50   ` Dave Jiang
2024-07-06  6:24 ` [ndctl PATCH v13 2/8] util/trace: add an optional pid check to event parsing alison.schofield
2024-07-06  6:24 ` [ndctl PATCH v13 3/8] util/trace: pass an event_ctx to its own parse_event method alison.schofield
2024-07-24 20:55   ` Dave Jiang
2024-07-06  6:24 ` alison.schofield [this message]
2024-07-06  6:24 ` [ndctl PATCH v13 5/8] libcxl: add interfaces for GET_POISON_LIST mailbox commands alison.schofield
2024-07-06  6:24 ` [ndctl PATCH v13 6/8] cxl/list: collect and parse media_error records alison.schofield
2024-07-08  2:07   ` Xingtao Yao (Fujitsu)
2024-07-08 20:54     ` Alison Schofield
2024-07-06  6:24 ` [ndctl PATCH v13 7/8] cxl/list: add --media-errors option to cxl list alison.schofield
2024-07-08  2:26   ` Xingtao Yao (Fujitsu)
2024-07-08 20:56     ` Alison Schofield
2024-07-06  6:24 ` [ndctl PATCH v13 8/8] cxl/test: add cxl-poison.sh unit test alison.schofield
2024-07-08  2:10   ` Xingtao Yao (Fujitsu)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b6089a98199539eca9c89f81de19cede18468408.1720241079.git.alison.schofield@intel.com \
    --to=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=fan.ni@samsung.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox