From patchwork Fri Dec 12 19:14:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Mayhew X-Patchwork-Id: 5484991 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2DF82BEEA8 for ; Fri, 12 Dec 2014 19:15:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5AE08201B4 for ; Fri, 12 Dec 2014 19:15:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4E502014A for ; Fri, 12 Dec 2014 19:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966277AbaLLTPB (ORCPT ); Fri, 12 Dec 2014 14:15:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45761 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966239AbaLLTPA (ORCPT ); Fri, 12 Dec 2014 14:15:00 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBCJEx4m019178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Dec 2014 14:14:59 -0500 Received: from tonberry.usersys.redhat.com (dhcp145-188.rdu.redhat.com [10.13.145.188]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBCJExQu004927 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 12 Dec 2014 14:14:59 -0500 Received: from tonberry.usersys.redhat.com (localhost [127.0.0.1]) by tonberry.usersys.redhat.com (8.14.8/8.14.5) with ESMTP id sBCJExtQ000351 for ; Fri, 12 Dec 2014 14:14:59 -0500 Received: (from smayhew@localhost) by tonberry.usersys.redhat.com (8.14.8/8.14.8/Submit) id sBCJEwIg000350 for linux-nfs@vger.kernel.org; Fri, 12 Dec 2014 14:14:58 -0500 From: Scott Mayhew To: linux-nfs@vger.kernel.org Subject: [nfs-utils PATCH v4 04/14] mountstats: Refactor compare_iostats Date: Fri, 12 Dec 2014 14:14:47 -0500 Message-Id: <1418411697-65535-5-git-send-email-smayhew@redhat.com> In-Reply-To: <1418411697-65535-1-git-send-email-smayhew@redhat.com> References: <1418411697-65535-1-git-send-email-smayhew@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Iterate over the newly added counters instead of using repeated assignment statements. Also compute the difference of every counter where it makes sense -- this will allow support for -S/--since to be implemented in the future. Signed-off-by: Scott Mayhew --- tools/mountstats/mountstats.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py index a129d61..912d31a 100644 --- a/tools/mountstats/mountstats.py +++ b/tools/mountstats/mountstats.py @@ -415,7 +415,11 @@ class DeviceData: def compare_iostats(self, old_stats): """Return the difference between two sets of stats """ + if old_stats.__nfs_data['age'] > self.__nfs_data['age']: + return self + result = DeviceData() + protocol = self.__rpc_data['protocol'] # copy self into result for key, value in self.__nfs_data.items(): @@ -430,12 +434,21 @@ class DeviceData: for op in result.__rpc_data['ops']: result.__rpc_data[op] = list(map(difference, self.__rpc_data[op], old_stats.__rpc_data[op])) - # update the remaining keys we care about - result.__rpc_data['rpcsends'] -= old_stats.__rpc_data['rpcsends'] - result.__rpc_data['backlogutil'] -= old_stats.__rpc_data['backlogutil'] - result.__nfs_data['serverreadbytes'] -= old_stats.__nfs_data['serverreadbytes'] - result.__nfs_data['serverwritebytes'] -= old_stats.__nfs_data['serverwritebytes'] - + # update the remaining keys + if protocol == 'udp': + for key in XprtUdpCounters: + result.__rpc_data[key] -= old_stats.__rpc_data[key] + elif protocol == 'tcp': + for key in XprtTcpCounters: + result.__rpc_data[key] -= old_stats.__rpc_data[key] + elif protocol == 'rdma': + for key in XprtRdmaCounters: + result.__rpc_data[key] -= old_stats.__rpc_data[key] + result.__nfs_data['age'] -= old_stats.__nfs_data['age'] + for key in NfsEventCounters: + result.__nfs_data[key] -= old_stats.__nfs_data[key] + for key in NfsByteCounters: + result.__nfs_data[key] -= old_stats.__nfs_data[key] return result def display_iostats(self, sample_time):