Skip to content

Commit 56b2562

Browse files
authored
Remove PantsDaemonStats class wrapper (#11003)
Follow up for https://github.com/pantsbuild/pants/pull/11000/files#r508861045
1 parent f4fb09f commit 56b2562

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/python/pants/bin/local_pants_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _finish_run(self, run_tracker: RunTracker, code: ExitCode) -> None:
214214
"""Cleans up the run tracker."""
215215

216216
metrics = self.graph_session.scheduler_session.metrics()
217-
run_tracker.pantsd_stats.set_scheduler_metrics(metrics)
217+
run_tracker.set_pantsd_scheduler_metrics(metrics)
218218
outcome = WorkUnit.SUCCESS if code == PANTS_SUCCEEDED_EXIT_CODE else WorkUnit.FAILURE
219219
run_tracker.set_root_outcome(outcome)
220220

src/python/pants/goal/run_tracker.py

+10-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import ast
55
import copy
6-
import dataclasses
76
import json
87
import multiprocessing
98
import os
@@ -13,7 +12,6 @@
1312
import uuid
1413
from collections import OrderedDict
1514
from contextlib import contextmanager
16-
from dataclasses import dataclass
1715
from typing import Any, Dict, Optional, Tuple
1816

1917
import requests
@@ -34,21 +32,6 @@
3432
from pants.version import VERSION
3533

3634

37-
@dataclass
38-
class PantsDaemonStats:
39-
"""Tracks various stats about the daemon."""
40-
41-
scheduler_metrics: Dict[str, int] = dataclasses.field(default_factory=dict)
42-
43-
def set_scheduler_metrics(self, scheduler_metrics: Dict[str, int]) -> None:
44-
self.scheduler_metrics = scheduler_metrics
45-
46-
def get_all(self) -> Dict[str, int]:
47-
for key in ["target_root_size", "affected_targets_size"]:
48-
self.scheduler_metrics.setdefault(key, 0)
49-
return self.scheduler_metrics
50-
51-
5235
class RunTrackerOptionEncoder(CoercingOptionEncoder):
5336
"""Use the json encoder we use for making options hashable to support datatypes.
5437
@@ -175,7 +158,6 @@ def __init__(self, *args, **kwargs):
175158
self.run_info = None
176159
self.cumulative_timings = None
177160
self.self_timings = None
178-
self.pantsd_stats = None
179161

180162
# Initialized in `start()`.
181163
self.report = None
@@ -273,8 +255,8 @@ def start(self, all_options: Options, run_start_time: float) -> None:
273255

274256
# Time spent in a workunit, not including its children.
275257
self.self_timings = AggregatedTimings(os.path.join(self.run_info_dir, "self_timings"))
276-
# Daemon stats.
277-
self.pantsd_stats = PantsDaemonStats()
258+
# pantsd stats.
259+
self._pantsd_metrics: Dict[str, int] = dict()
278260

279261
self._all_options = all_options
280262

@@ -294,6 +276,13 @@ def set_root_outcome(self, outcome):
294276
"""Useful for setup code that doesn't have a reference to a workunit."""
295277
self._main_root_workunit.set_outcome(outcome)
296278

279+
def set_pantsd_scheduler_metrics(self, metrics: Dict[str, int]) -> None:
280+
self._pantsd_metrics = metrics
281+
282+
@property
283+
def pantsd_scheduler_metrics(self) -> Dict[str, int]:
284+
return dict(self._pantsd_metrics) # defensive copy
285+
297286
@property
298287
def logger(self):
299288
return self._logger
@@ -485,7 +474,7 @@ def run_information(self):
485474
def _stats(self) -> dict:
486475
stats = {
487476
"run_info": self.run_information(),
488-
"pantsd_stats": self.pantsd_stats.get_all(),
477+
"pantsd_stats": self.pantsd_scheduler_metrics,
489478
"cumulative_timings": self.cumulative_timings.get_all(),
490479
"recorded_options": self.get_options_to_record(),
491480
}

0 commit comments

Comments
 (0)