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 <j...@redhat.com> --- 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; +} -- 2.14.3 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev