Skip to content
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

metrics #149

Merged
merged 5 commits into from
Jul 5, 2021
Merged

metrics #149

merged 5 commits into from
Jul 5, 2021

Conversation

turuslan
Copy link
Contributor

@turuslan turuslan commented Jun 9, 2021

  • instance count and list annotations for metrics.
  • count libp2p instances: tcp/noise/yamuxed connection, upgrader session, yamux stream, gossip stream and peer context.
  • metrics test.
  • fix unused warning (yamuxed_connection.cpp).

Signed-off-by: turuslan <turuslan.devbox@gmail.com>
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
@turuslan turuslan removed the request for review from xDimon June 9, 2021 09:43
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
@turuslan turuslan requested a review from art-gor June 9, 2021 11:08
static auto &count() { \
static auto &count = ([]() -> auto & { \
auto &state{::libp2p::metrics::instance::State::get()}; \
std::lock_guard lock{state.mutex}; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object creation or destruction locks and unlocks a mutex. That looks to be a too heavy operation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count()'s count is static local variable, so this lambda with mutex locking is called only once, to insert key-counter pair into map.
Generally LIBP2P_METRICS_INSTANCES_COUNT constructor/destructor is just checking "static guard variable" (was static variable initialized) followed by atomic increment/decrement.

LIBP2P_METRICS_INSTANCES_LIST is heavier and always locks mutex, because it inserts/erases list. Developer chooses whether to keep list of all type instances or not (or just count with LIBP2P_METRICS_INSTANCES_COUNT).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disabled by default via cmake option

@art-gor
Copy link
Contributor

art-gor commented Jun 15, 2021

Better to have this feature disabled by default in build time, and to be enabled explicitly by CMake variable and preprocessor,
cmake ... -DMETRICS_ENABLED=On
...
if(METRICS_ENABLED)
add_compile_definitions("METRICS_ENABLED")
... etc

Copy link
Contributor

@art-gor art-gor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented earlier about making this feature a non-default option

@turuslan turuslan requested a review from art-gor June 17, 2021 05:01
@turuslan turuslan merged commit 30f59b8 into master Jul 5, 2021
@turuslan turuslan deleted the feature/metrics branch July 5, 2021 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants