[3/4] f2fs: introduce IOSTAT_INFO_SHOW macro

Message ID 20230104112158.15844-3-frank.li@vivo.com
State New
Headers
Series [1/4] f2fs: reset iostat_count in f2fs_reset_iostat() |

Commit Message

李扬韬 Jan. 4, 2023, 11:21 a.m. UTC
  Define IOSTAT_INFO_SHOW macro and use it to simplify code.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/iostat.c | 136 +++++++++++------------------------------------
 1 file changed, 32 insertions(+), 104 deletions(-)
  

Patch

diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c
index e7d03c446994..991605fcfe0b 100644
--- a/fs/f2fs/iostat.c
+++ b/fs/f2fs/iostat.c
@@ -25,6 +25,12 @@  static inline unsigned long long iostat_get_avg_bytes(struct f2fs_sb_info *sbi,
 		sbi->iostat_count[type]) : 0;
 }
 
+#define IOSTAT_INFO_SHOW(name, type)					\
+	seq_printf(seq, "%-23s %-16llu %-16llu %-16llu\n",	\
+			name":", sbi->rw_iostat[type],				\
+			sbi->iostat_count[type],					\
+			iostat_get_avg_bytes(sbi, type))			\
+
 int __maybe_unused iostat_info_seq_show(struct seq_file *seq, void *offset)
 {
 	struct super_block *sb = seq->private;
@@ -39,120 +45,42 @@  int __maybe_unused iostat_info_seq_show(struct seq_file *seq, void *offset)
 
 	/* print app write IOs */
 	seq_puts(seq, "[WRITE]\n");
-	seq_printf(seq, "app buffered data:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_BUFFERED_IO],
-				sbi->iostat_count[APP_BUFFERED_IO],
-				iostat_get_avg_bytes(sbi, APP_BUFFERED_IO));
-	seq_printf(seq, "app direct data:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_DIRECT_IO],
-				sbi->iostat_count[APP_DIRECT_IO],
-				iostat_get_avg_bytes(sbi, APP_DIRECT_IO));
-	seq_printf(seq, "app mapped data:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_MAPPED_IO],
-				sbi->iostat_count[APP_MAPPED_IO],
-				iostat_get_avg_bytes(sbi, APP_MAPPED_IO));
-	seq_printf(seq, "app buffered cdata:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_BUFFERED_CDATA_IO],
-				sbi->iostat_count[APP_BUFFERED_CDATA_IO],
-				iostat_get_avg_bytes(sbi, APP_BUFFERED_CDATA_IO));
-	seq_printf(seq, "app mapped cdata:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_MAPPED_CDATA_IO],
-				sbi->iostat_count[APP_MAPPED_CDATA_IO],
-				iostat_get_avg_bytes(sbi, APP_MAPPED_CDATA_IO));
+	IOSTAT_INFO_SHOW("app buffered data", APP_BUFFERED_IO);
+	IOSTAT_INFO_SHOW("app direct data", APP_DIRECT_IO);
+	IOSTAT_INFO_SHOW("app mapped data", APP_MAPPED_IO);
+	IOSTAT_INFO_SHOW("app buffered cdata", APP_BUFFERED_CDATA_IO);
+	IOSTAT_INFO_SHOW("app mapped cdata", APP_MAPPED_CDATA_IO);
 
 	/* print fs write IOs */
-	seq_printf(seq, "fs data:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_DATA_IO],
-				sbi->iostat_count[FS_DATA_IO],
-				iostat_get_avg_bytes(sbi, FS_DATA_IO));
-	seq_printf(seq, "fs cdata:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_CDATA_IO],
-				sbi->iostat_count[FS_CDATA_IO],
-				iostat_get_avg_bytes(sbi, FS_CDATA_IO));
-	seq_printf(seq, "fs node:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_NODE_IO],
-				sbi->iostat_count[FS_NODE_IO],
-				iostat_get_avg_bytes(sbi, FS_NODE_IO));
-	seq_printf(seq, "fs meta:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_META_IO],
-				sbi->iostat_count[FS_META_IO],
-				iostat_get_avg_bytes(sbi, FS_META_IO));
-	seq_printf(seq, "fs gc data:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_GC_DATA_IO],
-				sbi->iostat_count[FS_GC_DATA_IO],
-				iostat_get_avg_bytes(sbi, FS_GC_DATA_IO));
-	seq_printf(seq, "fs gc node:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_GC_NODE_IO],
-				sbi->iostat_count[FS_GC_NODE_IO],
-				iostat_get_avg_bytes(sbi, FS_GC_NODE_IO));
-	seq_printf(seq, "fs cp data:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_CP_DATA_IO],
-				sbi->iostat_count[FS_CP_DATA_IO],
-				iostat_get_avg_bytes(sbi, FS_CP_DATA_IO));
-	seq_printf(seq, "fs cp node:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_CP_NODE_IO],
-				sbi->iostat_count[FS_CP_NODE_IO],
-				iostat_get_avg_bytes(sbi, FS_CP_NODE_IO));
-	seq_printf(seq, "fs cp meta:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_CP_META_IO],
-				sbi->iostat_count[FS_CP_META_IO],
-				iostat_get_avg_bytes(sbi, FS_CP_META_IO));
+	IOSTAT_INFO_SHOW("fs data", FS_DATA_IO);
+	IOSTAT_INFO_SHOW("fs cdata", FS_CDATA_IO);
+	IOSTAT_INFO_SHOW("fs node", FS_NODE_IO);
+	IOSTAT_INFO_SHOW("fs meta", FS_META_IO);
+	IOSTAT_INFO_SHOW("fs gc data", FS_GC_DATA_IO);
+	IOSTAT_INFO_SHOW("fs gc node", FS_GC_NODE_IO);
+	IOSTAT_INFO_SHOW("fs cp data", FS_CP_DATA_IO);
+	IOSTAT_INFO_SHOW("fs cp node", FS_CP_NODE_IO);
+	IOSTAT_INFO_SHOW("fs cp meta", FS_CP_META_IO);
 
 	/* print app read IOs */
 	seq_puts(seq, "[READ]\n");
-	seq_printf(seq, "app buffered data:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_BUFFERED_READ_IO],
-				sbi->iostat_count[APP_BUFFERED_READ_IO],
-				iostat_get_avg_bytes(sbi, APP_BUFFERED_READ_IO));
-	seq_printf(seq, "app direct data:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_DIRECT_READ_IO],
-				sbi->iostat_count[APP_DIRECT_READ_IO],
-				iostat_get_avg_bytes(sbi, APP_DIRECT_READ_IO));
-	seq_printf(seq, "app mapped data:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_MAPPED_READ_IO],
-				sbi->iostat_count[APP_MAPPED_READ_IO],
-				iostat_get_avg_bytes(sbi, APP_MAPPED_READ_IO));
-	seq_printf(seq, "app buffered cdata:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_BUFFERED_CDATA_READ_IO],
-				sbi->iostat_count[APP_BUFFERED_CDATA_READ_IO],
-				iostat_get_avg_bytes(sbi, APP_BUFFERED_CDATA_READ_IO));
-	seq_printf(seq, "app mapped cdata:	%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[APP_MAPPED_CDATA_READ_IO],
-				sbi->iostat_count[APP_MAPPED_CDATA_READ_IO],
-				iostat_get_avg_bytes(sbi, APP_MAPPED_CDATA_READ_IO));
+	IOSTAT_INFO_SHOW("app buffered data", APP_BUFFERED_READ_IO);
+	IOSTAT_INFO_SHOW("app direct data", APP_DIRECT_READ_IO);
+	IOSTAT_INFO_SHOW("app mapped data", APP_MAPPED_READ_IO);
+	IOSTAT_INFO_SHOW("app buffered cdata", APP_BUFFERED_CDATA_READ_IO);
+	IOSTAT_INFO_SHOW("app mapped cdata", APP_MAPPED_CDATA_READ_IO);
 
 	/* print fs read IOs */
-	seq_printf(seq, "fs data:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_DATA_READ_IO],
-				sbi->iostat_count[FS_DATA_READ_IO],
-				iostat_get_avg_bytes(sbi, FS_DATA_READ_IO));
-	seq_printf(seq, "fs gc data:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_GDATA_READ_IO],
-				sbi->iostat_count[FS_GDATA_READ_IO],
-				iostat_get_avg_bytes(sbi, FS_GDATA_READ_IO));
-	seq_printf(seq, "fs cdata:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_CDATA_READ_IO],
-				sbi->iostat_count[FS_CDATA_READ_IO],
-				iostat_get_avg_bytes(sbi, FS_CDATA_READ_IO));
-	seq_printf(seq, "fs node:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_NODE_READ_IO],
-				sbi->iostat_count[FS_NODE_READ_IO],
-				iostat_get_avg_bytes(sbi, FS_NODE_READ_IO));
-	seq_printf(seq, "fs meta:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_META_READ_IO],
-				sbi->iostat_count[FS_META_READ_IO],
-				iostat_get_avg_bytes(sbi, FS_META_READ_IO));
+	IOSTAT_INFO_SHOW("fs data", FS_DATA_READ_IO);
+	IOSTAT_INFO_SHOW("fs gc data", FS_GDATA_READ_IO);
+	IOSTAT_INFO_SHOW("fs cdata", FS_CDATA_READ_IO);
+	IOSTAT_INFO_SHOW("fs node", FS_NODE_READ_IO);
+	IOSTAT_INFO_SHOW("fs meta", FS_META_READ_IO);
 
 	/* print other IOs */
 	seq_puts(seq, "[OTHER]\n");
-	seq_printf(seq, "fs discard:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_DISCARD],
-				sbi->iostat_count[FS_DISCARD],
-				iostat_get_avg_bytes(sbi, FS_DISCARD));
-	seq_printf(seq, "fs flush:		%-16llu %-16llu %-16llu\n",
-				sbi->rw_iostat[FS_FLUSH],
-				sbi->iostat_count[FS_FLUSH],
-				iostat_get_avg_bytes(sbi, FS_FLUSH));
+	IOSTAT_INFO_SHOW("fs discard", FS_DISCARD);
+	IOSTAT_INFO_SHOW("fs flush", FS_FLUSH);
 
 	return 0;
 }