The time stamp converting function can be reused by various plugins.
Thus move it to the util section.
Signed-off-by: Wei Hou <wei.hou@scaleflux.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
__u8 reserved[4083];
};
-static int convert_ts(time_t time, char *ts_buf)
-{
- struct tm gmTimeInfo;
- time_t time_Human, time_ms;
- char buf[80];
-
- time_Human = time/1000;
- time_ms = time % 1000;
-
- gmtime_r((const time_t *)&time_Human, &gmTimeInfo);
-
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &gmTimeInfo);
- sprintf(ts_buf, "%s.%03ld GMT", buf, time_ms);
-
- return 0;
-}
-
static int ocp_print_C3_log_normal(struct nvme_dev *dev,
struct ssd_latency_monitor_log *log_data)
{
return 0;
}
-static int wdc_convert_ts(time_t time, char *ts_buf)
-{
- struct tm gmTimeInfo;
- time_t time_Human, time_ms;
- char buf[80];
-
- time_Human = time/1000;
- time_ms = time % 1000;
-
- gmtime_r((const time_t *)&time_Human, &gmTimeInfo);
-
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &gmTimeInfo);
- sprintf(ts_buf, "%s.%03ld GMT", buf, time_ms);
-
- return 0;
-}
-
static int wdc_print_latency_monitor_log_normal(struct nvme_dev *dev,
struct wdc_ssd_latency_monitor_log *log_data)
{
if (le64_to_cpu(log_data->active_latency_timestamp[i][j]) == -1)
printf(" N/A ");
else {
- wdc_convert_ts(le64_to_cpu(log_data->active_latency_timestamp[i][j]), ts_buf);
+ convert_ts(le64_to_cpu(log_data->active_latency_timestamp[i][j]), ts_buf);
printf("%s ", ts_buf);
}
}
if (le64_to_cpu(log_data->static_latency_timestamp[i][j]) == -1)
printf(" N/A ");
else {
- wdc_convert_ts(le64_to_cpu(log_data->static_latency_timestamp[i][j]), ts_buf);
+ convert_ts(le64_to_cpu(log_data->static_latency_timestamp[i][j]), ts_buf);
printf("%s ", ts_buf);
}
}
#include <stdio.h>
#include <string.h>
#include <locale.h>
+#include <time.h>
#include <ccan/endian/endian.h>
ret[i] = '\0';
return ret;
}
+
+int convert_ts(time_t time, char *ts_buf)
+{
+ struct tm time_info;
+ time_t time_human, time_ms;
+ char buf[80];
+
+ time_human = time / 1000;
+ time_ms = time % 1000;
+
+ gmtime_r((const time_t *)&time_human, &time_info);
+
+ strftime(buf, sizeof(buf), "%Y-%m-%dD|%H:%M:%S", &time_info);
+ sprintf(ts_buf, "%s:%03ld", buf, time_ms);
+
+ return 0;
+}
const char *util_uuid_to_string(unsigned char uuid[NVME_UUID_LEN]);
const char *util_fw_to_string(char *c);
+/**
+ * @brief convert time_t format time to a human readable string
+ *
+ * @param time, input time_t time
+ * @param ts_buf, output time string
+ * @Note, time string format is "Y-M-D|H:M:S:MS"
+ *
+ * @return 0 success
+ */
+int convert_ts(time_t time, char *ts_buf);
+
#endif /* _MISC_H */