GRPC Core  4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
census.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015-2016, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
38 #ifndef GRPC_CENSUS_H
39 #define GRPC_CENSUS_H
40 
41 #include <grpc/grpc.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
55 };
56 
64 CENSUSAPI int census_initialize(int features);
65 CENSUSAPI void census_shutdown(void);
66 
69 CENSUSAPI int census_supported(void);
70 
72 CENSUSAPI int census_enabled(void);
73 
84 
94 typedef struct {
95  const char *key;
96  const char *value;
97  uint8_t flags;
98 } census_tag;
99 
101 #define CENSUS_MAX_TAG_KV_LEN 255
102 
103 #define CENSUS_MAX_PROPAGATED_TAGS 255
104 
106 #define CENSUS_TAG_PROPAGATE 1
107 #define CENSUS_TAG_STATS 2
108 #define CENSUS_TAG_RESERVED 4
112 #define CENSUS_TAG_IS_PROPAGATED(flags) (flags & CENSUS_TAG_PROPAGATE)
113 #define CENSUS_TAG_IS_STATS(flags) (flags & CENSUS_TAG_STATS)
114 
117 typedef struct {
128 
148  const census_context *base, const census_tag *tags, int ntags,
149  census_context_status const **status);
150 
154 
157  const census_context *context);
158 
162 typedef struct {
164  int base;
165  int index;
166  char *kvm;
168 
171  const census_context *context, census_context_iterator *iterator);
172 
177  census_tag *tag);
178 
181  const char *key, census_tag *tag);
182 
193 CENSUSAPI size_t census_context_encode(const census_context *context,
194  char *buffer, size_t buf_size);
195 
199  size_t size);
200 
205 };
206 
209 CENSUSAPI int census_trace_mask(const census_context *context);
210 
212 CENSUSAPI void census_set_trace_mask(int trace_mask);
213 
240 typedef struct {
245 
261 
273 typedef struct {
274  const char *(*get_rpc_service_name)(int64_t id);
275  const char *(*get_rpc_method_name)(int64_t id);
277 
313  const census_context *context, int64_t rpc_name_id,
314  const census_rpc_name_info *rpc_name_info, const char *peer, int trace_mask,
315  const census_timestamp *start_time);
316 
321  const char *peer);
322 
342  const char *buffer, int64_t rpc_name_id,
343  const census_rpc_name_info *rpc_name_info, const char *peer, int trace_mask,
344  census_timestamp *start_time);
345 
372  const char *family, const char *name,
373  int trace_mask);
374 
384 CENSUSAPI void census_end_op(census_context *context, int status);
385 
386 #define CENSUS_TRACE_RECORD_START_OP ((uint32_t)0)
387 #define CENSUS_TRACE_RECORD_END_OP ((uint32_t)1)
388 
396 CENSUSAPI void census_trace_print(census_context *context, uint32_t type,
397  const char *buffer, size_t n);
398 
400 typedef struct {
402  uint64_t trace_id;
403  uint64_t op_id;
404  uint32_t type;
405  const char *buffer;
406  size_t buf_size;
408 
418 CENSUSAPI int census_trace_scan_start(int consume);
419 
430 
433 
459 CENSUSAPI int32_t census_define_resource(const uint8_t *resource_pb,
460  size_t resource_pb_size);
461 
463 CENSUSAPI void census_delete_resource(int32_t resource_id);
464 
467 CENSUSAPI int32_t census_resource_id(const char *name);
468 
471 typedef struct {
472  int32_t resource_id;
473  double value;
474 } census_value;
475 
478  census_value *values, size_t nvalues);
479 
480 #ifdef __cplusplus
481 }
482 #endif
483 
484 #endif /* GRPC_CENSUS_H */
int n_modified_tags
number of tags that were added
Definition: census.h:122
CENSUSAPI int census_enabled(void)
Return the census features currently enabled.
int n_propagated_tags
Definition: census.h:118
CENSUSAPI census_context * census_start_server_rpc_op(const char *buffer, int64_t rpc_name_id, const census_rpc_name_info *rpc_name_info, const char *peer, int trace_mask, census_timestamp *start_time)
Start a server RPC operation.
A single value to be recorded comprises two parts: an ID for the particular resource and the value to...
Definition: census.h:471
double value
Definition: census.h:473
int32_t resource_id
Definition: census.h:472
An instance of this structure is kept by every context, and records the basic information associated ...
Definition: census.h:117
CENSUSAPI const census_context_status * census_context_get_status(const census_context *context)
Get a pointer to the original status from the context creation.
int n_added_tags
number of tags that were deleted
Definition: census.h:121
Do not enable census.
Definition: census.h:50
CENSUSAPI int census_context_get_tag(const census_context *context, const char *key, census_tag *tag)
Get a context tag by key.
CENSUSAPI int census_trace_mask(const census_context *context)
Get the current trace mask associated with this context.
CENSUSAPI void census_record_values(census_context *context, census_value *values, size_t nvalues)
Record new usage values against the given context.
int n_deleted_tags
number of non-propagated (local) tags
Definition: census.h:120
int n_invalid_tags
number of tags that were modified
Definition: census.h:123
Enable Census stats collection.
Definition: census.h:52
Trace record.
Definition: census.h:400
CENSUSAPI void census_trace_print(census_context *context, uint32_t type, const char *buffer, size_t n)
Insert a trace record into the trace stream.
census_trace_mask_values
Distributed traces can have a number of options.
Definition: census.h:202
uint8_t flags
Definition: census.h:97
Represent functions to map RPC name ID to service/method names.
Definition: census.h:273
Enable Census CPU usage collection.
Definition: census.h:53
uint64_t op_id
Trace ID associated with record.
Definition: census.h:403
Enable census tracing.
Definition: census.h:51
CENSUSAPI census_context * census_context_create(const census_context *base, const census_tag *tags, int ntags, census_context_status const **status)
Create a new context, adding and removing tags from an existing context.
CENSUSAPI census_context * census_start_op(census_context *context, const char *family, const char *name, int trace_mask)
Start a new, non-RPC operation.
CENSUSAPI int census_trace_scan_start(int consume)
Start a scan of existing trace records.
int n_local_tags
number of propagated tags
Definition: census.h:119
int n_ignored_tags
number of tags with bad keys or values (e.g.
Definition: census.h:125
CENSUSAPI void census_shutdown(void)
CENSUSAPI void census_trace_scan_end()
End a scan previously started by census_trace_scan_start()
char * kvm
Definition: census.h:166
CENSUSAPI void census_context_destroy(census_context *context)
Destroy a context.
CENSUSAPI size_t census_context_encode(const census_context *context, char *buffer, size_t buf_size)
Tag set encode/decode functionality.
census_timestamp timestamp
Definition: census.h:401
gpr_timespec ts
Use gpr_timespec for default implementation.
Definition: census.h:243
uint32_t type
Operation ID associated with record.
Definition: census.h:404
int base
Definition: census.h:164
The concept of "operation" is a fundamental concept for Census.
Definition: census.h:240
Default, empty flags.
Definition: census.h:204
CENSUSAPI census_context * census_context_decode(const char *buffer, size_t size)
Decode context buffer encoded with census_context_encode().
CENSUSAPI int census_context_next_tag(census_context_iterator *iterator, census_tag *tag)
Get the contents of the "next" tag in the context.
CENSUSAPI void census_delete_resource(int32_t resource_id)
Delete a resource created by census_define_resource().
const census_context * context
Definition: census.h:163
CENSUSAPI int census_supported(void)
Return the features supported by the current census implementation (not all features will be availabl...
CENSUSAPI int32_t census_resource_id(const char *name)
Determine the id of a resource, given its name.
CENSUSAPI int census_get_trace_record(census_trace_record *trace_record)
Get a trace record.
const char * key
Definition: census.h:95
CENSUSAPI void census_end_op(census_context *context, int status)
End an operation started by any of the census_start_*_op*() calls.
CENSUSAPI int census_initialize(int features)
Shutdown and startup census subsystem.
CENSUSAPI void census_set_trace_mask(int trace_mask)
Set the trace mask associated with a context.
uint64_t trace_id
Time of record creation.
Definition: census.h:402
census_features
RPC-internal Census API's.
Definition: census.h:48
CENSUSAPI void census_set_rpc_client_peer(census_context *context, const char *peer)
Add peer information to a context representing a client RPC operation.
A tag is a key:value pair.
Definition: census.h:94
CENSUSAPI int32_t census_define_resource(const uint8_t *resource_pb, size_t resource_pb_size)
Core stats collection API's.
#define CENSUSAPI
Definition: port_platform.h:424
Analogous to struct timespec.
Definition: gpr_types.h:62
const char * value
Definition: census.h:96
CENSUSAPI void census_context_initialize_iterator(const census_context *context, census_context_iterator *iterator)
Initialize a census_tag_iterator.
Definition: census.h:203
const char * buffer
Type (as used in census_trace_print()
Definition: census.h:405
size_t buf_size
Buffer (from census_trace_print()
Definition: census.h:406
CENSUSAPI census_context * census_start_client_rpc_op(const census_context *context, int64_t rpc_name_id, const census_rpc_name_info *rpc_name_info, const char *peer, int trace_mask, const census_timestamp *start_time)
Start a client rpc operation.
int index
Definition: census.h:165
CENSUSAPI census_timestamp census_start_rpc_op_timestamp(void)
Mark the beginning of an RPC operation.
Structure used for iterating over the tags in a context.
Definition: census.h:162
struct census_context census_context
A Census Context is a handle used by Census to represent the current tracing and stats collection inf...
Definition: census.h:83
Definition: census.h:49