YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/test_graph.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
#ifndef YB_UTIL_TEST_GRAPH_H
33
#define YB_UTIL_TEST_GRAPH_H
34
35
#include <memory>
36
#include <string>
37
#include <unordered_map>
38
39
#include "yb/gutil/ref_counted.h"
40
#include "yb/gutil/macros.h"
41
#include "yb/gutil/walltime.h"
42
#include "yb/util/countdown_latch.h"
43
#include "yb/util/faststring.h"
44
#include "yb/util/locks.h"
45
46
namespace yb {
47
48
class Thread;
49
50
class TimeSeries {
51
 public:
52
  void AddValue(double val);
53
  void SetValue(double val);
54
55
  double value() const;
56
57
 private:
58
  friend class TimeSeriesCollector;
59
60
  TimeSeries() :
61
    val_(0)
62
12
  {}
63
64
  mutable simple_spinlock lock_;
65
  double val_;
66
67
  DISALLOW_COPY_AND_ASSIGN(TimeSeries);
68
};
69
70
class TimeSeriesCollector {
71
 public:
72
  explicit TimeSeriesCollector(std::string scope);
73
74
  ~TimeSeriesCollector();
75
76
  std::shared_ptr<TimeSeries> GetTimeSeries(const std::string &key);
77
  void StartDumperThread();
78
  void StopDumperThread();
79
80
 private:
81
  void DumperThread();
82
  void BuildMetricsString(WallTime time_since_start, faststring *dst_buf) const;
83
84
  std::string scope_;
85
86
  typedef std::unordered_map<std::string, std::shared_ptr<TimeSeries> > SeriesMap;
87
  SeriesMap series_map_;
88
  mutable Mutex series_lock_;
89
90
  scoped_refptr<yb::Thread> dumper_thread_;
91
92
  // Latch used to stop the dumper_thread_. When the thread is started,
93
  // this is set to 1, and when the thread should exit, it is counted down.
94
  CountDownLatch exit_latch_;
95
96
  bool started_;
97
98
  DISALLOW_COPY_AND_ASSIGN(TimeSeriesCollector);
99
};
100
101
} // namespace yb
102
103
#endif // YB_UTIL_TEST_GRAPH_H