Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: client/third_party/infra_libs/ts_mon/common/metric_store.py

Issue 2465423002: Roll infra_libs to 564aaf7480f24c90687df79d9cef910cc342a54d (Closed)
Patch Set: update readmes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import collections 5 import collections
6 import copy 6 import copy
7 import itertools 7 import itertools
8 import threading 8 import threading
9 import time 9 import time
10 10
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 def iter_field_values(self, name): 251 def iter_field_values(self, name):
252 return itertools.chain.from_iterable( 252 return itertools.chain.from_iterable(
253 x.iteritems() for _, x in self._entry(name).values.iter_targets()) 253 x.iteritems() for _, x in self._entry(name).values.iter_targets())
254 254
255 def get_all(self): 255 def get_all(self):
256 # Make a copy of the metric values in case another thread (or this 256 # Make a copy of the metric values in case another thread (or this
257 # generator's consumer) modifies them while we're iterating. 257 # generator's consumer) modifies them while we're iterating.
258 with self._thread_lock: 258 with self._thread_lock:
259 values = copy.copy(self._values) 259 values = copy.copy(self._values)
260 end_time = self._time_fn()
260 261
261 for name, metric_values in values.iteritems(): 262 for name, metric_values in values.iteritems():
262 if name not in self._state.metrics: 263 if name not in self._state.metrics:
263 continue 264 continue
264 start_time = metric_values.start_time 265 start_time = metric_values.start_time
265 for target, fields_values in metric_values.values.iter_targets(): 266 for target, fields_values in metric_values.values.iter_targets():
266 yield target, self._state.metrics[name], start_time, fields_values 267 yield (target, self._state.metrics[name], start_time, end_time,
268 fields_values)
267 269
268 def set(self, name, fields, target_fields, value, enforce_ge=False): 270 def set(self, name, fields, target_fields, value, enforce_ge=False):
269 with self._thread_lock: 271 with self._thread_lock:
270 if enforce_ge: 272 if enforce_ge:
271 old_value = self._entry(name).get_value(fields, target_fields, 0) 273 old_value = self._entry(name).get_value(fields, target_fields, 0)
272 if value < old_value: 274 if value < old_value:
273 raise errors.MonitoringDecreasingValueError(name, old_value, value) 275 raise errors.MonitoringDecreasingValueError(name, old_value, value)
274 276
275 self._entry(name).set_value(fields, target_fields, value) 277 self._entry(name).set_value(fields, target_fields, value)
276 278
(...skipping 15 matching lines...) Expand all
292 294
293 def reset_for_unittest(self, name=None): 295 def reset_for_unittest(self, name=None):
294 if name is not None: 296 if name is not None:
295 self._reset(name) 297 self._reset(name)
296 else: 298 else:
297 for name in self._values.keys(): 299 for name in self._values.keys():
298 self._reset(name) 300 self._reset(name)
299 301
300 def _reset(self, name): 302 def _reset(self, name):
301 self._values[name] = MetricValues(self, self._start_time(name)) 303 self._values[name] = MetricValues(self, self._start_time(name))
OLDNEW
« no previous file with comments | « client/third_party/infra_libs/ts_mon/common/interface.py ('k') | client/third_party/infra_libs/ts_mon/common/metrics.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698