[lustre-devel] [PATCH 09/42] lustre: ldebugfs: make job_stats and rename_stats valid YAML

James Simmons <[email protected]>
Newsgroups org.lustre.lists.lustre-devel
Message-ID <[email protected]>
From: Lei Feng <[email protected]>

Adjust the format of job_stats and rename_stats to make
them valid YAML.  This fixes the output to correctly indent
the items to follow YAML formatting rules.

Add a test case to verify the format of these params is valid
YAML to avoid other errors being introduced in the future.

WC-bug-id: https://jira.whamcloud.com/browse/LU-16110
Lustre-commit: e96cb6ff1fea7a2bc ("LU-16110 lprocfs: make job_stats and rename_stats valid YAML")
Signed-off-by: Lei Feng <[email protected]>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48417
Reviewed-by: Andreas Dilger <[email protected]>
Reviewed-by: Li Xi <[email protected]>
Reviewed-by: Oleg Drokin <[email protected]>
Signed-off-by: James Simmons <[email protected]>
---
 fs/lustre/include/lprocfs_status.h  |  2 +-
 fs/lustre/llite/lproc_llite.c       |  8 ++++---
 fs/lustre/mdc/lproc_mdc.c           |  3 ++-
 fs/lustre/obdclass/genops.c         |  2 +-
 fs/lustre/obdclass/lprocfs_status.c | 36 ++++++++++++++++++++++-------
 fs/lustre/osc/lproc_osc.c           |  6 +++--
 6 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/fs/lustre/include/lprocfs_status.h b/fs/lustre/include/lprocfs_status.h
index f53125c96683..ef923ae4ca37 100644
--- a/fs/lustre/include/lprocfs_status.h
+++ b/fs/lustre/include/lprocfs_status.h
@@ -461,7 +461,7 @@ int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
 int lprocfs_obd_cleanup(struct obd_device *obd);
 void lprocfs_stats_header(struct seq_file *seq, ktime_t now,
 			  ktime_t ts_init, int width, const char *colon,
-			  bool show_units);
+			  bool show_units, const char *prefix);
 
 /* Generic callbacks */
 int ldebugfs_uint(struct seq_file *m, void *data);
diff --git a/fs/lustre/llite/lproc_llite.c b/fs/lustre/llite/lproc_llite.c
index a57d7bb0a848..ef7ca4c67681 100644
--- a/fs/lustre/llite/lproc_llite.c
+++ b/fs/lustre/llite/lproc_llite.c
@@ -2020,7 +2020,8 @@ static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
 	}
 
 	spin_lock(&sbi->ll_pp_extent_lock);
-	lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
+	lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":",
+			     true, "");
 	seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
 	seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
 		   "extents", "calls", "%", "cum%", "calls", "%", "cum%");
@@ -2157,7 +2158,8 @@ static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
 	}
 
 	spin_lock(&sbi->ll_lock);
-	lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
+	lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":",
+			     true, "");
 
 	seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
 	seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
@@ -2341,7 +2343,7 @@ static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
 	}
 	spin_lock(&sbi->ll_process_lock);
 	lprocfs_stats_header(seq, ktime_get(), sbi->ll_process_stats_init, 25,
-			     ":", true);
+			     ":", true, "");
 	seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
 		   "R/W", "PID", "RANGE START", "RANGE END",
 		   "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
diff --git a/fs/lustre/mdc/lproc_mdc.c b/fs/lustre/mdc/lproc_mdc.c
index cb3744ad9f93..81397a388681 100644
--- a/fs/lustre/mdc/lproc_mdc.c
+++ b/fs/lustre/mdc/lproc_mdc.c
@@ -513,7 +513,8 @@ static int mdc_stats_seq_show(struct seq_file *seq, void *v)
 	struct obd_device *obd = seq->private;
 	struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
 
-	lprocfs_stats_header(seq, ktime_get(), stats->os_init, 25, ":", true);
+	lprocfs_stats_header(seq, ktime_get(), stats->os_init, 25, ":", true,
+			     "");
 	seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
 		   stats->os_lockless_writes);
 	seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
diff --git a/fs/lustre/obdclass/genops.c b/fs/lustre/obdclass/genops.c
index 6e4d2402efee..a20b119f9c37 100644
--- a/fs/lustre/obdclass/genops.c
+++ b/fs/lustre/obdclass/genops.c
@@ -1448,7 +1448,7 @@ int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq)
 
 	spin_lock_irq(&cli->cl_mod_rpcs_waitq.lock);
 	lprocfs_stats_header(seq, ktime_get(), cli->cl_mod_rpcs_init, 25,
-			     ":", true);
+			     ":", true, "");
 	seq_printf(seq, "modify_RPCs_in_flight:  %hu\n",
 		   cli->cl_mod_rpcs_in_flight);
 
