diff mbox series

[RFC,2/7] rasdaemon: Add common function to get timestamp for the event

Message ID 20230412083312.1384-3-shiju.jose@huawei.com
State New, archived
Headers show
Series rasdaemon: Process the generic CXL trace events | expand

Commit Message

Shiju Jose April 12, 2023, 8:33 a.m. UTC
From: Shiju Jose <shiju.jose@huawei.com>

Add common function to get the timestamp for the event
reported.

Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
---
 ras-cxl-handler.c | 44 +++++++++++++++++---------------------------
 1 file changed, 17 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/ras-cxl-handler.c b/ras-cxl-handler.c
index ad93558..025e582 100644
--- a/ras-cxl-handler.c
+++ b/ras-cxl-handler.c
@@ -42,6 +42,20 @@  static void convert_timestamp(unsigned long long ts, char *ts_ptr, uint16_t size
 			size);
 }
 
+static void get_timestamp(struct trace_seq *s, struct tep_record *record,
+			  struct ras_events *ras, char *ts_ptr, uint16_t size)
+{
+	time_t now;
+	struct tm *tm;
+
+	now = record->ts / user_hz + ras->uptime_diff;
+	tm = localtime(&now);
+	if (tm)
+		strftime(ts_ptr, size, "%Y-%m-%d %H:%M:%S %z", tm);
+	else
+		strncpy(ts_ptr, "1970-01-01 00:00:00 +0000", size);
+}
+
 /* Poison List: Payload out flags */
 #define CXL_POISON_FLAG_MORE            BIT(0)
 #define CXL_POISON_FLAG_OVERFLOW        BIT(1)
@@ -68,17 +82,9 @@  int ras_cxl_poison_event_handler(struct trace_seq *s,
 	int len;
 	unsigned long long val;
 	struct ras_events *ras = context;
-	time_t now;
-	struct tm *tm;
 	struct ras_cxl_poison_event ev;
 
-	now = record->ts / user_hz + ras->uptime_diff;
-	tm = localtime(&now);
-	if (tm)
-		strftime(ev.timestamp, sizeof(ev.timestamp),
-			 "%Y-%m-%d %H:%M:%S %z", tm);
-	else
-		strncpy(ev.timestamp, "1970-01-01 00:00:00 +0000", sizeof(ev.timestamp));
+	get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
 	if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
 		return -1;
 
@@ -277,19 +283,11 @@  int ras_cxl_aer_ue_event_handler(struct trace_seq *s,
 {
 	int len, i;
 	unsigned long long val;
-	time_t now;
-	struct tm *tm;
 	struct ras_events *ras = context;
 	struct ras_cxl_aer_ue_event ev;
 
 	memset(&ev, 0, sizeof(ev));
-	now = record->ts / user_hz + ras->uptime_diff;
-	tm = localtime(&now);
-	if (tm)
-		strftime(ev.timestamp, sizeof(ev.timestamp),
-			 "%Y-%m-%d %H:%M:%S %z", tm);
-	else
-		strncpy(ev.timestamp, "1970-01-01 00:00:00 +0000", sizeof(ev.timestamp));
+	get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
 	if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
 		return -1;
 
@@ -372,18 +370,10 @@  int ras_cxl_aer_ce_event_handler(struct trace_seq *s,
 {
 	int len;
 	unsigned long long val;
-	time_t now;
-	struct tm *tm;
 	struct ras_events *ras = context;
 	struct ras_cxl_aer_ce_event ev;
 
-	now = record->ts / user_hz + ras->uptime_diff;
-	tm = localtime(&now);
-	if (tm)
-		strftime(ev.timestamp, sizeof(ev.timestamp),
-			 "%Y-%m-%d %H:%M:%S %z", tm);
-	else
-		strncpy(ev.timestamp, "1970-01-01 00:00:00 +0000", sizeof(ev.timestamp));
+	get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
 	if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
 		return -1;