-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add metrics collector (#4407)
* merge * compile * uncomment * revert * add manager * more additions * clang * remove options parsing * clang * address comments * comments * clang * remove output hooks * unused * comments * clang * update name to metrics_collector * remove filename * remove filename .h * remove fn * fix construction * revert settings
- Loading branch information
Showing
23 changed files
with
121 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) by respective owners including Yahoo!, Microsoft, and | ||
// individual contributors. All rights reserved. Released under a BSD (revised) | ||
// license as described in the file LICENSE.= | ||
|
||
#pragma once | ||
|
||
#include "metric_sink.h" | ||
#include "vw/core/learner_fwd.h" | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
#include <map> | ||
#include <memory> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace VW | ||
{ | ||
class metrics_collector | ||
{ | ||
public: | ||
metrics_collector(bool enabled = false); | ||
|
||
using metrics_callback_fn = std::function<void(VW::metric_sink&)>; | ||
|
||
bool are_metrics_enabled() const; | ||
void register_metrics_callback(const metrics_callback_fn& callback); | ||
VW::metric_sink collect_metrics(LEARNER::base_learner* l = nullptr) const; | ||
|
||
private: | ||
bool _are_metrics_enabled; | ||
std::vector<metrics_callback_fn> _metrics_callbacks; | ||
}; | ||
} // namespace VW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) by respective owners including Yahoo!, Microsoft, and | ||
// individual contributors. All rights reserved. Released under a BSD (revised) | ||
// license as described in the file LICENSE. | ||
|
||
#include "vw/core/metrics_collector.h" | ||
|
||
#include "vw/core/learner.h" | ||
namespace VW | ||
{ | ||
metrics_collector::metrics_collector(bool enabled) : _are_metrics_enabled(enabled) {} | ||
|
||
bool metrics_collector::are_metrics_enabled() const { return _are_metrics_enabled; } | ||
|
||
void metrics_collector::register_metrics_callback(const metrics_callback_fn& callback) | ||
{ | ||
if (_are_metrics_enabled) { _metrics_callbacks.push_back(callback); } | ||
} | ||
|
||
metric_sink metrics_collector::collect_metrics(LEARNER::base_learner* l) const | ||
{ | ||
VW::metric_sink sink; | ||
if (!_are_metrics_enabled) { THROW("Metrics must be enabled to call collect_metrics"); } | ||
if (l) { l->persist_metrics(sink); } | ||
for (const auto& callback : _metrics_callbacks) { callback(sink); } | ||
return sink; | ||
} | ||
} // namespace VW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.