Skip to content

Commit 9b61784

Browse files
committed
metrics
1 parent 4c4e028 commit 9b61784

File tree

6 files changed

+93
-22
lines changed

6 files changed

+93
-22
lines changed

ucm/shared/metrics/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
file(GLOB_RECURSE UCMMETRICS_CC_SOURCE_FILES "./cc/*.cc")
22
add_library(metrics STATIC ${UCMMETRICS_CC_SOURCE_FILES})
33
target_include_directories(metrics PUBLIC
4-
${CMAKE_CURRENT_SOURCE_DIR}/cc
4+
${CMAKE_CURRENT_SOURCE_DIR}/cc/api
5+
${CMAKE_CURRENT_SOURCE_DIR}/cc/domain
56
)
67

78
file(GLOB_RECURSE UCMMETRICS_CPY_SOURCE_FILES CONFIGURE_DEPENDS "./cpy/*.cc")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
* */
24+
#include "metrics_api.h"
25+
namespace UC::Metrics {
26+
27+
void CreateStats(const std::string& name, std::string& type) { Metrics::GetInstance().CreateStats(name, type); }
28+
29+
void UpdateStats(const std::string& name, double value)
30+
{
31+
Metrics::GetInstance().UpdateStats(name, value);
32+
}
33+
34+
void UpdateStats(const std::unordered_map<std::string, double>& values)
35+
{
36+
Metrics::GetInstance().UpdateStats(values);
37+
}
38+
39+
std::tuple<
40+
std::unordered_map<std::string, double>,
41+
std::unordered_map<std::string, double>,
42+
std::unordered_map<std::string, std::vector<double>>
43+
> GetAllStatsAndClear()
44+
{
45+
return Metrics::GetInstance().GetAllStatsAndClear();
46+
}
47+
48+
} // namespace UC::Metrics
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
* */
24+
#ifndef UNIFIEDCACHE_METRICS_API_H
25+
#define UNIFIEDCACHE_METRICS_API_H
26+
#include "metrics.h"
27+
28+
namespace UC::Metrics {
29+
void CreateStats(const std::string& name, std::string& type);
30+
31+
void UpdateStats(const std::string& name, double value);
32+
33+
void UpdateStats(const std::unordered_map<std::string, double>& values);
34+
35+
std::tuple<
36+
std::unordered_map<std::string, double>,
37+
std::unordered_map<std::string, double>,
38+
std::unordered_map<std::string, std::vector<double>>
39+
> GetAllStatsAndClear();
40+
41+
} // namespace UC::Metrics
42+
#endif

ucm/shared/metrics/cpy/metrics.py.cc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,11 @@
2323
* */
2424
#include <pybind11/pybind11.h>
2525
#include <pybind11/stl.h>
26-
#include "metrics.h"
26+
#include "metrics_api.h"
2727

2828
namespace py = pybind11;
2929
namespace UC::Metrics {
3030

31-
inline void CreateStats(const std::string& name, std::string& type) {
32-
Metrics::GetInstance().CreateStats(name, type);
33-
}
34-
35-
inline void UpdateStats(const std::string& name, double value) {
36-
Metrics::GetInstance().UpdateStats(name, value);
37-
}
38-
39-
inline void UpdateStats(const std::unordered_map<std::string, double>& params) {
40-
Metrics::GetInstance().UpdateStats(params);
41-
}
42-
43-
inline std::tuple<
44-
std::unordered_map<std::string, double>,
45-
std::unordered_map<std::string, double>,
46-
std::unordered_map<std::string, std::vector<double>>
47-
> GetAllStatsAndClear() {
48-
return Metrics::GetInstance().GetAllStatsAndClear();
49-
}
50-
5131
void bind_monitor(py::module_& m)
5232
{
5333
m.def("create_stats", &CreateStats);

0 commit comments

Comments
 (0)