diff --git a/fs/lustre/obdclass/lprocfs_status.c b/fs/lustre/obdclass/lprocfs_status.c
index 01b8132087d6..edc576d5f957 100644
--- a/fs/lustre/obdclass/lprocfs_status.c
+++ b/fs/lustre/obdclass/lprocfs_status.c
@@ -1373,21 +1373,40 @@ static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
 	return lprocfs_stats_seq_start(p, pos);
 }
 
+/**
+ * print header of stats including snapshot_time, start_time and elapsed_time.
+ *
+ * @seq		the file to print content to
+ * @now		end time to calculate elapsed_time
+ * @ts_init		start time to calculate elapsed_time
+ * @width		the width of key to align them well
+ * @colon		"" or ":"
+ * @show_units		show units or not
+ * @prefix		prefix (indent) before printing each line of header
+ *			to align them with other content
+ */
 void lprocfs_stats_header(struct seq_file *seq, ktime_t now, ktime_t ts_init,
-			  int width, const char *colon, bool show_units)
+			  int width, const char *colon, bool show_units,
+			  const char *prefix)
 {
 	const char *units = show_units ? " secs.nsecs" : "";
 	struct timespec64 ts;
+	const char *field;
 
+	field = (colon && colon[0]) ? "snapshot_time:" : "snapshot_time";
 	ts = ktime_to_timespec64(now);
-	seq_printf(seq, "%-*s%s %llu.%09lu%s\n", width,
-		   "snapshot_time", colon, (s64)ts.tv_sec, ts.tv_nsec, units);
+	seq_printf(seq, "%s%-*s %llu.%09lu%s\n", prefix, width, field,
+		   (s64)ts.tv_sec, ts.tv_nsec, units);
+
+	field = (colon && colon[0]) ? "start_time:" : "start_time";
 	ts = ktime_to_timespec64(ts_init);
-	seq_printf(seq, "%-*s%s %llu.%09lu%s\n", width,
-		   "start_time", colon, (s64)ts.tv_sec, ts.tv_nsec, units);
+	seq_printf(seq, "%s%-*s %llu.%09lu%s\n", prefix, width, field,
+		   (s64)ts.tv_sec, ts.tv_nsec, units);
+
+	field = (colon && colon[0]) ? "elapsed_time:" : "elapsed_time";
 	ts = ktime_to_timespec64(ktime_sub(now, ts_init));
-	seq_printf(seq, "%-*s%s %llu.%09lu%s\n", width,
-		   "elapsed_time", colon, (s64)ts.tv_sec, ts.tv_nsec, units);
+	seq_printf(seq, "%s%-*s %llu.%09lu%s\n", prefix, width, field,
+		   (s64)ts.tv_sec, ts.tv_nsec, units);
 }
 EXPORT_SYMBOL(lprocfs_stats_header);
 
@@ -1400,7 +1419,8 @@ static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
 	int idx = *(loff_t *)v;
 
 	if (idx == 0)
-		lprocfs_stats_header(p, ktime_get(), stats->ls_init, 25, "", 1);
+		lprocfs_stats_header(p, ktime_get(), stats->ls_init, 25, "",
+				     true, "");
 
 	hdr = &stats->ls_cnt_header[idx];
 	lprocfs_stats_collect(stats, idx, &ctr);
diff --git a/fs/lustre/osc/lproc_osc.c b/fs/lustre/osc/lproc_osc.c
index 54b86d17eb78..c4b1e3e4e2cc 100644
--- a/fs/lustre/osc/lproc_osc.c
+++ b/fs/lustre/osc/lproc_osc.c
@@ -702,7 +702,8 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 
 	spin_lock(&cli->cl_loi_list_lock);
 
-	lprocfs_stats_header(seq, ktime_get(), cli->cl_stats_init, 25, ":", 1);
+	lprocfs_stats_header(seq, ktime_get(), cli->cl_stats_init, 25, ":",
+			     true, "");
 	seq_printf(seq, "read RPCs in flight:  %d\n",
 		   cli->cl_r_in_flight);
 	seq_printf(seq, "write RPCs in flight: %d\n",
@@ -814,7 +815,8 @@ static int osc_stats_seq_show(struct seq_file *seq, void *v)
 	struct obd_device *obd = seq->private;
 	struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
 
-	lprocfs_stats_header(seq, ktime_get(), stats->os_init, 25, ":", true);
+	lprocfs_stats_header(seq, ktime_get(), stats->os_init, 25, ":", true,
+			     "");
 	seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
 		   stats->os_lockless_writes);
 	seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
-- 
2.27.0

_______________________________________________
lustre-devel mailing list
[email protected]
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.