From d1e3d561472ce962f76dcb486f8dd9489749c39d Mon Sep 17 00:00:00 2001
From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Date: Wed, 16 Nov 2011 16:16:54 +0900
Subject: [RFC PATCH 2/2] makedumpfile: Add Compression and IO time report

Add compression and IO time report in information given when
--message-level 16 is specified in command-line.

The example is like this:

$ ./makedumpfile --message-level 16 -c -d0 vmcore dumpfile

bitmap creation time: 0.001376 seconds

I/O time: 3.152995 seconds
Compression time: 216.267694 seconds
STEP [Copying data               ] : 319.352670 seconds

Original pages  : 0x0000000000140000
  Excluded pages   : 0x000000000001254d
    Pages filled with zero  : 0x000000000001254d
    Cache pages             : 0x0000000000000000
    Cache pages + private   : 0x0000000000000000
    User process data pages : 0x0000000000000000
    Free pages              : 0x0000000000000000
  Remaining pages  : 0x000000000012dab3
  (The number of pages is reduced to 94%.)
Memory Hole     : 0x0000000000000000
--------------------------------------------------
Total pages     : 0x0000000000140000
---
 makedumpfile.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 makedumpfile.h |   10 ++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/makedumpfile.c b/makedumpfile.c
index 2f810b1..7a600e7 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -4679,6 +4679,7 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 	unsigned long len_buf_out, len_buf_out_zlib, len_buf_out_lzo;
 	struct dump_bitmap bitmap2;
 	struct timeval tv_start;
+	double d_start, d_end, d_compress, d_io;
 	const off_t failed = (off_t)-1;
 	lzo_bytep wrkmem = NULL;
 
@@ -4749,6 +4750,8 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 		end_pfn   = info->max_mapnr;
 	}
 
+	d_compress = d_io = 0.0;
+
 	for (pfn = start_pfn; pfn < end_pfn; pfn++) {
 
 		if ((num_dumped % per) == 0)
@@ -4779,19 +4782,29 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 		 * Compress the page data.
 		 */
 		if ((info->flag_compress & DUMP_DH_COMPRESSED_ZLIB)
-		    && ((size_out = len_buf_out),
+		    && ((d_start = getdtime()),
+			(size_out = len_buf_out),
 			compress2(buf_out, &size_out, buf, info->page_size,
 				  Z_BEST_SPEED) == Z_OK)
+		    && ((d_end = getdtime()), TRUE)
 		    && (size_out < info->page_size)) {
+
+			d_compress += d_end - d_start;
+
 			pd.flags = DUMP_DH_COMPRESSED_ZLIB;
 			pd.size = size_out;
 			memcpy(buf, buf_out, pd.size);
 		} else if (info->flag_lzo_support
 			   && (info->flag_compress & DUMP_DH_COMPRESSED_LZO)
-			   && ((size_out = info->page_size),
+			   && ((d_start = getdtime()),
+			       (size_out = info->page_size),
 			       lzo1x_1_compress(buf, info->page_size, buf_out,
 						&size_out, wrkmem) == LZO_E_OK)
+			   && ((d_end = getdtime()), TRUE)
 			   && (size_out < info->page_size)) {
+
+			d_compress += d_end - d_start;
+
 			pd.flags = DUMP_DH_COMPRESSED_LZO;
 			pd.size = size_out;
 			memcpy(buf, buf_out, pd.size);
@@ -4803,6 +4816,8 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 		pd.offset     = offset_data;
 		offset_data  += pd.size;
 
+		d_start = getdtime();
+
 		/*
 		 * Write the page header.
 		 */
@@ -4814,8 +4829,14 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 		 */
 		if (!write_cache(cd_page, buf, pd.size))
 			goto out;
+
+		d_end = getdtime();
+
+		d_io += d_end - d_start;
 	}
 
+	d_start = getdtime();
+
 	/*
 	 * Write the remainder.
 	 */
@@ -4824,6 +4845,14 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 	if (!write_cache_bufsz(cd_header))
 		goto out;
 
+	d_end = getdtime();
+
+	d_io += d_end - d_start;
+
+	REPORT_MSG("\n");
+	REPORT_MSG("I/O time: %lf seconds\n", d_io);
+	REPORT_MSG("Compression time: %lf seconds\n", d_compress);
+
 	/*
 	 * print [100 %]
 	 */
@@ -6039,6 +6068,7 @@ int
 create_dumpfile(void)
 {
 	int num_retry, status, new_level;
+	double d_start, d_end, d_bitmap;
 
 	if (!open_files_for_creating_dumpfile())
 		return FALSE;
@@ -6073,9 +6103,18 @@ retry:
 	if (info->name_filterconfig && !gather_filter_info())
 		return FALSE;
 
+	d_start = getdtime();
+
 	if (!create_dump_bitmap())
 		return FALSE;
 
+	d_end = getdtime();
+
+	d_bitmap = d_end - d_start;
+
+	REPORT_MSG("\n");
+	REPORT_MSG("bitmap creation time: %lf seconds\n", d_bitmap);
+
 	if (info->flag_split) {
 		if ((status = writeout_multiple_dumpfiles()) == FALSE)
 			return FALSE;
diff --git a/makedumpfile.h b/makedumpfile.h
index 7ac8c0e..7ec8cc6 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -33,6 +33,7 @@
 #include <getopt.h>
 #include <limits.h>
 #include <lzo/lzo1x.h>
+#include <sys/time.h>
 #include "common.h"
 #include "dwarf_info.h"
 #include "diskdump_mod.h"
@@ -1447,4 +1448,13 @@ struct elf_prstatus {
 
 #endif
 
+static inline double getdtime(void)
+{
+	struct timeval tv;
+
+	gettimeofday(&tv, NULL);
+
+	return (double)tv.tv_sec + (double)tv.tv_usec * 0.001 * 0.001;
+}
+
 #endif /* MAKEDUMPFILE_H */
-- 
1.7.4.4

