Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <cstring>
#include <string>
#include <sstream>
 
namespace onnxruntime {
 
// Runtime statistics collected by an allocator.
struct AllocatorStats {
  int64_t num_allocs;              // Number of allocations.
  int64_t num_reserves;            // Number of reserves. (Number of calls to Reserve() in arena-based allocators)
  int64_t num_arena_extensions;    // Number of arena extensions (Relevant only for arena based allocators)
  int64_t num_arena_shrinkages;    // Number of arena shrinkages (Relevant only for arena based allocators)
  int64_t bytes_in_use;            // Number of bytes in use (includes padding).
  int64_t bytes_requested_in_use;  // Number of bytes actually requested by user code (excludes padding).
  int64_t total_allocated_bytes;   // The total number of allocated bytes by the allocator.
  int64_t max_bytes_in_use;        // The maximum bytes in use.
  int64_t max_alloc_size;          // The max single allocation seen.
                                   // The upper limit what the allocator can allocate, if such a limit
                                   // is known. Certain allocator may return 0 to indicate the limit is
                                   // unknown.
  int64_t bytes_limit;
 
  AllocatorStats() { Clear(); }
 
  void Clear() {
    this->num_allocs = 0;
    this->num_reserves = 0;
    this->num_arena_extensions = 0;
    this->num_arena_shrinkages = 0;
    this->bytes_in_use = 0;
    this->bytes_requested_in_use = 0;
    this->max_bytes_in_use = 0;
    this->max_alloc_size = 0;
    this->bytes_limit = 0;
    this->total_allocated_bytes = 0;
  }
 
  // Assign a stat field by its key name. Returns true if the key was recognized.
  bool SetFromKeyValue(const char* key, int64_t val) {
    if (std::strcmp(key, "Limit") == 0) {
      bytes_limit = val;
    } else if (std::strcmp(key, "InUse") == 0) {
      bytes_in_use = val;
    } else if (std::strcmp(key, "RequestedInUse") == 0) {
      bytes_requested_in_use = val;
    } else if (std::strcmp(key, "TotalAllocated") == 0) {
      total_allocated_bytes = val;
    } else if (std::strcmp(key, "MaxInUse") == 0) {
      max_bytes_in_use = val;
    } else if (std::strcmp(key, "NumAllocs") == 0) {
      num_allocs = val;
    } else if (std::strcmp(key, "NumReserves") == 0) {
      num_reserves = val;
    } else if (std::strcmp(key, "NumArenaExtensions") == 0) {
      num_arena_extensions = val;
    } else if (std::strcmp(key, "NumArenaShrinkages") == 0) {
      num_arena_shrinkages = val;
    } else if (std::strcmp(key, "MaxAllocSize") == 0) {
      max_alloc_size = val;
    } else {
      return false;
    }
    return true;
  }
 
  std::string DebugString() const {
    std::ostringstream ss;
    ss << "Limit:                    " << this->bytes_limit << "\n"
       << "InUse:                    " << this->bytes_in_use << "\n"
       << "RequestedInUse:           " << this->bytes_requested_in_use << "\n"
       << "TotalAllocated:           " << this->total_allocated_bytes << "\n"
       << "MaxInUse:                 " << this->max_bytes_in_use << "\n"
       << "NumAllocs:                " << this->num_allocs << "\n"
       << "NumReserves:              " << this->num_reserves << "\n"
       << "NumArenaExtensions:       " << this->num_arena_extensions << "\n"
       << "NumArenaShrinkages:       " << this->num_arena_shrinkages << "\n"
       << "MaxAllocSize:             " << this->max_alloc_size << "\n";
    return ss.str();
  }
};
}  // namespace onnxruntime