From patchwork Thu Jan 7 16:32:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12004419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 250FBC433E0 for ; Thu, 7 Jan 2021 16:33:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9EE0233FC for ; Thu, 7 Jan 2021 16:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728142AbhAGQc4 (ORCPT ); Thu, 7 Jan 2021 11:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726468AbhAGQc4 (ORCPT ); Thu, 7 Jan 2021 11:32:56 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE47C0612F5 for ; Thu, 7 Jan 2021 08:32:15 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id y17so6219391wrr.10 for ; Thu, 07 Jan 2021 08:32:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Dkys2TZsvFsYLc4Nzw+wTJ/OAwTXIQdwI+QSCleLVFI=; b=UZY8mM8r/vYJvIlQl61Wo9xVpINe7M5uosebvOlbbsTpoBPKw2DOeNaDnQFgizrkYr sr4eJbAcm9HgKG6c0eaTH3kXEfcnELoK5WV90W3e4agXKnvn73VVJ0SphuDEeZmT4t/f scwQrDZHkoaT2MJICXKEQw+0eSa+1PJ2RguGS8zBt8VSKgNMmfnuUsY2TJ+kkncQoeoN itCrm8vq8L6gLXrZjyqDX8AALDjlkqx1oNr9MszGbIcehRSWhUXNzh/ttS6uoCZOnkxS xCie63w64emwXGyP8DsAO0zOKPCZZxg7G1o1JjoT4NxomOkHZ34F6D1IGPFwf4u/q7R8 SoAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Dkys2TZsvFsYLc4Nzw+wTJ/OAwTXIQdwI+QSCleLVFI=; b=Pi/X0NS1xZXqd3Cm2yrnyIJ82o8WJyNBPfx3KGNjT8ZSpqs7Q4RmNEe6TPo/hUGMr3 CwlXl0vcdu8GRzqZtC/qAJ4ZP4VyLSnNYV8Cs7MLz8LDPjjpG+RDkYy8Ct9VpBfY0acA dg8qEj8SnvMq2KAg11nc6EZORwkEhv8UdB6MsOwaUv5HAxqYM+fAeYPmFXJBcq6n3xgt Qq6fICyyldFdXuVUBtHmg5Rq3v/7+w/hZNmg5WYw5wwg05hZN0rPbtSw4w8nZA0ZOjCP WTsEtyYK/9HJkqzjpShFnyXYlo8DL3YjNbqk9+Ww0XIsWhHdfL4zmLQ/6bhRikKbaRQj hwkQ== X-Gm-Message-State: AOAM532FAiOtCKP3KUKwLk8cTH1iTcJQ80LTYglGuoJuBNTVORKWctbR nChgDM2U+t/LceUmk3rLPt+1ZxAytjg= X-Google-Smtp-Source: ABdhPJwY6GIr98pgaio6g7WsZvlorfnVuX71zMUCBAahLn5vdCdZ7dhl78cqhlOjZ7/YGKCt7C4UqQ== X-Received: by 2002:adf:f605:: with SMTP id t5mr9564439wrp.39.1610037134253; Thu, 07 Jan 2021 08:32:14 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s63sm9493806wms.18.2021.01.07.08.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 08:32:13 -0800 (PST) Message-Id: <0e500c86f397987c4d03beac52b1e91f683e4d11.1610037131.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Jan 2021 16:32:02 +0000 Subject: [PATCH v3 01/10] tree-walk: report recursion counts Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, newren@gmail.com, Derrick Stolee , =?utf-8?b?UmVuw6k=?= Scharfe , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The traverse_trees() method recursively walks through trees, but also prunes the tree-walk based on a callback. Some callers, such as unpack_trees(), are quite complicated and can have wildly different performance between two different commands. Create constants that count these values and then report the results at the end of a process. These counts are cumulative across multiple "root" instances of traverse_trees(), but they provide reproducible values for demonstrating improvements to the pruning algorithm when possible. This change is modeled after a similar statistics reporting in 42e50e78 (revision.c: add trace2 stats around Bloom filter usage, 2020-04-06). Signed-off-by: Derrick Stolee --- tree-walk.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tree-walk.c b/tree-walk.c index 0160294712b..2d6226d5f18 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -4,6 +4,7 @@ #include "object-store.h" #include "tree.h" #include "pathspec.h" +#include "json-writer.h" static const char *get_mode(const char *str, unsigned int *modep) { @@ -167,6 +168,25 @@ int tree_entry_gently(struct tree_desc *desc, struct name_entry *entry) return 1; } +static int traverse_trees_atexit_registered; +static int traverse_trees_count; +static int traverse_trees_cur_depth; +static int traverse_trees_max_depth; + +static void trace2_traverse_trees_statistics_atexit(void) +{ + struct json_writer jw = JSON_WRITER_INIT; + + jw_object_begin(&jw, 0); + jw_object_intmax(&jw, "traverse_trees_count", traverse_trees_count); + jw_object_intmax(&jw, "traverse_trees_max_depth", traverse_trees_max_depth); + jw_end(&jw); + + trace2_data_json("traverse_trees", the_repository, "statistics", &jw); + + jw_release(&jw); +} + void setup_traverse_info(struct traverse_info *info, const char *base) { size_t pathlen = strlen(base); @@ -180,6 +200,11 @@ void setup_traverse_info(struct traverse_info *info, const char *base) info->namelen = pathlen; if (pathlen) info->prev = &dummy; + + if (trace2_is_enabled() && !traverse_trees_atexit_registered) { + atexit(trace2_traverse_trees_statistics_atexit); + traverse_trees_atexit_registered = 1; + } } char *make_traverse_path(char *path, size_t pathlen, @@ -416,6 +441,12 @@ int traverse_trees(struct index_state *istate, int interesting = 1; char *traverse_path; + traverse_trees_count++; + traverse_trees_cur_depth++; + + if (traverse_trees_cur_depth > traverse_trees_max_depth) + traverse_trees_max_depth = traverse_trees_cur_depth; + if (n >= ARRAY_SIZE(entry)) BUG("traverse_trees() called with too many trees (%d)", n); @@ -515,6 +546,8 @@ int traverse_trees(struct index_state *istate, free(traverse_path); info->traverse_path = NULL; strbuf_release(&base); + + traverse_trees_cur_depth--; return error; }