From patchwork Wed Mar 7 17:01:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 882693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zxKjG6p27z9sf4 for ; Thu, 8 Mar 2018 04:03:30 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 97C881291; Wed, 7 Mar 2018 17:01:22 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9EB901289 for ; Wed, 7 Mar 2018 17:01:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4B5E75E6 for ; Wed, 7 Mar 2018 17:01:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 880EAD142A for ; Wed, 7 Mar 2018 17:01:16 +0000 (UTC) Received: from monae.redhat.com (ovpn-124-182.rdu2.redhat.com [10.10.124.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BCDF215CDA7 for ; Wed, 7 Mar 2018 17:01:16 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 7 Mar 2018 11:01:13 -0600 Message-Id: <20180307170115.29137-4-mmichels@redhat.com> In-Reply-To: <20180307170115.29137-1-mmichels@redhat.com> References: <20180307170115.29137-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 07 Mar 2018 17:01:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 07 Mar 2018 17:01:16 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mmichels@redhat.com' RCPT:'' X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v6 3/5] stopwatch: Add API for retrieving calculated statistics X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Jakub Sitnicki Will be used for testing the module. Signed-off-by: Jakub Sitnicki Signed-off-by: Mark Michelson --- lib/stopwatch.c | 34 ++++++++++++++++++++++++++++++++++ lib/stopwatch.h | 13 +++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/stopwatch.c b/lib/stopwatch.c index 9b7847bf5..4f36c4692 100644 --- a/lib/stopwatch.c +++ b/lib/stopwatch.c @@ -232,6 +232,40 @@ add_sample(struct stopwatch *sw, unsigned long long new_sample) calc_average(&sw->long_term, new_sample); } +static bool +performance_get_stats_protected(const char *name, + struct performance_stats *stats) +{ + struct performance *perf; + + perf = shash_find_data(&performances, name); + if (!perf) { + return false; + } + + stats->count = perf->samples; + stats->unit = perf->units; + stats->max = perf->max; + stats->min = perf->min; + stats->pctl_95 = perf->pctl.percentile; + stats->ewma_50 = perf->short_term.average; + stats->ewma_1 = perf->long_term.average; + + return true; +} + +bool +performance_get_stats(const char *name, struct performance_stats *stats) +{ + bool found = false; + + ovs_mutex_lock(&performances_lock); + found = performance_get_stats_protected(name, stats); + ovs_mutex_unlock(&performances_lock); + + return found; +} + static void stopwatch_print(struct stopwatch *sw, const char *name, struct ds *s) diff --git a/lib/stopwatch.h b/lib/stopwatch.h index 61f814523..fac5de2c6 100644 --- a/lib/stopwatch.h +++ b/lib/stopwatch.h @@ -24,6 +24,16 @@ enum stopwatch_units { SW_NS, }; +struct stopwatch_stats { + unsigned long long count; /* Total number of samples. */ + enum stopwatch_units unit; /* Unit of following values. */ + unsigned long long max; /* Maximum value. */ + unsigned long long min; /* Minimum value. */ + double pctl_95; /* 95th percentile. */ + double ewma_50; /* Exponentially weighted moving average (alpha 0.50). */ + double ewma_1; /* Exponentially weighted moving average (alpha 0.01). */ +}; + /* Create a new stopwatch. * The "units" are not used for any calculations but are printed when * statistics are requested. @@ -38,4 +48,7 @@ void stopwatch_start(const char *name, unsigned long long ts); */ void stopwatch_stop(const char *name, unsigned long long ts); +/* Retrieve statistics calculated from collected samples */ +bool stopwatch_get_stats(const char *name, struct stopwatch_stats *stats); + #endif /* stopwatch.h */