From patchwork Thu May 31 10:41:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 923303 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 40xPCX6RgKz9rxs for ; Thu, 31 May 2018 20:41:44 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 78D7FCAA; Thu, 31 May 2018 10:41:19 +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 37AE2C93 for ; Thu, 31 May 2018 10:41:17 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A4C1C71B for ; Thu, 31 May 2018 10:41:16 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id 18-v6so47596762wml.2 for ; Thu, 31 May 2018 03:41:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/mxGqmRudsp0cK4Cn4FJDoYR5s9JGdHOoM4OG7muH28=; b=pZomAl3mvvG8sZqSyEVaCtvQLiO0YKaBXD9DLnzScdCW6ndm1bJ76J7bqkDD4fCwi3 UuyMbfB4XICb4k5s0dQ5QzM6G7dVMyCDdyBPBL1ZB1kQd6dfQFoNc4xAvZSd+qwMmR3g qIWojPb/TsMi5DpMqI+phC11YuREdwlqdlvi61QX6OMpI16XKCZwCHJOy8JjPRzDr80P xlBGc3pfITMTRDpdjWBEXviu+i8PWfQLjyzLV9K+oVyEp49/pKku07lfVGP9IoQYueqC 0MTET4udLBhuaoEFTZ8eRNsTbsgEOFEfIaruR89TFr5kkyW21CSNnf1XtmUw4+JcbRfh kgFQ== X-Gm-Message-State: ALKqPwdqYUZ0luRBJuUAtnD7NGcX3KyVEKI1K+ZgXtjiEAmj4zyDzl// P4pIcH/yK+o1khBYNbWf0N0VM8LUivI= X-Google-Smtp-Source: ADUXVKKAoT7d9zG36WeljHqxGhxhI+ASHPHAr0/mqe56nkLQUPp6LptAPR9CdID21XqooxzB54cNQw== X-Received: by 2002:a1c:228b:: with SMTP id i133-v6mr4173715wmi.92.1527763275076; Thu, 31 May 2018 03:41:15 -0700 (PDT) Received: from redhat.com (red-hat-inc.vlan404.asr1.mad1.gblx.net. [64.215.113.190]) by smtp.gmail.com with ESMTPSA id k126-v6sm1364109wmd.45.2018.05.31.03.41.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 03:41:14 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Thu, 31 May 2018 12:41:10 +0200 Message-Id: <20180531104111.15790-2-jkbs@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180531104111.15790-1-jkbs@redhat.com> References: <20180531104111.15790-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v2 1/2] coverage: Add command for reading counter value 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 Facilitate checking coverage counters from scripts and tests with a new "coverage/read-counter" command that gets the total count for a counter. Same could be achieved by scraping the output of "coverage/show" command but the difficulties there are that output is in human readable format and zero-value counters are not listed. Signed-off-by: Jakub Sitnicki --- lib/coverage-unixctl.man | 2 ++ lib/coverage.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/coverage-unixctl.man b/lib/coverage-unixctl.man index 8e5df818e..81eb93902 100644 --- a/lib/coverage-unixctl.man +++ b/lib/coverage-unixctl.man @@ -11,3 +11,5 @@ debugging. Displays the averaged per-second rates for the last few seconds, the last minute and the last hour, and the total counts of all of the coverage counters. +.IP "\fBcoverage/read-counter\fR \fIcounter\fR" +Displays the total count for the given coverage \fIcounter\fR. diff --git a/lib/coverage.c b/lib/coverage.c index 6cef82614..2cf2d38cc 100644 --- a/lib/coverage.c +++ b/lib/coverage.c @@ -44,6 +44,8 @@ static unsigned int idx_count = 0; static void coverage_read(struct svec *); static unsigned int coverage_array_sum(const unsigned int *arr, const unsigned int len); +static bool coverage_read_counter(const char *name, + unsigned long long int *count); /* Registers a coverage counter with the coverage core */ void @@ -72,11 +74,33 @@ coverage_unixctl_show(struct unixctl_conn *conn, int argc OVS_UNUSED, svec_destroy(&lines); } +static void +coverage_unixctl_read_counter(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + unsigned long long count; + char *reply; + bool ok; + + coverage_clear(); + ok = coverage_read_counter(argv[1], &count); + if (!ok) { + unixctl_command_reply_error(conn, "No such counter"); + return; + } + + reply = xasprintf("%llu\n", count); + unixctl_command_reply(conn, reply); + free(reply); +} + void coverage_init(void) { unixctl_command_register("coverage/show", "", 0, 0, coverage_unixctl_show, NULL); + unixctl_command_register("coverage/read-counter", "COUNTER", 1, 1, + coverage_unixctl_read_counter, NULL); } /* Sorts coverage counters in descending order by total, within equal @@ -372,3 +396,22 @@ coverage_array_sum(const unsigned int *arr, const unsigned int len) ovs_mutex_unlock(&coverage_mutex); return sum; } + +static bool +coverage_read_counter(const char *name, unsigned long long int *count) +{ + for (size_t i = 0; i < n_coverage_counters; i++) { + struct coverage_counter *c = coverage_counters[i]; + + if (!strcmp(c->name, name)) { + ovs_mutex_lock(&coverage_mutex); + c->total += c->count(); + *count = c->total; + ovs_mutex_unlock(&coverage_mutex); + + return true; + } + } + + return false; +}