-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Add metrics collector #4407
Merged
Merged
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
eb313ef
merge
bassmang 60f91a4
compile
bassmang 157f585
uncomment
bassmang cb26b9e
revert
bassmang 4349022
add manager
bassmang 55a14e4
more additions
bassmang a276640
clang
bassmang 94f7b1b
remove options parsing
bassmang 4d6b5b3
Merge remote-tracking branch 'upstream/master' into metrics_fix
bassmang d82968a
clang
bassmang 4c1efb5
address comments
bassmang b2cbe0f
Merge remote-tracking branch 'upstream/master' into metrics_fix
bassmang 22e866a
comments
bassmang 22c459d
clang
bassmang 129071b
remove output hooks
bassmang d164302
unused
bassmang fc86673
comments
bassmang 7749d31
clang
bassmang 8315033
Merge remote-tracking branch 'upstream/master' into metrics_fix
bassmang 6cabfb1
update name to metrics_collector
bassmang b7b6407
remove filename
bassmang 19c5d93
remove filename .h
bassmang c36f420
remove fn
bassmang 99e64c1
fix construction
bassmang c8e1e89
merge
bassmang f743f03
revert settings
bassmang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,36 @@ | ||
// 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, std::string filename = ""); | ||
|
||
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; | ||
std::string _metrics_filename; | ||
}; | ||
} // 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,30 @@ | ||
// 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, std::string filename) | ||
: _are_metrics_enabled(enabled), _metrics_filename(filename) | ||
{ | ||
} | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.