mirror of https://github.com/grpc/grpc.git
commit
ee090ec975
113 changed files with 7919 additions and 597 deletions
@ -0,0 +1,67 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/lib/debug/stats.h" |
||||
|
||||
#include <inttypes.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
#include "src/core/lib/support/string.h" |
||||
|
||||
grpc_stats_data *grpc_stats_per_cpu_storage = NULL; |
||||
static size_t g_num_cores; |
||||
|
||||
void grpc_stats_init(void) { |
||||
g_num_cores = GPR_MAX(1, gpr_cpu_num_cores()); |
||||
grpc_stats_per_cpu_storage = |
||||
gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores); |
||||
} |
||||
|
||||
void grpc_stats_shutdown(void) { gpr_free(grpc_stats_per_cpu_storage); } |
||||
|
||||
void grpc_stats_collect(grpc_stats_data *output) { |
||||
memset(output, 0, sizeof(*output)); |
||||
for (size_t core = 0; core < g_num_cores; core++) { |
||||
for (size_t i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { |
||||
output->counters[i] += gpr_atm_no_barrier_load( |
||||
&grpc_stats_per_cpu_storage[core].counters[i]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
char *grpc_stats_data_as_json(const grpc_stats_data *data) { |
||||
gpr_strvec v; |
||||
char *tmp; |
||||
bool is_first = true; |
||||
gpr_strvec_init(&v); |
||||
gpr_strvec_add(&v, gpr_strdup("{")); |
||||
for (size_t i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { |
||||
gpr_asprintf(&tmp, "%s\"%s\": %" PRIdPTR, is_first ? "" : ", ", |
||||
grpc_stats_counter_name[i], data->counters[i]); |
||||
gpr_strvec_add(&v, tmp); |
||||
is_first = false; |
||||
} |
||||
gpr_strvec_add(&v, gpr_strdup("}")); |
||||
tmp = gpr_strvec_flatten(&v, NULL); |
||||
gpr_strvec_destroy(&v); |
||||
return tmp; |
||||
} |
@ -0,0 +1,44 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_DEBUG_STATS_H |
||||
#define GRPC_CORE_LIB_DEBUG_STATS_H |
||||
|
||||
#include <grpc/support/atm.h> |
||||
#include "src/core/lib/debug/stats_data.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
|
||||
typedef struct grpc_stats_data { |
||||
gpr_atm counters[GRPC_STATS_COUNTER_COUNT]; |
||||
} grpc_stats_data; |
||||
|
||||
extern grpc_stats_data *grpc_stats_per_cpu_storage; |
||||
|
||||
#define GRPC_THREAD_STATS_DATA(exec_ctx) \ |
||||
(&grpc_stats_per_cpu_storage[(exec_ctx)->starting_cpu]) |
||||
|
||||
#define GRPC_STATS_INC_COUNTER(exec_ctx, ctr) \ |
||||
(gpr_atm_no_barrier_fetch_add( \
|
||||
&GRPC_THREAD_STATS_DATA((exec_ctx))->counters[(ctr)], 1)) |
||||
|
||||
void grpc_stats_init(void); |
||||
void grpc_stats_shutdown(void); |
||||
void grpc_stats_collect(grpc_stats_data *output); |
||||
char *grpc_stats_data_as_json(const grpc_stats_data *data); |
||||
|
||||
#endif |
@ -0,0 +1,25 @@ |
||||
/*
|
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
/*
|
||||
* Automatically generated by tools/codegen/core/gen_stats_data.py |
||||
*/ |
||||
|
||||
#include "src/core/lib/debug/stats_data.h" |
||||
const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { |
||||
"client_calls_created", "server_calls_created", "syscall_write", |
||||
"syscall_read", "syscall_poll", "syscall_wait", |
||||
}; |
@ -0,0 +1,47 @@ |
||||
/*
|
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
/*
|
||||
* Automatically generated by tools/codegen/core/gen_stats_data.py |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_DEBUG_STATS_DATA_H |
||||
#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H |
||||
|
||||
typedef enum { |
||||
GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED, |
||||
GRPC_STATS_COUNTER_SERVER_CALLS_CREATED, |
||||
GRPC_STATS_COUNTER_SYSCALL_WRITE, |
||||
GRPC_STATS_COUNTER_SYSCALL_READ, |
||||
GRPC_STATS_COUNTER_SYSCALL_POLL, |
||||
GRPC_STATS_COUNTER_SYSCALL_WAIT, |
||||
GRPC_STATS_COUNTER_COUNT |
||||
} grpc_stats_counters; |
||||
#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ |
||||
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) |
||||
#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ |
||||
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) |
||||
#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ |
||||
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) |
||||
#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ |
||||
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) |
||||
#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ |
||||
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) |
||||
#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ |
||||
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) |
||||
extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; |
||||
|
||||
#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ |
@ -0,0 +1,9 @@ |
||||
# Stats data declaration |
||||
# use tools/codegen/core/gen_stats_data.py to turn this into stats_data.h |
||||
|
||||
- counter: client_calls_created |
||||
- counter: server_calls_created |
||||
- counter: syscall_write |
||||
- counter: syscall_read |
||||
- counter: syscall_poll |
||||
- counter: syscall_wait |
@ -0,0 +1,102 @@ |
||||
#!/usr/bin/env python2.7 |
||||
|
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
import collections |
||||
import sys |
||||
import yaml |
||||
|
||||
with open('src/core/lib/debug/stats_data.yaml') as f: |
||||
attrs = yaml.load(f.read()) |
||||
|
||||
Counter = collections.namedtuple('Counter', 'name') |
||||
|
||||
counters = [] |
||||
|
||||
for attr in attrs: |
||||
if 'counter' in attr: |
||||
counters.append(Counter(name=attr['counter'])) |
||||
else: |
||||
print 'Error: bad attr %r' % attr |
||||
|
||||
# utility: print a big comment block into a set of files |
||||
def put_banner(files, banner): |
||||
for f in files: |
||||
print >>f, '/*' |
||||
for line in banner: |
||||
print >>f, ' * %s' % line |
||||
print >>f, ' */' |
||||
print >>f |
||||
|
||||
with open('src/core/lib/debug/stats_data.h', 'w') as H: |
||||
# copy-paste copyright notice from this file |
||||
with open(sys.argv[0]) as my_source: |
||||
copyright = [] |
||||
for line in my_source: |
||||
if line[0] != '#': break |
||||
for line in my_source: |
||||
if line[0] == '#': |
||||
copyright.append(line) |
||||
break |
||||
for line in my_source: |
||||
if line[0] != '#': |
||||
break |
||||
copyright.append(line) |
||||
put_banner([H], [line[2:].rstrip() for line in copyright]) |
||||
|
||||
put_banner([H], ["Automatically generated by tools/codegen/core/gen_stats_data.py"]) |
||||
|
||||
print >>H, "#ifndef GRPC_CORE_LIB_DEBUG_STATS_DATA_H" |
||||
print >>H, "#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H" |
||||
print >>H |
||||
|
||||
print >>H, "typedef enum {" |
||||
for ctr in counters: |
||||
print >>H, " GRPC_STATS_COUNTER_%s," % ctr.name.upper() |
||||
print >>H, " GRPC_STATS_COUNTER_COUNT" |
||||
print >>H, "} grpc_stats_counters;" |
||||
|
||||
for ctr in counters: |
||||
print >>H, "#define GRPC_STATS_INC_%s(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)" % (ctr.name.upper(), ctr.name.upper()) |
||||
|
||||
print >>H, "extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT];" |
||||
|
||||
print >>H |
||||
print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */" |
||||
|
||||
with open('src/core/lib/debug/stats_data.c', 'w') as C: |
||||
# copy-paste copyright notice from this file |
||||
with open(sys.argv[0]) as my_source: |
||||
copyright = [] |
||||
for line in my_source: |
||||
if line[0] != '#': break |
||||
for line in my_source: |
||||
if line[0] == '#': |
||||
copyright.append(line) |
||||
break |
||||
for line in my_source: |
||||
if line[0] != '#': |
||||
break |
||||
copyright.append(line) |
||||
put_banner([C], [line[2:].rstrip() for line in copyright]) |
||||
|
||||
put_banner([C], ["Automatically generated by tools/codegen/core/gen_stats_data.py"]) |
||||
|
||||
print >>C, "#include \"src/core/lib/debug/stats_data.h\"" |
||||
|
||||
print >>C, "const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = {"; |
||||
for ctr in counters: |
||||
print >>C, " \"%s\"," % ctr.name |
||||
print >>C, "};" |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue