From patchwork Tue Dec 28 19:36:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 12700559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13DA2C433FE for ; Tue, 28 Dec 2021 19:36:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237184AbhL1Tgs (ORCPT ); Tue, 28 Dec 2021 14:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235996AbhL1Tgq (ORCPT ); Tue, 28 Dec 2021 14:36:46 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ED9FC06173E for ; Tue, 28 Dec 2021 11:36:46 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id k18so3436237wrg.11 for ; Tue, 28 Dec 2021 11:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=A5ypdyfHh2bAKzMpBSxox7x/1MKcxEji0wJh6spOIZg=; b=S9wspW/MArss94cLLxWaEOLiudzYsa+10Sc2/9W8JBCTPc1qjHU2Ypzp+Gz7LCu16o lwUwikoExcZaai2KW5h2pAr7hxyJI0Lv/KqiVNi2ZT7TT1pzdzky7V0hAIgMg3wslYvN vnzARfhHvt62F+/okDcQPUGmNeMARm5n/mNRcWuEpbafHSICkY5kC85+WwnzV9KaPFBb SFmtoFam3RS7HjkofkD6sOXXlCnLdp+eXezDCAgNVBh9eYy3UDBk4oitFLcQ3mJjlROm 8s1U0grS94Cy2E31QIoe12TEF1/jaoxrgolTlMRkarQ/BsD3CzVc+uUCLCDrL9jLwfD2 TIxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=A5ypdyfHh2bAKzMpBSxox7x/1MKcxEji0wJh6spOIZg=; b=THKYKGPDM8oLFU6WIZTN2nAZm0tYgNT9MvsOlGi3NSxAwFVgwb3hIp2MJJhG/3IfTN 3cGbiDLP+vvGkV8U5L4DG7/8/j74GFKzuCIHs2d/0Om/eFOci+EONB8M6TrbkOTk/EKd sswm4FwEfaFxo81VJzH/ftVgWWiW6w3czjdUYQBBx3Zl6Tj9FVLRG7xGQfxXz9JuYc1B 8uQv64F8djqgGIjSwufqpS+4MoHPh47t+oW2B34Ycx51+qw82l5e5jtHREn6CJha2a9h M1FCvKHliMRij7XvdQLkrRCh+1sBsgAoKQwPiAhOav8OcEPlNNPm0Le9lvAiOFzuaxWF Cnog== X-Gm-Message-State: AOAM5305VE7N0rV+o+3zTi+2Sxl4ZjyW7RCb8H8xuQDG0S8Spx7+iL4/ LAVAqkHA6bu8mrME4A1McNjxTCjoLRE= X-Google-Smtp-Source: ABdhPJzjzzWDkVwG8EGLRIVKQaRJeX9MDP94u6rQgNAgY/0vWrjWv3ijKeL7c1sFoc2Mge8M7n+m6Q== X-Received: by 2002:a5d:610c:: with SMTP id v12mr17590667wrt.410.1640720203758; Tue, 28 Dec 2021 11:36:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c2sm20886571wri.50.2021.12.28.11.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Dec 2021 11:36:43 -0800 (PST) Message-Id: In-Reply-To: References: From: "Jeff Hostetler via GitGitGadget" Date: Tue, 28 Dec 2021 19:36:33 +0000 Subject: [PATCH v2 0/9] Trace2 stopwatch timers and global counters Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Jeff Hostetler , Derrick Stolee , Matheus Tavares , Johannes Sixt , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Here is version 2 of my series to add stopwatch timers and global counters to Trace2. I think this version address all of the comments made on V1. * I moved the Trace2 "thread_name" field into a flex-array at the bottom of the thread local storage block. This avoids the issue of whether it should be allocated and by whom and its const-ness. * I moved the truncation of the "thread_name" into the "_perf" target (which was the only target that actually cared) so that columns still line up. * Started phasing out the TLS and CTX acronyms in the Trace2 code. There is an ambiguity between "thread local storage" and "transport layer security" that caused some confusion. In this patch series, I eliminated new uses of the TLS term. A future series will be needed to actually rename variables, functions, and data types to fully eliminate the TLS term. * In V1 I included a change to the "_event" target version number. I've rolled this back in favor of Ævar's new proposal describing when/why we change it. (That proposal is independent of this series.) * In V1 I had reported timer values {total, min, max} in floating point seconds with microsecond precision (using a "%9.6f" format) and was internally accumulating interval times in microseconds. After some discussion, I've changed this to accumulate in nanoseconds and report integer nanoseconds. This may avoid some accumulated round off error. (However, on some platforms getnanotime() only has microsecond accuracy, so this increased precision may be misleading.) * Refactor the pattern model used in the unit tests to make it easier to visually parse. * Some cosmetic cleanup of the private timer and counter API. There were additional requests/comments that I have not addressed in this version because I think they should be in their own top-level topic in a future series rather than appended onto this series: * The full elimination of the TLS and CTX terms. * Ævar proposed a new test_trace2 test function to parse trace output. This would be similar to (or a generalization of) the test_region function that we already have in test-lib-functions.sh. * Ævar proposed a large refactor of the "_perf" target to have a "fmt()" varargs function to reduce the amount of copy-n-pasted code in many of the "fn" event handlers. This looks like a good change based on the mockup but is a large refactor. * Ævar proposed a new rationale for when/why we change the "_event" version number. That text can be added to the design document independently. Jeff Hostetler (9): trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctx trace2: convert tr2tls_thread_ctx.thread_name from strbuf to flex array trace2: defer free of thread local storage until program exit. trace2: add thread-name override to event target trace2: add thread-name override to perf target trace2: add timer events to perf and event target formats trace2: add stopwatch timers trace2: add counter events to perf and event target formats trace2: add global counters Documentation/technical/api-trace2.txt | 157 +++++++++++++++++++++ Makefile | 2 + t/helper/test-trace2.c | 183 +++++++++++++++++++++++++ t/t0211-trace2-perf.sh | 88 ++++++++++++ t/t0212-trace2-event.sh | 86 ++++++++++++ trace2.c | 106 ++++++++++++++ trace2.h | 75 ++++++++++ trace2/tr2_ctr.c | 67 +++++++++ trace2/tr2_ctr.h | 79 +++++++++++ trace2/tr2_tgt.h | 39 ++++++ trace2/tr2_tgt_event.c | 111 +++++++++++---- trace2/tr2_tgt_normal.c | 2 + trace2/tr2_tgt_perf.c | 114 ++++++++++----- trace2/tr2_tls.c | 119 +++++++++++++--- trace2/tr2_tls.h | 51 +++++-- trace2/tr2_tmr.c | 136 ++++++++++++++++++ trace2/tr2_tmr.h | 139 +++++++++++++++++++ 17 files changed, 1465 insertions(+), 89 deletions(-) create mode 100644 trace2/tr2_ctr.c create mode 100644 trace2/tr2_ctr.h create mode 100644 trace2/tr2_tmr.c create mode 100644 trace2/tr2_tmr.h base-commit: e773545c7fe7eca21b134847f4fc2cbc9547fa14 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1099%2Fjeffhostetler%2Ftrace2-stopwatch-v2-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1099/jeffhostetler/trace2-stopwatch-v2-v2 Pull-Request: https://github.com/gitgitgadget/git/pull/1099 Range-diff vs v1: 1: 96f6896a13e = 1: 96f6896a13e trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctx 2: 3a4fe07e40e ! 2: ff8df1b148e trace2: convert tr2tls_thread_ctx.thread_name from strbuf to char* @@ Metadata Author: Jeff Hostetler ## Commit message ## - trace2: convert tr2tls_thread_ctx.thread_name from strbuf to char* + trace2: convert tr2tls_thread_ctx.thread_name from strbuf to flex array - Use a 'char *' to hold the thread name rather than a 'struct strbuf'. - The thread name is set when the thread is created and should not be - be modified afterwards. Replace the strbuf with an allocated pointer - to make that more clear. + Move the thread name to a flex array at the bottom of the Trace2 + thread local storage data and get rid of the strbuf. - This was discussed in: https://lore.kernel.org/all/xmqqa6kdwo24.fsf@gitster.g/ + Let the flex array have the full computed value of the thread name + without truncation. + + Change the PERF target to truncate the thread name so that the columns + still line up. Signed-off-by: Jeff Hostetler @@ trace2/tr2_tgt_event.c: static void event_fmt_prepare(const char *event_name, co * In brief mode, only emit