1 | /** |
2 | * Copyright (c) Glow Contributors. See CONTRIBUTORS file. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | #ifndef GLOW_RUNTIME_HEALTHMONITOR_H |
17 | #define GLOW_RUNTIME_HEALTHMONITOR_H |
18 | |
19 | #include <memory> |
20 | #include <vector> |
21 | |
22 | namespace glow { |
23 | |
24 | /// Interface for exporting runtime statistics. The base implementation |
25 | /// delegates to any subclass registered via `registerStatsExporter`. |
26 | class DeviceHealthMonitor { |
27 | public: |
28 | /// Dtor. |
29 | virtual ~DeviceHealthMonitor() = default; |
30 | |
31 | /// Start monitoring the device health |
32 | virtual void start() = 0; |
33 | }; |
34 | |
35 | /// Registry of StatsExporters. |
36 | class DeviceHealthMonitorRegistry final { |
37 | public: |
38 | /// Start all the device health monitors |
39 | void start() { |
40 | for (auto *monitor : monitors_) { |
41 | monitor->start(); |
42 | } |
43 | } |
44 | |
45 | /// Register a DeviceHealthMonitor. |
46 | void registerDeviceHealthMonitor(DeviceHealthMonitor *monitor); |
47 | |
48 | /// Revoke a DeviceHealthMonitor. |
49 | void revokeDeviceHealthMonitor(DeviceHealthMonitor *exporter); |
50 | |
51 | /// Static singleton DeviceHealthMonitor. |
52 | static std::shared_ptr<DeviceHealthMonitorRegistry> Monitors(); |
53 | |
54 | private: |
55 | /// Registered StatsExporters. |
56 | std::vector<DeviceHealthMonitor *> monitors_; |
57 | }; |
58 | |
59 | } // namespace glow |
60 | |
61 | #endif // GLOW_RUNTIME_HEALTHMONITOR_H |
62 | |