1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
|
#ifndef INCLUDES_TARANTOOL_BOX_VY_STAT_H
#define INCLUDES_TARANTOOL_BOX_VY_STAT_H
/*
* Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdint.h>
#include <string.h>
#include "latency.h"
#include "tuple.h"
#include "iproto_constants.h"
#if defined(__cplusplus)
extern "C" {
#endif /* defined(__cplusplus) */
/** Number of statements of each type. */
struct vy_stmt_stat {
int64_t inserts;
int64_t replaces;
int64_t deletes;
int64_t upserts;
};
/** Used for accounting statements stored in memory. */
struct vy_stmt_counter {
/** Number of statements. */
int64_t rows;
/** Size, in bytes. */
int64_t bytes;
};
/** Used for accounting statements stored on disk. */
struct vy_disk_stmt_counter {
/** Number of statements. */
int64_t rows;
/** Size when uncompressed, in bytes. */
int64_t bytes;
/** Size when compressed, in bytes */
int64_t bytes_compressed;
/** Number of pages. */
int64_t pages;
};
/** Memory iterator statistics. */
struct vy_mem_iterator_stat {
/** Number of lookups in the memory tree. */
int64_t lookup;
/** Number of statements returned by the iterator. */
struct vy_stmt_counter get;
};
/** Run iterator statistics. */
struct vy_run_iterator_stat {
/** Number of lookups in the page index. */
int64_t lookup;
/** Number of statements returned by the iterator. */
struct vy_stmt_counter get;
/**
* Number of times the bloom filter allowed to
* avoid a disk read.
*/
int64_t bloom_hit;
/**
* Number of times the bloom filter failed to
* prevent a disk read.
*/
int64_t bloom_miss;
/**
* Number of statements actually read from the disk.
* It may be greater than the number of statements
* returned by the iterator, because of page granularity
* of disk reads.
*/
struct vy_disk_stmt_counter read;
};
/** TX write set iterator statistics. */
struct vy_txw_iterator_stat {
/** Number of lookups in the write set. */
int64_t lookup;
/** Number of statements returned by the iterator. */
struct vy_stmt_counter get;
};
/** LSM tree statistics. */
struct vy_lsm_stat {
/** Number of lookups in the LSM tree. */
int64_t lookup;
/** Number of statements read from this LSM tree. */
struct vy_stmt_counter get;
/** Number of statements skipped on read. */
struct vy_stmt_counter skip;
/** Number of statements written to this LSM tree. */
struct vy_stmt_counter put;
/** Read latency. */
struct latency latency;
/** Upsert statistics. */
struct {
/** How many upsert chains have been squashed. */
int64_t squashed;
/** How many upserts have been applied on read. */
int64_t applied;
} upsert;
/** Memory related statistics. */
struct {
/** Number of statements stored in memory. */
struct vy_stmt_counter count;
/** Memory iterator statistics. */
struct vy_mem_iterator_stat iterator;
} memory;
/** Disk related statistics. */
struct {
/** Number of statements stored on disk. */
struct vy_disk_stmt_counter count;
/** Number of statements stored in the last LSM level. */
struct vy_disk_stmt_counter last_level_count;
/** Statement statistics. */
struct vy_stmt_stat stmt;
/** Run iterator statistics. */
struct vy_run_iterator_stat iterator;
/** Dump statistics. */
struct {
/* Number of completed tasks. */
int32_t count;
/** Time spent on dump tasks, in seconds. */
double time;
/** Number of input statements. */
struct vy_stmt_counter input;
/** Number of output statements. */
struct vy_disk_stmt_counter output;
} dump;
/** Compaction statistics. */
struct {
/* Number of completed tasks. */
int32_t count;
/** Time spent on compaction tasks, in seconds. */
double time;
/** Number of input statements. */
struct vy_disk_stmt_counter input;
/** Number of output statements. */
struct vy_disk_stmt_counter output;
/** Number of statements awaiting compaction. */
struct vy_disk_stmt_counter queue;
} compaction;
} disk;
/** TX write set statistics. */
struct {
/** Number of statements in the write set. */
struct vy_stmt_counter count;
/** TX write set iterator statistics. */
struct vy_txw_iterator_stat iterator;
} txw;
};
/** Tuple cache statistics. */
struct vy_cache_stat {
/** Number of statements in the cache. */
struct vy_stmt_counter count;
/** Number of lookups in the cache. */
int64_t lookup;
/** Number of reads from the cache. */
struct vy_stmt_counter get;
/** Number of writes to the cache. */
struct vy_stmt_counter put;
/**
* Number of statements removed from the cache
* due to overwrite.
*/
struct vy_stmt_counter invalidate;
/**
* Number of statements removed from the cache
* due to memory shortage.
*/
struct vy_stmt_counter evict;
};
/** Transaction statistics. */
struct vy_tx_stat {
/** Number of committed transactions. */
int64_t commit;
/** Number of rolled back transactions. */
int64_t rollback;
/** Number of transactions aborted on conflict. */
int64_t conflict;
};
/**
* Scheduler statistics.
*
* All byte counters are given without taking into account
* disk compression.
*/
struct vy_scheduler_stat {
/** Number of completed tasks. */
int32_t tasks_completed;
/** Number of failed tasks. */
int32_t tasks_failed;
/** Number of tasks in progress. */
int32_t tasks_inprogress;
/** Number of completed memory dumps. */
int32_t dump_count;
/** Time spent on dump tasks, in seconds. */
double dump_time;
/** Number of bytes read by dump tasks. */
int64_t dump_input;
/** Number of bytes written by dump tasks. */
int64_t dump_output;
/** Time spent on compaction tasks, in seconds. */
double compaction_time;
/** Number of bytes read by compaction tasks. */
int64_t compaction_input;
/** Number of bytes written by compaction tasks. */
int64_t compaction_output;
};
static inline int
vy_lsm_stat_create(struct vy_lsm_stat *stat)
{
return latency_create(&stat->latency);
}
static inline void
vy_lsm_stat_destroy(struct vy_lsm_stat *stat)
{
latency_destroy(&stat->latency);
}
static inline void
vy_stmt_counter_reset(struct vy_stmt_counter *c)
{
memset(c, 0, sizeof(*c));
}
static inline void
vy_disk_stmt_counter_reset(struct vy_disk_stmt_counter *c)
{
memset(c, 0, sizeof(*c));
}
static inline void
vy_stmt_counter_acct_tuple(struct vy_stmt_counter *c, struct tuple *tuple)
{
c->rows++;
c->bytes += tuple_size(tuple);
}
static inline void
vy_stmt_counter_unacct_tuple(struct vy_stmt_counter *c, struct tuple *tuple)
{
c->rows--;
c->bytes -= tuple_size(tuple);
}
static inline void
vy_stmt_counter_add(struct vy_stmt_counter *c1,
const struct vy_stmt_counter *c2)
{
c1->rows += c2->rows;
c1->bytes += c2->bytes;
}
static inline void
vy_stmt_counter_sub(struct vy_stmt_counter *c1,
const struct vy_stmt_counter *c2)
{
c1->rows -= c2->rows;
c1->bytes -= c2->bytes;
}
static inline void
vy_stmt_counter_add_disk(struct vy_stmt_counter *c1,
const struct vy_disk_stmt_counter *c2)
{
c1->rows += c2->rows;
c1->bytes += c2->bytes;
}
static inline void
vy_disk_stmt_counter_add(struct vy_disk_stmt_counter *c1,
const struct vy_disk_stmt_counter *c2)
{
c1->rows += c2->rows;
c1->bytes += c2->bytes;
c1->bytes_compressed += c2->bytes_compressed;
c1->pages += c2->pages;
}
static inline void
vy_disk_stmt_counter_sub(struct vy_disk_stmt_counter *c1,
const struct vy_disk_stmt_counter *c2)
{
c1->rows -= c2->rows;
c1->bytes -= c2->bytes;
c1->bytes_compressed -= c2->bytes_compressed;
c1->pages -= c2->pages;
}
/**
* Account a single statement of the given type in @stat.
*/
static inline void
vy_stmt_stat_acct(struct vy_stmt_stat *stat, enum iproto_type type)
{
switch (type) {
case IPROTO_INSERT:
stat->inserts++;
break;
case IPROTO_REPLACE:
stat->replaces++;
break;
case IPROTO_DELETE:
stat->deletes++;
break;
case IPROTO_UPSERT:
stat->upserts++;
break;
default:
break;
}
}
/**
* Add statistics accumulated in @s2 to @s1.
*/
static inline void
vy_stmt_stat_add(struct vy_stmt_stat *s1, const struct vy_stmt_stat *s2)
{
s1->inserts += s2->inserts;
s1->replaces += s2->replaces;
s1->deletes += s2->deletes;
s1->upserts += s2->upserts;
}
/**
* Subtract statistics accumulated in @s2 from @s1.
*/
static inline void
vy_stmt_stat_sub(struct vy_stmt_stat *s1, const struct vy_stmt_stat *s2)
{
s1->inserts -= s2->inserts;
s1->replaces -= s2->replaces;
s1->deletes -= s2->deletes;
s1->upserts -= s2->upserts;
}
#if defined(__cplusplus)
} /* extern "C" */
#endif /* defined(__cplusplus) */
#endif /* INCLUDES_TARANTOOL_BOX_VY_STAT_H */
|