From 276b30506c1f6f41d2f6533f3a0be65f9c89e7fe Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 5 Aug 2024 16:54:42 -0300 Subject: [PATCH] fix: Add elapsed time logging to print statements --- aider/repomap.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index 932233007..1f2d109a0 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -3,6 +3,7 @@ import math import os import random import sys +import time import warnings from collections import Counter, defaultdict, namedtuple from importlib import resources @@ -23,6 +24,15 @@ from aider.dump import dump # noqa: F402,E402 Tag = namedtuple("Tag", "rel_fname fname line name kind".split()) +def print_elapsed(message): + current_time = time.time() + if hasattr(print_elapsed, 'last_time'): + elapsed = current_time - print_elapsed.last_time + print(f"{message}: {elapsed:.2f} seconds") + else: + print(f"{message}: (first measurement)") + print_elapsed.last_time = current_time + class RepoMap: CACHE_VERSION = 3 @@ -246,7 +256,7 @@ class RepoMap: fnames = tqdm(fnames) self.cache_missing = False - print('tags') + print_elapsed('Starting tags processing') for fname in fnames: if not Path(fname).is_file(): @@ -284,7 +294,7 @@ class RepoMap: elif tag.kind == "ref": references[tag.name].append(rel_fname) - print('graph') + print_elapsed('Finished tags processing, starting graph creation') ## # dump(defines) # dump(references) @@ -325,13 +335,13 @@ class RepoMap: else: pers_args = dict() - print('rank') + print_elapsed('Starting pagerank calculation') try: ranked = nx.pagerank(G, weight="weight", **pers_args) except ZeroDivisionError: return [] - print('dist rank') + print_elapsed('Starting rank distribution') # distribute the rank from each source node, across all of its out edges ranked_definitions = defaultdict(float) @@ -349,7 +359,7 @@ class RepoMap: # dump(ranked_definitions) - print('ranked_tags') + print_elapsed('Starting ranked tags processing') for (fname, ident), rank in ranked_definitions: # print(f"{rank:.03f} {fname} {ident}") if fname in chat_rel_fnames: @@ -370,7 +380,7 @@ class RepoMap: for fname in rel_other_fnames_without_tags: ranked_tags.append((fname,)) - print('done') + print_elapsed('Finished processing') return ranked_tags def get_ranked_tags_map(