jdk

Форк
0
/
tableStatistics.cpp 
153 строки · 5.5 Кб
1
/*
2
 * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 *
23
 */
24

25
#include "precompiled.hpp"
26
#include "runtime/atomic.hpp"
27
#include "runtime/os.hpp"
28
#include "utilities/debug.hpp"
29
#include "utilities/macros.hpp"
30
#include "utilities/tableStatistics.hpp"
31
#if INCLUDE_JFR
32
#include "jfr/jfr.hpp"
33
#endif
34

35
TableRateStatistics::TableRateStatistics() :
36
  _added_items(0), _removed_items(0),
37
  _time_stamp(0), _seconds_stamp(0),
38
  _added_items_stamp(0), _added_items_stamp_prev(0),
39
  _removed_items_stamp(0), _removed_items_stamp_prev(0) {}
40

41
TableRateStatistics::~TableRateStatistics() { };
42

43
void TableRateStatistics::add() {
44
#if INCLUDE_JFR
45
  if (Jfr::is_recording()) {
46
    Atomic::inc(&_added_items);
47
  }
48
#endif
49
}
50

51
void TableRateStatistics::remove() {
52
#if INCLUDE_JFR
53
  if (Jfr::is_recording()) {
54
    Atomic::inc(&_removed_items);
55
  }
56
#endif
57
}
58

59
void TableRateStatistics::stamp() {
60
  jlong now = os::javaTimeNanos();
61

62
  _added_items_stamp_prev = _added_items_stamp;
63
  _removed_items_stamp_prev = _removed_items_stamp;
64

65
  _added_items_stamp = _added_items;
66
  _removed_items_stamp = _removed_items;
67

68
  if (_time_stamp == 0) {
69
    _time_stamp = now - 1000000000;
70
  }
71
  jlong diff = (now - _time_stamp);
72
  _seconds_stamp = (float)diff / 1000000000.0;
73
  _time_stamp = now;
74
}
75

76
float TableRateStatistics::get_add_rate() {
77
  return (float)(((double)_added_items_stamp - (double)_added_items_stamp_prev) / _seconds_stamp);
78
}
79

80
float TableRateStatistics::get_remove_rate() {
81
  return (float)(_removed_items_stamp - _removed_items_stamp_prev) / (float)_seconds_stamp;
82
}
83

84
TableStatistics::TableStatistics() :
85
  _literal_bytes(0),
86
  _number_of_buckets(0), _number_of_entries(0),
87
  _maximum_bucket_size(0), _average_bucket_size(0),
88
  _variance_of_bucket_size(0), _stddev_of_bucket_size(0),
89
  _bucket_bytes(0), _entry_bytes(0), _total_footprint(0),
90
  _bucket_size(0), _entry_size(0),
91
  _add_rate(0), _remove_rate(0) {
92
}
93

94
TableStatistics::TableStatistics(NumberSeq summary, size_t literal_bytes, size_t bucket_bytes, size_t node_bytes) :
95
  _literal_bytes(literal_bytes),
96
  _number_of_buckets(0), _number_of_entries(0),
97
  _maximum_bucket_size(0), _average_bucket_size(0),
98
  _variance_of_bucket_size(0), _stddev_of_bucket_size(0),
99
  _bucket_bytes(0), _entry_bytes(0), _total_footprint(0),
100
  _bucket_size(0), _entry_size(0),
101
  _add_rate(0), _remove_rate(0) {
102

103
  _number_of_buckets = summary.num();
104
  _number_of_entries = (size_t)summary.sum();
105

106
  _maximum_bucket_size = (size_t)summary.maximum();
107
  _average_bucket_size = (float)summary.avg();
108
  _variance_of_bucket_size = (float)summary.variance();
109
  _stddev_of_bucket_size = (float)summary.sd();
110

111
  _bucket_bytes = _number_of_buckets * bucket_bytes;
112
  _entry_bytes = _number_of_entries * node_bytes;
113
  _total_footprint = _literal_bytes + _bucket_bytes + _entry_bytes;
114

115
  _bucket_size = (_number_of_buckets <= 0) ? 0 : (_bucket_bytes / _number_of_buckets);
116
  _entry_size = (_number_of_entries <= 0) ? 0 : (_entry_bytes / _number_of_entries);
117
}
118

119
TableStatistics::TableStatistics(TableRateStatistics& rate_stats,
120
                                  NumberSeq summary, size_t literal_bytes,
121
                                  size_t bucket_bytes, size_t node_bytes) :
122
  TableStatistics(summary, literal_bytes, bucket_bytes, node_bytes) {
123
#if INCLUDE_JFR
124
  if (Jfr::is_recording()) {
125
    rate_stats.stamp();
126
    _add_rate = rate_stats.get_add_rate();
127
    _remove_rate = rate_stats.get_remove_rate();
128
  }
129
#endif
130
}
131

132
TableStatistics::~TableStatistics() { }
133

134
void TableStatistics::print(outputStream* st, const char *table_name) {
135
  st->print_cr("%s statistics:", table_name);
136
  st->print_cr("Number of buckets       : %9" PRIuPTR " = %9" PRIuPTR
137
               " bytes, each " SIZE_FORMAT,
138
              _number_of_buckets, _bucket_bytes, _bucket_size);
139
  st->print_cr("Number of entries       : %9" PRIuPTR " = %9" PRIuPTR
140
               " bytes, each " SIZE_FORMAT,
141
               _number_of_entries, _entry_bytes, _entry_size);
142
  if (_literal_bytes != 0) {
143
    float literal_avg = (_number_of_entries <= 0) ? 0.0f : (float)(_literal_bytes / _number_of_entries);
144
    st->print_cr("Number of literals      : %9" PRIuPTR " = %9" PRIuPTR
145
                 " bytes, avg %7.3f",
146
                 _number_of_entries, _literal_bytes, literal_avg);
147
  }
148
  st->print_cr("Total footprint         : %9s = %9" PRIuPTR " bytes", "", _total_footprint);
149
  st->print_cr("Average bucket size     : %9.3f", _average_bucket_size);
150
  st->print_cr("Variance of bucket size : %9.3f", _variance_of_bucket_size);
151
  st->print_cr("Std. dev. of bucket size: %9.3f", _stddev_of_bucket_size);
152
  st->print_cr("Maximum bucket size     : %9" PRIuPTR, _maximum_bucket_size);
153
}
154

155

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.