From patchwork Sat Jul 6 06:24:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725679 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79ABF1C68C for ; Sat, 6 Jul 2024 06:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247105; cv=none; b=N+G+ooJYSOm07UQbyYgTL1L8Q/sDRf8S+9ZZUWcOEM0a3kcdo1ayL3xc0oL7Sn5XthqmMKfmvZ45f8GY/0VKv0ckV2Soututfn6oWzbFGC/YWV1XHL/CMoY5piax0n/RZe76/+flrxMZ7p70s9TPoI/llfaprWMgdAZzrJQEWd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247105; c=relaxed/simple; bh=hvKg/t3CyFdt16dcyKFhlzMVaWxFkrYEOsQBvf3o8zc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GCPX+H87nWT0MEmpBBbkIrmseHzJFVL/Pwg60cIISoMPlRZrYbp0wbi2MUayFWJeWI0jXyZRN/xsesBSzKXr1UPz+E8ozTiuyEOSl3N9UN6jZ/CoO9a4GbgLmRECLzzLzA6rpM5GTZtA6PdXbhyJ00mQ3vp4GLNICe13iGgSfAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=c4OnQmWw; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="c4OnQmWw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247103; x=1751783103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hvKg/t3CyFdt16dcyKFhlzMVaWxFkrYEOsQBvf3o8zc=; b=c4OnQmWwRUF47TySgYivOfLz2DyocQaT4nC5IMa77zCHEKu/7iY+G+xR OXxkH8IB6iNgi8bvdMO9/y/XUxHI9tDXQWf9YHK8diH601W5bIeAHFv9C 9h6BqZSPFiun9a4Psel5dJ7M+aiZnqpt9Rew8AC6qUorjARmq9GIvZbN6 2g1XF+pL1JNi2F4FJkN5OO5R4YEFos2YWlP6mIXA+WXjZ2zxDhQ2UuTP1 InUHbDzStManKAkfrbgXDfllkTMgHoRpQ4W142b2zNB24Adm1rpo5cDpp NDUr34ct9j+HOVl21anqZD0Lgj0QbtIPVxPAbLF5SqYSpXc0PTOe2usVL w==; X-CSE-ConnectionGUID: AB6GQSyHQAiYqjM8oDzb5A== X-CSE-MsgGUID: 8XQAgQZ2Sv6ndQnvQ0MsdQ== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166938" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166938" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:02 -0700 X-CSE-ConnectionGUID: WzvvE/ijQqudln6JSfnsZA== X-CSE-MsgGUID: FPz/UGr/Rsa4ES7I/41QmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172519" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:02 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Dave Jiang , Fan Ni 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 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield 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 Reviewed-by: Dave Jiang Reviewed-by: Fan Ni --- 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 +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 #include +#include 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