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.
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.
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).
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.
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
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"
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) {}
41
TableRateStatistics::~TableRateStatistics() { };
43
void TableRateStatistics::add() {
45
if (Jfr::is_recording()) {
46
Atomic::inc(&_added_items);
51
void TableRateStatistics::remove() {
53
if (Jfr::is_recording()) {
54
Atomic::inc(&_removed_items);
59
void TableRateStatistics::stamp() {
60
jlong now = os::javaTimeNanos();
62
_added_items_stamp_prev = _added_items_stamp;
63
_removed_items_stamp_prev = _removed_items_stamp;
65
_added_items_stamp = _added_items;
66
_removed_items_stamp = _removed_items;
68
if (_time_stamp == 0) {
69
_time_stamp = now - 1000000000;
71
jlong diff = (now - _time_stamp);
72
_seconds_stamp = (float)diff / 1000000000.0;
76
float TableRateStatistics::get_add_rate() {
77
return (float)(((double)_added_items_stamp - (double)_added_items_stamp_prev) / _seconds_stamp);
80
float TableRateStatistics::get_remove_rate() {
81
return (float)(_removed_items_stamp - _removed_items_stamp_prev) / (float)_seconds_stamp;
84
TableStatistics::TableStatistics() :
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) {
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) {
103
_number_of_buckets = summary.num();
104
_number_of_entries = (size_t)summary.sum();
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();
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;
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);
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) {
124
if (Jfr::is_recording()) {
126
_add_rate = rate_stats.get_add_rate();
127
_remove_rate = rate_stats.get_remove_rate();
132
TableStatistics::~TableStatistics() { }
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
146
_number_of_entries, _literal_bytes, literal_avg);
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);