OLD | NEW |
(Empty) | |
| 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 |
| 34 /* A very fast in-memory log, optimized for multiple writers. */ |
| 35 |
| 36 #ifndef GRPC_INTERNAL_CORE_CENSUS_MLOG_H |
| 37 #define GRPC_INTERNAL_CORE_CENSUS_MLOG_H |
| 38 |
| 39 #include <grpc/support/port_platform.h> |
| 40 #include <stddef.h> |
| 41 |
| 42 /* Maximum record size, in bytes. */ |
| 43 #define CENSUS_LOG_2_MAX_RECORD_SIZE 14 /* 2^14 = 16KB */ |
| 44 #define CENSUS_LOG_MAX_RECORD_SIZE (1 << CENSUS_LOG_2_MAX_RECORD_SIZE) |
| 45 |
| 46 /* Initialize the statistics logging subsystem with the given log size. A log |
| 47 size of 0 will result in the smallest possible log for the platform |
| 48 (approximately CENSUS_LOG_MAX_RECORD_SIZE * gpr_cpu_num_cores()). If |
| 49 discard_old_records is non-zero, then new records will displace older ones |
| 50 when the log is full. This function must be called before any other |
| 51 census_log functions. |
| 52 */ |
| 53 void census_log_initialize(size_t size_in_mb, int discard_old_records); |
| 54 |
| 55 /* Shutdown the logging subsystem. Caller must ensure that: |
| 56 - no in progress or future call to any census_log functions |
| 57 - no incomplete records |
| 58 */ |
| 59 void census_log_shutdown(void); |
| 60 |
| 61 /* Allocates and returns a 'size' bytes record and marks it in use. A |
| 62 subsequent census_log_end_write() marks the record complete. The |
| 63 'bytes_written' census_log_end_write() argument must be <= |
| 64 'size'. Returns NULL if out-of-space AND: |
| 65 - log is configured to keep old records OR |
| 66 - all blocks are pinned by incomplete records. |
| 67 */ |
| 68 void* census_log_start_write(size_t size); |
| 69 |
| 70 void census_log_end_write(void* record, size_t bytes_written); |
| 71 |
| 72 void census_log_init_reader(void); |
| 73 |
| 74 /* census_log_read_next() iterates over blocks with data and for each block |
| 75 returns a pointer to the first unread byte. The number of bytes that can be |
| 76 read are returned in 'bytes_available'. Reader is expected to read all |
| 77 available data. Reading the data consumes it i.e. it cannot be read again. |
| 78 census_log_read_next() returns NULL if the end is reached i.e last block |
| 79 is read. census_log_init_reader() starts the iteration or aborts the |
| 80 current iteration. |
| 81 */ |
| 82 const void* census_log_read_next(size_t* bytes_available); |
| 83 |
| 84 /* Returns estimated remaining space across all blocks, in bytes. If log is |
| 85 configured to discard old records, returns total log space. Otherwise, |
| 86 returns space available in empty blocks (partially filled blocks are |
| 87 treated as full). |
| 88 */ |
| 89 size_t census_log_remaining_space(void); |
| 90 |
| 91 /* Returns the number of times gprc_stats_log_start_write() failed due to |
| 92 out-of-space. */ |
| 93 int64_t census_log_out_of_space_count(void); |
| 94 |
| 95 #endif /* GRPC_INTERNAL_CORE_CENSUS_LOG_H */ |
OLD | NEW |