3
3
4
4
import ast
5
5
import copy
6
- import dataclasses
7
6
import json
8
7
import multiprocessing
9
8
import os
13
12
import uuid
14
13
from collections import OrderedDict
15
14
from contextlib import contextmanager
16
- from dataclasses import dataclass
17
15
from typing import Any , Dict , Optional , Tuple
18
16
19
17
import requests
34
32
from pants .version import VERSION
35
33
36
34
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
-
52
35
class RunTrackerOptionEncoder (CoercingOptionEncoder ):
53
36
"""Use the json encoder we use for making options hashable to support datatypes.
54
37
@@ -175,7 +158,6 @@ def __init__(self, *args, **kwargs):
175
158
self .run_info = None
176
159
self .cumulative_timings = None
177
160
self .self_timings = None
178
- self .pantsd_stats = None
179
161
180
162
# Initialized in `start()`.
181
163
self .report = None
@@ -273,8 +255,8 @@ def start(self, all_options: Options, run_start_time: float) -> None:
273
255
274
256
# Time spent in a workunit, not including its children.
275
257
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 ()
278
260
279
261
self ._all_options = all_options
280
262
@@ -294,6 +276,13 @@ def set_root_outcome(self, outcome):
294
276
"""Useful for setup code that doesn't have a reference to a workunit."""
295
277
self ._main_root_workunit .set_outcome (outcome )
296
278
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
+
297
286
@property
298
287
def logger (self ):
299
288
return self ._logger
@@ -485,7 +474,7 @@ def run_information(self):
485
474
def _stats (self ) -> dict :
486
475
stats = {
487
476
"run_info" : self .run_information (),
488
- "pantsd_stats" : self .pantsd_stats . get_all () ,
477
+ "pantsd_stats" : self .pantsd_scheduler_metrics ,
489
478
"cumulative_timings" : self .cumulative_timings .get_all (),
490
479
"recorded_options" : self .get_options_to_record (),
491
480
}
0 commit comments