From patchwork Mon Sep 10 21:58:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Beller X-Patchwork-Id: 10594813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0ABB314E5 for ; Mon, 10 Sep 2018 21:58:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE1CA29127 for ; Mon, 10 Sep 2018 21:58:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E25D229142; Mon, 10 Sep 2018 21:58:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 727D629127 for ; Mon, 10 Sep 2018 21:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbeIKCyn (ORCPT ); Mon, 10 Sep 2018 22:54:43 -0400 Received: from mail-yb1-f202.google.com ([209.85.219.202]:51563 "EHLO mail-yb1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbeIKCyn (ORCPT ); Mon, 10 Sep 2018 22:54:43 -0400 Received: by mail-yb1-f202.google.com with SMTP id 1-v6so10790545ybe.18 for ; Mon, 10 Sep 2018 14:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=U9DPIcYrXKEqkhCDeZZkhjFQcDZNBa9WLq5Oah2PLVg=; b=L/kV3TbjNz6D7etNVeUyvr4eJfnTh7/ApSRFHotc/SoUeiWakMpklWH9s+ik66u2Is sUjYz5CsPcbWuaqMeBS92rDgc91P//DOQ9jyYKZDl1tre5oX5Y5JRSZVtLrrnQG4m+zW DQXDvNmcTySWR0dFXcTuN8/S4Hmh4TmbrkTyyAkm1QP6SIFhTn77Wfsr/EWqtLYk+4sX shHnP52tX4/ca9hCqDLqWMWvV3iGdF7mn66YMd7yj1FHeyi9tN8KupRIkZCey4V0fxVV IgC3dG04TDNtS1IKq9c3bxoslVJ9w2dAp4tnUt3kmTYuKMjtU86O7dYMxVX7Rz5kW5HX Qwow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=U9DPIcYrXKEqkhCDeZZkhjFQcDZNBa9WLq5Oah2PLVg=; b=TJ0ZiNSav4sfrJrg4WuzCoK5pxbEpCo9veLLh15bsSRdY9uSL/27o4G1Vkny3B2rFN yzacl/fGIN0EITbr/tpvQ7TNyz70rEC6iHpQssol0W7pX4+7b3k59UhmaRigv+epNRc2 MdCIGIMIi1D48Pe6X3d32wNfZ5B/Lhz7NY0L7aLXwBjywjT6UukHRfKJ9olYOJLa4oVR lAHqhmlvMqrdv6uQXz6c8qVmfoWev1burC3491maf3it4r2LiU5m/h1msFuUFN8ni/eZ icbCm9HcSnRIQCxzsro9NrM5XH5fb6NCQNhVD9Lwm9Cyei+gf7zxGoK73Ddtupp23HJC LCXA== X-Gm-Message-State: APzg51DFRtE5QfgERKr+EPVmsXOSZo5GafwGF9YPS9bC5O+luWTF8Vhh KrEvy72gaaJmWu5rszXijvd1+2QCbPh3 X-Google-Smtp-Source: ANB0VdZjHpzPDYEZLHTTtc7bkElgf3v6jpFOvZeD3ryZIZFxtZ1KTQsydenGeuLzXmu9yWRF6AoifZ5/EWUA X-Received: by 2002:a81:1393:: with SMTP id 141-v6mr5353741ywt.209.1536616716484; Mon, 10 Sep 2018 14:58:36 -0700 (PDT) Date: Mon, 10 Sep 2018 14:58:30 -0700 In-Reply-To: Message-Id: <20180910215831.17608-1-sbeller@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.19.0.rc2.392.g5ba43deb5a-goog Subject: [PATCH 1/2] trace: add trace_print_string_list_key From: Stefan Beller To: sbeller@google.com Cc: git@vger.kernel.org, gitster@pobox.com, peff@peff.net Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similar to trace_strbuf or trace_argv_printf, we might want to output a string list in tracing. Add such a function. Signed-off-by: Stefan Beller --- I separated this from the other series, making it into 2 patches: This first patch adds tracing for string lists and the next patch that removes the unused function from the string list API. That way we can decide on these two patches separately if needed. Documentation/technical/api-trace.txt | 8 ++++++ trace.c | 39 +++++++++++++++++++++++++++ trace.h | 16 +++++++++++ 3 files changed, 63 insertions(+) diff --git a/Documentation/technical/api-trace.txt b/Documentation/technical/api-trace.txt index fadb5979c48..ad0ea99d930 100644 --- a/Documentation/technical/api-trace.txt +++ b/Documentation/technical/api-trace.txt @@ -62,6 +62,14 @@ Functions Prints the strbuf, without additional formatting (i.e. doesn't choke on `%` or even `\0`). +`void trace_print_string_list_key(struct trace_key *key, const struct string_list *p, const char *text):: + + Print the string-pointer pairs of the string_list, + each one in its own line. + It takes an optional key and header argument. + If the tracing key is not given, use the default key. + The header text is printed before the list itself. + `uint64_t getnanotime(void)`:: Returns nanoseconds since the epoch (01/01/1970), typically used diff --git a/trace.c b/trace.c index fc623e91fdd..e3a12a092f9 100644 --- a/trace.c +++ b/trace.c @@ -176,6 +176,38 @@ void trace_strbuf_fl(const char *file, int line, struct trace_key *key, strbuf_release(&buf); } +void trace_print_string_list_key_fl(const char *file, int line, + struct trace_key *key, + const struct string_list *p, + const char *text) +{ + int i, buf_prefix; + struct strbuf buf = STRBUF_INIT; + + if (!key) + key = &trace_default_key; + + if (!prepare_trace_line(file, line, key, &buf)) + return; + + buf_prefix = buf.len; + + if (text) { + strbuf_addstr(&buf, text); + print_trace_line(key, &buf); + } + + for (i = 0; i < p->nr; i++) { + strbuf_setlen(&buf, buf_prefix); + strbuf_addf(&buf, "%s:%p\n", + p->items[i].string, + p->items[i].util); + print_trace_line(key, &buf); + } + + strbuf_release(&buf); +} + static void trace_performance_vprintf_fl(const char *file, int line, uint64_t nanos, const char *format, va_list ap) @@ -227,6 +259,13 @@ void trace_strbuf(struct trace_key *key, const struct strbuf *data) trace_strbuf_fl(NULL, 0, key, data); } +void trace_print_string_list_key(struct trace_key *key, + const struct string_list *p, + const char *text) +{ + trace_print_string_list_key_fl(NULL, 0, key, p, list); +} + void trace_performance(uint64_t nanos, const char *format, ...) { va_list ap; diff --git a/trace.h b/trace.h index 2b6a1bc17c2..0e083891e1f 100644 --- a/trace.h +++ b/trace.h @@ -37,6 +37,10 @@ extern void trace_argv_printf(const char **argv, const char *format, ...); extern void trace_strbuf(struct trace_key *key, const struct strbuf *data); +extern void trace_print_string_list_key(struct trace_key *key, + const struct string_list *p, + const char *text); + /* Prints elapsed time (in nanoseconds) if GIT_TRACE_PERFORMANCE is enabled. */ __attribute__((format (printf, 2, 3))) extern void trace_performance(uint64_t nanos, const char *format, ...); @@ -103,6 +107,13 @@ extern void trace_performance_since(uint64_t start, const char *format, ...); trace_strbuf_fl(TRACE_CONTEXT, __LINE__, key, data);\ } while (0) +#define trace_print_string_list_key(key, list, text) \ + do { \ + if (trace_pass_fl(key)) \ + trace_print_string_list_key_fl(TRACE_CONTEXT, \ + __LINE__, key, data);\ + } while (0) + #define trace_performance(nanos, ...) \ do { \ if (trace_pass_fl(&trace_perf_key)) \ @@ -127,6 +138,11 @@ extern void trace_argv_printf_fl(const char *file, int line, const char **argv, const char *format, ...); extern void trace_strbuf_fl(const char *file, int line, struct trace_key *key, const struct strbuf *data); +extern void trace_print_string_list_key_fl(const char *file, int line, + struct trace_key *key, + const struct string_list *p, + const char *text); + __attribute__((format (printf, 4, 5))) extern void trace_performance_fl(const char *file, int line, uint64_t nanos, const char *fmt, ...); From patchwork Mon Sep 10 21:58:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Beller X-Patchwork-Id: 10594815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C282814E5 for ; Mon, 10 Sep 2018 21:58:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC37029127 for ; Mon, 10 Sep 2018 21:58:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A035C29142; Mon, 10 Sep 2018 21:58:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49D9129127 for ; Mon, 10 Sep 2018 21:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbeIKCyp (ORCPT ); Mon, 10 Sep 2018 22:54:45 -0400 Received: from mail-io0-f201.google.com ([209.85.223.201]:56075 "EHLO mail-io0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbeIKCyp (ORCPT ); Mon, 10 Sep 2018 22:54:45 -0400 Received: by mail-io0-f201.google.com with SMTP id m15-v6so1931316ioj.22 for ; Mon, 10 Sep 2018 14:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1AODeIPDv46vexyadb6PwWFiND/V1p15PPZuEpBrJ/8=; b=D5ovJphD8fkK77S7gDsS15p0jqj0GTq/E2ejaQcHAip1fjb4pIdxcfY5Ff4VjJhAIh sHbmSXEV3Hx2zZkiw93b/dl0ROYLf5FIxCAu3izPZ+IH5RTyT7G99ge42UFvuSkzr/2b coMgnKvGeaafHQDdzRPzQlnROcuh5FJ6tPTblqukDEMV88Xvy/nu7OVdNPmdhTMFITnA RuhpEB8GOxTk4Z/rlZV4e0JoUtq3F0szxZOJHw4fPj0VHwYWxSSJ3sQ7SLxLuT5JkgF5 jHJ5P46GZcRJ5E+2awjNPwpTYN3qS0FpLDPVtcRiL1zWUKHHEl2lRbsAB4DNsquSiGBj d3Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1AODeIPDv46vexyadb6PwWFiND/V1p15PPZuEpBrJ/8=; b=bS7yNQa4jJMPHWtJHYp3RGtlprr7CHRJE5yMEZIybZi6tnedEGPoFwZm97kmh7D4rB 8Q3sJ1vc3sH8PJpMbSMRoe0wEFswEAylg5CtMz/W2KQ4a8mvo4pjxDsyHX3DeGNOHz1b lNNjIdI11bieRu6VS4iqFhlkCXRSWSHl+/Ae+Ky1lwpTLh2I/P/u9AwCsYDurlktbawb CV48yI66dyejA6K/oHVKqQDhtHwdLQsmsGBbCupIu4VxpLlVTt+FQ+Z5BYtsmPxsjkma pnP3jB9XR3YKqWCJ7HVfsgPPiK63a7KC7WaQEoMuhXAVto9G354qQDrdVbDTeIUU9y2b E4mg== X-Gm-Message-State: APzg51A8VgQ1nuGNyRxReoEdn5BX3MLdXuo3ieXipwegpi/wO3IBXGQS A1CRNvqhHNODXcA14oEqCnm8L3YIS21O X-Google-Smtp-Source: ANB0VdbJwB8zQHdP408T1tH85YXtr0PZbZb+EUUGAMuKD6MzHb1D1z1zAGzNP21oC7ni1IyKzqhBLMRphf/B X-Received: by 2002:a24:294d:: with SMTP id p74-v6mr21009252itp.36.1536616719095; Mon, 10 Sep 2018 14:58:39 -0700 (PDT) Date: Mon, 10 Sep 2018 14:58:31 -0700 In-Reply-To: <20180910215831.17608-1-sbeller@google.com> Message-Id: <20180910215831.17608-2-sbeller@google.com> Mime-Version: 1.0 References: <20180910215831.17608-1-sbeller@google.com> X-Mailer: git-send-email 2.19.0.rc2.392.g5ba43deb5a-goog Subject: [PATCH 2/2] string-list: remove unused function print_string_list From: Stefan Beller To: sbeller@google.com Cc: git@vger.kernel.org, gitster@pobox.com, peff@peff.net Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Stefan Beller --- string-list.c | 10 ---------- string-list.h | 8 -------- 2 files changed, 18 deletions(-) diff --git a/string-list.c b/string-list.c index 771c4550980..1f6063f2a27 100644 --- a/string-list.c +++ b/string-list.c @@ -195,16 +195,6 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c list->nr = list->alloc = 0; } - -void print_string_list(const struct string_list *p, const char *text) -{ - int i; - if ( text ) - printf("%s\n", text); - for (i = 0; i < p->nr; i++) - printf("%s:%p\n", p->items[i].string, p->items[i].util); -} - struct string_list_item *string_list_append_nodup(struct string_list *list, char *string) { diff --git a/string-list.h b/string-list.h index ff8f6094a33..18c718c12ce 100644 --- a/string-list.h +++ b/string-list.h @@ -113,14 +113,6 @@ typedef int (*string_list_each_func_t)(struct string_list_item *, void *); void filter_string_list(struct string_list *list, int free_util, string_list_each_func_t want, void *cb_data); -/** - * Dump a string_list to stdout, useful mainly for debugging - * purposes. It can take an optional header argument and it writes out - * the string-pointer pairs of the string_list, each one in its own - * line. - */ -void print_string_list(const struct string_list *p, const char *text); - /** * Free a string_list. The `string` pointer of the items will be freed * in case the `strdup_strings` member of the string_list is set. The