From 983958474b3edf29a7263b9bbfe2e20359c1d43a Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 3 Apr 2015 08:42:43 +0300 Subject: [PATCH] ceph daemonperf: add watch interval and count parameters Fixes: #11319 Signed-off-by: Mykola Golub --- src/ceph.in | 17 ++++++++++++++++- src/pybind/ceph_daemon.py | 8 ++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index f9c66d350e5..d208d96d45f 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -550,7 +550,22 @@ def main(): return errno.EINVAL if sockpath and daemon_perf: - DaemonWatcher(sockpath).run() + interval = 1 + count = None + if len(childargs) > 0: + try: + interval = float(childargs[0]) + if interval < 0: + raise ValueError + except ValueError: + print >> sys.stderr, 'daemonperf: interval should be a positive number' + return errno.EINVAL + if len(childargs) > 1: + if not childargs[1].isdigit(): + print >> sys.stderr, 'daemonperf: count should be a positive integer' + return errno.EINVAL + count = int(childargs[1]) + DaemonWatcher(sockpath).run(interval, count) return 0 elif sockpath: try: diff --git a/src/pybind/ceph_daemon.py b/src/pybind/ceph_daemon.py index 30c54e4b5a3..638ef8978e0 100755 --- a/src/pybind/ceph_daemon.py +++ b/src/pybind/ceph_daemon.py @@ -244,7 +244,7 @@ class DaemonWatcher(object): if schema_data.get('nick'): self._stats[section_name][name] = schema_data['nick'] - def run(self, ostr=sys.stdout): + def run(self, interval, count=None, ostr=sys.stdout): """ Print output at regular intervals until interrupted. @@ -267,8 +267,12 @@ class DaemonWatcher(object): self._print_headers(ostr) rows_since_header = 0 self._print_vals(ostr, dump, last_dump) + if count is not None: + count -= 1 + if count <= 0: + break rows_since_header += 1 last_dump = dump - time.sleep(1) + time.sleep(interval) except KeyboardInterrupt: return -- 2.47.3