-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add grpc_rs for exporting internal APIs #50
Open
overvenus
wants to merge
2
commits into
tikv:rs-release
Choose a base branch
from
overvenus:public-stats
base: rs-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,81 @@ | ||
// Copyright 2023 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
#ifndef GRPC_RS_STATS_H | ||
#define GRPC_RS_STATS_H | ||
|
||
#include <grpc/support/port_platform.h> | ||
#include <grpc/slice.h> | ||
|
||
#ifndef GRPCRSAPI | ||
#define GRPCRSAPI GPRAPI | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** gRPC stats. | ||
See: grpc/src/core/lib/debug/stats_data.yaml */ | ||
typedef struct grpcrs_stats grpcrs_stats; | ||
|
||
enum grpcrs_stats_counter { | ||
ClientCallsCreated, | ||
ServerCallsCreated, | ||
ClientChannelsCreated, | ||
ClientSubchannelsCreated, | ||
ServerChannelsCreated, | ||
InsecureConnectionsCreated, | ||
SyscallWrite, | ||
SyscallRead, | ||
TcpReadAlloc8k, | ||
TcpReadAlloc64k, | ||
Http2SettingsWrites, | ||
Http2PingsSent, | ||
Http2WritesBegun, | ||
Http2TransportStalls, | ||
Http2StreamStalls, | ||
CqPluckCreates, | ||
CqNextCreates, | ||
CqCallbackCreates, | ||
COUNTER_COUNT | ||
}; | ||
|
||
enum grpcrs_stats_histogram { | ||
CallInitialSize, | ||
TcpWriteSize, | ||
TcpWriteIovSize, | ||
TcpReadSize, | ||
TcpReadOffer, | ||
TcpReadOfferIovSize, | ||
Http2SendMessageSize, | ||
Http2MetadataSize, | ||
HISTOGRAM_COUNT | ||
}; | ||
|
||
GRPCRSAPI grpcrs_stats* grpcrs_stats_collect(); | ||
|
||
GRPCRSAPI void grpcrs_stats_free(grpcrs_stats* stats); | ||
|
||
GRPCRSAPI uint64_t grpcrs_stats_get_counter( | ||
const grpcrs_stats* stats, grpcrs_stats_counter which); | ||
|
||
GRPCRSAPI grpc_slice grpcrs_stats_counter_name(grpcrs_stats_counter which); | ||
|
||
GRPCRSAPI grpc_slice grpcrs_stats_counter_doc(grpcrs_stats_counter which); | ||
|
||
GRPCRSAPI double grpcrs_stats_get_histogram_percentile( | ||
const grpcrs_stats* stats, grpcrs_stats_histogram which, | ||
double percentile); | ||
|
||
GRPCRSAPI double grpcrs_stats_get_histogram_count( | ||
const grpcrs_stats* stats, grpcrs_stats_histogram which); | ||
|
||
GRPCRSAPI grpc_slice grpcrs_stats_histogram_name(grpcrs_stats_histogram which); | ||
|
||
GRPCRSAPI grpc_slice grpcrs_stats_histogram_doc(grpcrs_stats_histogram which); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* GRPC_RS_STATS_H */ |
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,74 @@ | ||
// Copyright 2023 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
#include <include/grpcrs/stats.h> | ||
|
||
#include "src/core/lib/debug/stats.h" | ||
#include "src/core/lib/debug/stats_data.h" | ||
|
||
// Just make sure they have the same number of counters. | ||
static_assert(static_cast<int>(grpcrs_stats_counter::COUNTER_COUNT) == | ||
static_cast<int>(grpc_core::GlobalStats::Counter::COUNT), | ||
"Counter count must be the same"); | ||
|
||
// Just make sure they have the same number of histograms. | ||
static_assert(static_cast<int>(grpcrs_stats_histogram::HISTOGRAM_COUNT) == | ||
static_cast<int>(grpc_core::GlobalStats::Histogram::COUNT), | ||
"Histogram count must be the same"); | ||
|
||
grpcrs_stats* grpcrs_stats_collect() { | ||
return (grpcrs_stats*)grpc_core::global_stats().Collect().release(); | ||
} | ||
|
||
void grpcrs_stats_free(grpcrs_stats* stats) { | ||
auto s = (grpc_core::GlobalStats*)stats; | ||
delete s; | ||
} | ||
|
||
uint64_t grpcrs_stats_get_counter( | ||
const grpcrs_stats* stats, grpcrs_stats_counter which) { | ||
auto s = (const grpc_core::GlobalStats*)stats; | ||
return s->counters[which]; | ||
} | ||
|
||
grpc_slice | ||
grpcrs_stats_counter_name(grpcrs_stats_counter which) { | ||
auto name = grpc_core::GlobalStats::counter_name[which]; | ||
auto slice = grpc_slice_from_static_buffer(name.data(), name.size()); | ||
return slice; | ||
} | ||
|
||
grpc_slice | ||
grpcrs_stats_counter_doc(grpcrs_stats_counter which) { | ||
auto doc = grpc_core::GlobalStats::counter_doc[which]; | ||
auto slice = grpc_slice_from_static_buffer(doc.data(), doc.size()); | ||
return slice; | ||
} | ||
|
||
double grpcrs_stats_get_histogram_percentile( | ||
const grpcrs_stats* stats, grpcrs_stats_histogram which, | ||
double percentile) { | ||
auto s = (const grpc_core::GlobalStats*)stats; | ||
return s->histogram(static_cast<grpc_core::GlobalStats::Histogram>(which)) | ||
.Percentile(percentile); | ||
} | ||
|
||
double grpcrs_stats_get_histogram_count( | ||
const grpcrs_stats* stats, grpcrs_stats_histogram which) { | ||
auto s = (const grpc_core::GlobalStats*)stats; | ||
return s->histogram(static_cast<grpc_core::GlobalStats::Histogram>(which)) | ||
.Count(); | ||
} | ||
|
||
grpc_slice | ||
grpcrs_stats_histogram_name(grpcrs_stats_histogram which) { | ||
auto name = grpc_core::GlobalStats::histogram_name[which]; | ||
auto slice = grpc_slice_from_static_buffer(name.data(), name.size()); | ||
return slice; | ||
} | ||
|
||
grpc_slice | ||
grpcrs_stats_histogram_doc(grpcrs_stats_histogram which) { | ||
auto doc = grpc_core::GlobalStats::histogram_doc[which]; | ||
auto slice = grpc_slice_from_static_buffer(doc.data(), doc.size()); | ||
return slice; | ||
} |
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.
Why need a new library?
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.
So that code can be placed outside of src/core and let
grpc
andgrpc_unsecure
depends on it using its build system.Anyway, what's your suggestion?
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.
Why not put the source in the source list just like CMakeLists.txt does?
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.
CMakeLists.txt is generated from BUILD, upstream may overwrite CMakeLists.txt if they add or remove a file.
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.
@BusyJay PTAL, thanks!
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.
I'm a bit confused. Now is CMakeLists.txt auto-generated? Note we always need to modify CMakeLists.txt as the generated one from upstream doesn't always compile.