Skip to content

Commit

Permalink
Add More Metrics to be Logged by LoggerHook (#475)
Browse files Browse the repository at this point in the history
* Added more metrics

* Added metrics and tests

* Added client ID env var

* Revert "Added client ID env var"

This reverts commit 04a0df9.

* Updated names

* Updated names and tests
  • Loading branch information
surge119 authored Aug 2, 2024
1 parent 81dfbe6 commit e4d9bbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/fixit/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def visit_hook(name: str) -> Iterator[None]:
finally:
duration_us = int(1000 * 1000 * (time.perf_counter() - start))
LOG.debug(f"PERF: {name} took {duration_us} µs")
self.metrics[name] += duration_us
self.metrics[f"Duration.{name}"] += duration_us

metadata_cache: Mapping[ProviderT, object] = {}
needs_repo_manager: Set[ProviderT] = set()
Expand All @@ -103,14 +103,20 @@ def visit_hook(name: str) -> Iterator[None]:
wrapper.visit_batched(rules)
count = 0
for rule in rules:
self.metrics[f"Count.{rule.name}"] = len(rule._violations)
self.metrics[f"FixCount.{rule.name}"] = 0
for violation in rule._violations:
count += 1

if violation.replacement:
self.metrics[f"FixCount.{rule.name}"] += 1
diff = diff_violation(self.path, self.module, violation)
violation = replace(violation, diff=diff)

yield violation

self.metrics["Count.Total"] = count

if metrics_hook:
metrics_hook(self.metrics)

Expand Down
7 changes: 5 additions & 2 deletions src/fixit/tests/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ def test_timing(self) -> None:
rule = NoopRule()
for _ in self.runner.collect_violations([rule], Config()):
pass # exhaust the generator
self.assertIn("NoopRule.visit_Module", self.runner.metrics)
self.assertIn("NoopRule.leave_Module", self.runner.metrics)
self.assertIn("Duration.NoopRule.visit_Module", self.runner.metrics)
self.assertIn("Duration.NoopRule.leave_Module", self.runner.metrics)
self.assertGreaterEqual(self.runner.metrics["NoopRule.visit_Module"], 0)
self.assertIn("Count.Noop", self.runner.metrics)
self.assertIn("FixCount.Noop", self.runner.metrics)
self.assertIn("Count.Total", self.runner.metrics)

def test_timing_hook(self) -> None:
rule = NoopRule()
Expand Down

0 comments on commit e4d9bbd

Please sign in to comment.