[Metric] new cython interface for python worker metric (#9469)

This commit is contained in:
Lingxuan Zuo
2020-07-19 10:43:21 +08:00
committed by GitHub
parent 7edd1e6694
commit ce3f542739
7 changed files with 273 additions and 1 deletions
+11
View File
@@ -13,6 +13,7 @@
// limitations under the License.
#include "ray/stats/metric.h"
#include "opencensus/stats/internal/aggregation_window.h"
#include "opencensus/stats/internal/set_aggregation_window.h"
@@ -85,6 +86,16 @@ void Metric::Record(double value, const TagsType &tags) {
opencensus::stats::Record({{*measure_, value}}, combined_tags);
}
void Metric::Record(double value, std::unordered_map<std::string, std::string> &tags) {
TagsType tags_pair_vec;
std::for_each(
tags.begin(), tags.end(),
[&tags_pair_vec](std::pair<std::string, std::string> tag) {
return tags_pair_vec.push_back({TagKeyType::Register(tag.first), tag.second});
});
Record(value, tags_pair_vec);
}
void Gauge::RegisterView() {
opencensus::stats::ViewDescriptor view_descriptor =
opencensus::stats::ViewDescriptor()
+7 -1
View File
@@ -92,7 +92,7 @@ class Metric {
std::string GetName() const { return name_; }
/// Record the value for this metric.
void Record(double value) { Record(value, {}); }
void Record(double value) { Record(value, TagsType{}); }
/// Record the value for this metric.
///
@@ -100,6 +100,12 @@ class Metric {
/// \param tags The tag values that we want to record for this metric record.
void Record(double value, const TagsType &tags);
/// Record the value for this metric.
///
/// \param value The value that we record.
/// \param tags The map tag values that we want to record for this metric record.
void Record(double value, std::unordered_map<std::string, std::string> &tags);
protected:
virtual void RegisterView() = 0;