From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kOlhASOVm2JJfgEAbAwnHQ (envelope-from ) for ; Sat, 04 Jun 2022 19:23:47 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id QGdxACOVm2JQkgAAG6o9tA (envelope-from ) for ; Sat, 04 Jun 2022 19:23:47 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C03101CCE6 for ; Sat, 4 Jun 2022 19:23:46 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1BC175F7C8; Sat, 4 Jun 2022 17:23:34 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 3654C5F7C1 for ; Sat, 4 Jun 2022 17:23:31 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 89F6F5FC0D; Sat, 4 Jun 2022 13:23:30 -0400 (EDT) Received: (nullmailer pid 1150085 invoked by uid 1000); Sat, 04 Jun 2022 17:23:25 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH v3 11/17] CLI/git: add @timed decorator, time a few functions Date: Sat, 4 Jun 2022 14:23:07 -0300 Message-Id: <20220604172313.1149879-12-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220604172313.1149879-1-david@tethera.net> References: <20220604172313.1149879-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CWCDZ4DZ5O2GT22BJCQAOVLT62SOHWIO X-Message-ID-Hash: CWCDZ4DZ5O2GT22BJCQAOVLT62SOHWIO X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654363426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=MiuirfbMbY9aYWeOqT5YXRmF5vA3Fli3rblF+ZpyTUM=; b=g1Mf7nn6Vb1ge2Gx6/K2RWjEvmK+5ot41ORwFDmTFfnYsU+Xv4IJ1yUWm8lUkonvBYJKx1 Z9deid7f7t/nse4J83ohGTmUCK/84dGyx/dneVUqjdL1ES3n+8ahQsjZbb1Tn6IE5U5I8U 63N7YCNgT1oRZM1/jI4+cHoRfv2VzL5kNKmoSHjCBMUGOA3DyBVSK3MLjwo1FQSzoBvx1U yYyHFBWDqXsNedE+LSnSyq89Sp4SkuJmtjMw6dyjtSaOnFf+636+g4vgaOmDD8B9++navU mKK6Tklvn+Dz62GgrcOrWjRQBx4Y+VhOMLDq1m9k+hdLtmc39PGqAdNeKFd1Mg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654363426; a=rsa-sha256; cv=none; b=jLq1YaAnmbpXo5soJzQRaYD/FxIIV9ZTyyeyFTURm+DGKsZLNbv3mWWIIf8cZvOpkiDULx /+Li8dYq89kSV3xfTmvNM99A7gT9HkT5Fx7SjcWmcJPu5ApCfjljSaVkAFMJehXlkRos7J 3LXcoAKfbkfPQaDC9OMPlg2VO/AOTXj5tfK9OfSLL0N/MDIgAt72mlxcDV3mhR+yM82evZ ts7VJcuqZZa1wkLTCkt6wPMUbO5Ya7fU6uljf9cGMVOEkLRB3GNa6bEbSgU2Vf5JDW/TKP 7hOxF+n7NAQVQmwgv6b6a3x/6ALoS7naWSrCkz1kEB+asu5gc4JREleiLMO0sg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.05 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: C03101CCE6 X-Spam-Score: -1.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: u0MSRNeqxRx0 Perf will show which binaries are using the CPU cycles, and standard python profilers will show which python functions, but neither is great at finding which call to an external binary is taking time, or locating I/O hotspots. --- notmuch-git.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/notmuch-git.py b/notmuch-git.py index badf9000..6ea50fe8 100644 --- a/notmuch-git.py +++ b/notmuch-git.py @@ -89,6 +89,20 @@ def _xapian_unquote(string): return string +def timed(fn): + """Timer decorator""" + from time import perf_counter + + def inner(*args, **kwargs): + start_time = perf_counter() + rval = fn(*args, **kwargs) + end_time = perf_counter() + _LOG.info('{0}: {1:.8f}s elapsed'.format(fn.__name__, end_time - start_time)) + return rval + + return inner + + class SubprocessError(RuntimeError): "A subprocess exited with a nonzero status" def __init__(self, args, status, stdout=None, stderr=None): @@ -321,6 +335,7 @@ def commit(treeish='HEAD', message=None): _git(args=['read-tree', treeish], wait=True) raise +@timed def _update_index(status): with _git( args=['update-index', '--index-info'], @@ -561,6 +576,7 @@ def _is_unmerged(ref='@{upstream}'): return base != fetch_head +@timed def get_status(): status = { 'deleted': {}, @@ -581,7 +597,7 @@ def get_status(): _os.remove(index) return status - +@timed def _index_tags(): "Write notmuch tags to the nmbug.index." path = _os.path.join(NOTMUCH_GIT_DIR, 'nmbug.index') @@ -630,6 +646,7 @@ def _index_tags_for_message(id, status, tags): yield '{mode} {hash}\t{path}\n'.format(mode=mode, hash=hash, path=path) +@timed def _diff_index(index, filter): """ Get an {id: {tag, ...}} dict for a given filter. -- 2.35.2