[CRIU] [PATCH 09/11] p.haul: add revive_stats needed for revive mode

Nikita Spiridonov nspiridonov at virtuozzo.com
Fri Mar 4 01:31:14 PST 2016


Add revive_stats class needed for migration in revive mode,
rename existing migration_stats to live_stats and rework it
respectively to use generic logic in both live_stats and
revive_stats.

Signed-off-by: Nikita Spiridonov <nspiridonov at virtuozzo.com>
---
 phaul/iters.py  |    5 +-
 phaul/mstats.py |  116 ++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 79 insertions(+), 42 deletions(-)

diff --git a/phaul/iters.py b/phaul/iters.py
index 506151f..7f592a1 100644
--- a/phaul/iters.py
+++ b/phaul/iters.py
@@ -142,13 +142,13 @@ class phaul_iter_worker:
 		use_pre_dumps = self.__check_use_pre_dumps()
 		root_pid = self.htype.root_task_pid()
 
-		migration_stats = mstats.migration_stats()
+		migration_stats = mstats.live_stats()
 		migration_stats.handle_start()
 
 		# Handle preliminary FS migration
 		logging.info("Preliminary FS migration")
 		fsstats = self.fs.start_migration()
-		migration_stats.handle_fs_start(fsstats)
+		migration_stats.handle_preliminary(fsstats)
 
 		iter_index = 0
 		prev_dstats = None
@@ -201,6 +201,7 @@ class phaul_iter_worker:
 		dstats = criu_api.criu_get_dstats(self.img)
 		migration_stats.handle_iteration(dstats, fsstats)
 
+		logging.info("Migration succeeded")
 		self.htype.umount()
 		migration_stats.handle_stop(self)
 		self.img.close()
diff --git a/phaul/mstats.py b/phaul/mstats.py
index e6956dc..0ef402c 100644
--- a/phaul/mstats.py
+++ b/phaul/mstats.py
@@ -2,55 +2,91 @@ import time
 import logging
 
 
-def usec2sec(usec):
-	return usec / 1000000.
-
-
 class fs_iter_stats:
 	def __init__(self, bytes_xferred):
 		self.bytes_xferred = bytes_xferred
 
 
-class migration_stats:
+class live_stats:
 	def __init__(self):
-		self._iter_fr_times = []
-		self._frozen_time = 0
+		self.__start_time = 0.0
+		self.__end_time = 0.0
+		self.__restore_time = 0
+		self.__img_sync_time = 0.0
+		self.__iter_frozen_times = []
 
 	def handle_start(self):
-		self._start_time = time.time()
+		self.__start_time = time.time()
+
+	def handle_preliminary(self, fsstats):
+		_print_fsstats(fsstats)
 
-	def handle_fs_start(self, fsstats):
-		self.__print_fsstats(fsstats)
+	def handle_iteration(self, dstats, fsstats):
+		self.__iter_frozen_times.append(dstats.frozen_time)
+		_print_dstats(dstats)
+		_print_fsstats(fsstats)
 
 	def handle_stop(self, iters):
-		self._rst_time = iters.get_target_host().restore_time()
-		self._img_sync_time = iters.img.img_sync_time()
-		self._end_time = time.time()
-		self.__print_overall_stats()
+		self.__end_time = time.time()
+		self.__restore_time = iters.get_target_host().restore_time()
+		self.__img_sync_time = iters.img.img_sync_time()
+		self.__print_overall()
 
-	def handle_iteration(self, dstats, fsstats):
-		self._iter_fr_times.append("%.2lf" % usec2sec(dstats.frozen_time))
-		self._frozen_time += dstats.frozen_time
-		self.__print_dstats(dstats)
-		self.__print_fsstats(fsstats)
-
-	def __print_dstats(self, dstats):
-		if dstats:
-			logging.info("\tDumped %d pages, %d skipped",
-				dstats.pages_written, dstats.pages_skipped_parent)
-
-	def __print_fsstats(self, fsstats):
-		if fsstats:
-			mbytes_xferred_str = ""
-			mbytes_xferred = fsstats.bytes_xferred >> 20
-			if mbytes_xferred != 0:
-				mbytes_xferred_str = " (~{0}Mb)".format(mbytes_xferred)
-			logging.info("\tFs driver transfer %d bytes%s",
-				fsstats.bytes_xferred, mbytes_xferred_str)
-
-	def __print_overall_stats(self):
-		logging.info("Migration succeeded")
-		logging.info("\t   total time is ~%.2lf sec", self._end_time - self._start_time)
-		logging.info("\t  frozen time is ~%.2lf sec (%s)", usec2sec(self._frozen_time), str(self._iter_fr_times))
-		logging.info("\t restore time is ~%.2lf sec", usec2sec(self._rst_time))
-		logging.info("\timg sync time is ~%.2lf sec", self._img_sync_time)
+	def __print_overall(self):
+
+		total_time = self.__end_time - self.__start_time
+		restore_time = self.__usec2sec(self.__restore_time)
+
+		frozen_time = 0.0
+		frozen_times = []
+		for iter_time in self.__iter_frozen_times:
+			frozen_time += self.__usec2sec(iter_time)
+			frozen_times.append("%.2lf" % self.__usec2sec(iter_time))
+
+		logging.info("\t   total time is ~%.2lf sec", total_time)
+		logging.info("\t  frozen time is ~%.2lf sec (%s)", frozen_time,
+			str(frozen_times))
+		logging.info("\t restore time is ~%.2lf sec", restore_time)
+		logging.info("\timg sync time is ~%.2lf sec", self.__img_sync_time)
+
+	def __usec2sec(self, usec):
+		return usec / 1000000.
+
+
+class revive_stats:
+	def __init__(self):
+		self.__start_time = 0.0
+		self.__end_time = 0.0
+
+	def handle_start(self):
+		self.__start_time = time.time()
+
+	def handle_preliminary(self, fsstats):
+		_print_fsstats(fsstats)
+
+	def handle_iteration(self, fsstats):
+		_print_fsstats(fsstats)
+
+	def handle_stop(self):
+		self.__end_time = time.time()
+		self.__print_overall()
+
+	def __print_overall(self):
+		logging.info("\t   total time is ~%.2lf sec",
+			self.__end_time - self.__start_time)
+
+
+def _print_dstats(dstats):
+	if dstats:
+		logging.info("\tDumped %d pages, %d skipped",
+			dstats.pages_written, dstats.pages_skipped_parent)
+
+
+def _print_fsstats(fsstats):
+	if fsstats:
+		mbytes_xferred_str = ""
+		mbytes_xferred = fsstats.bytes_xferred >> 20
+		if mbytes_xferred != 0:
+			mbytes_xferred_str = " (~{0}Mb)".format(mbytes_xferred)
+		logging.info("\tFs driver transfer %d bytes%s",
+			fsstats.bytes_xferred, mbytes_xferred_str)
-- 
1.7.1



More information about the CRIU mailing list