|
1 /* |
|
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * Copyright (c) 2018, SAP SE. |
|
4 * |
|
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
6 * |
|
7 * This code is free software; you can redistribute it and/or modify it |
|
8 * under the terms of the GNU General Public License version 2 only, as |
|
9 * published by the Free Software Foundation. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 * |
|
25 */ |
|
26 |
|
27 #ifndef HOTSPOT_SHARE_SERVICES_STATHIST_INTERNALS_HPP |
|
28 #define HOTSPOT_SHARE_SERVICES_STATHIST_INTERNALS_HPP |
|
29 |
|
30 #include "memory/allocation.hpp" |
|
31 #include "services/stathist.hpp" |
|
32 #include "utilities/globalDefinitions.hpp" |
|
33 |
|
34 |
|
35 namespace StatisticsHistory { |
|
36 |
|
37 typedef uint64_t value_t; |
|
38 #define INVALID_VALUE ((value_t)UINT64_MAX) |
|
39 |
|
40 struct record_t { |
|
41 time_t timestamp; |
|
42 value_t values[1]; // var sized |
|
43 }; |
|
44 |
|
45 class ColumnList; |
|
46 |
|
47 class Column: public CHeapObj<mtInternal> { |
|
48 friend class ColumnList; |
|
49 |
|
50 const char* const _category; |
|
51 const char* const _header; // optional. May be NULL. |
|
52 const char* const _name; |
|
53 const char* const _description; |
|
54 |
|
55 // The following members are fixed by ColumnList when the Column is added to it. |
|
56 Column* _next; // next column in table |
|
57 int _idx; // position in table |
|
58 int _idx_cat; // position in category |
|
59 int _idx_hdr; // position under its header (if any, 0 otherwise) |
|
60 |
|
61 protected: |
|
62 |
|
63 Column(const char* category, const char* header, const char* name, const char* description); |
|
64 |
|
65 // Child classes implement this. |
|
66 // output stream can be NULL; in that case, method shall return number of characters it would have printed. |
|
67 virtual int do_print(outputStream* os, value_t value, |
|
68 value_t last_value, int last_value_age, const print_info_t* pi) const = 0; |
|
69 |
|
70 public: |
|
71 |
|
72 const char* category() const { return _category; } |
|
73 const char* header() const { return _header; } |
|
74 const char* name() const { return _name; } |
|
75 const char* description() const { return _description; } |
|
76 |
|
77 void print_value(outputStream* os, value_t value, value_t last_value, |
|
78 int last_value_age, int min_width, const print_info_t* pi) const; |
|
79 |
|
80 // Returns the number of characters this value needs to be printed. |
|
81 int calc_print_size(value_t value, value_t last_value, |
|
82 int last_value_age, const print_info_t* pi) const; |
|
83 |
|
84 // Returns the index (the position in the table) of this column. |
|
85 int index() const { return _idx; } |
|
86 int index_within_category_section() const { return _idx_cat; } |
|
87 int index_within_header_section() const { return _idx_hdr; } |
|
88 |
|
89 const Column* next () const { return _next; } |
|
90 |
|
91 virtual bool is_memory_size() const { return false; } |
|
92 virtual bool is_delta() const { return false; } |
|
93 |
|
94 |
|
95 }; |
|
96 |
|
97 // Some standard column types |
|
98 |
|
99 class PlainValueColumn: public Column { |
|
100 int do_print(outputStream* os, value_t value, value_t last_value, |
|
101 int last_value_age, const print_info_t* pi) const; |
|
102 public: |
|
103 PlainValueColumn(const char* category, const char* header, const char* name, const char* description) |
|
104 : Column(category, header, name, description) |
|
105 {} |
|
106 }; |
|
107 |
|
108 class DeltaValueColumn: public Column { |
|
109 const bool _show_only_positive; |
|
110 int do_print(outputStream* os, value_t value, value_t last_value, |
|
111 int last_value_age, const print_info_t* pi) const; |
|
112 public: |
|
113 // only_positive: only positive deltas are shown, negative deltas are supressed |
|
114 DeltaValueColumn(const char* category, const char* header, const char* name, const char* description, |
|
115 bool show_only_positive = true) |
|
116 : Column(category, header, name, description) |
|
117 , _show_only_positive(show_only_positive) |
|
118 {} |
|
119 bool is_delta() const { return true; } |
|
120 }; |
|
121 |
|
122 class MemorySizeColumn: public Column { |
|
123 int do_print(outputStream* os, value_t value, value_t last_value, |
|
124 int last_value_age, const print_info_t* pi) const; |
|
125 public: |
|
126 MemorySizeColumn(const char* category, const char* header, const char* name, const char* description) |
|
127 : Column(category, header, name, description) |
|
128 {} |
|
129 bool is_memory_size() const { return true; } |
|
130 }; |
|
131 |
|
132 class DeltaMemorySizeColumn: public Column { |
|
133 int do_print(outputStream* os, value_t value, value_t last_value, |
|
134 int last_value_age, const print_info_t* pi) const; |
|
135 public: |
|
136 DeltaMemorySizeColumn(const char* category, const char* header, const char* name, const char* description) |
|
137 : Column(category, header, name, description) |
|
138 {} |
|
139 bool is_memory_size() const { return true; } |
|
140 bool is_delta() const { return true; } |
|
141 }; |
|
142 |
|
143 class ColumnList: public CHeapObj<mtInternal> { |
|
144 |
|
145 Column* _first, *_last; |
|
146 int _num_columns; |
|
147 |
|
148 static ColumnList* _the_list; |
|
149 |
|
150 public: |
|
151 |
|
152 ColumnList() |
|
153 : _first(NULL), _last(NULL), _num_columns(0) |
|
154 {} |
|
155 |
|
156 const Column* first() const { return _first; } |
|
157 int num_columns() const { return _num_columns; } |
|
158 |
|
159 void add_column(Column* column); |
|
160 |
|
161 static ColumnList* the_list () { return _the_list; } |
|
162 |
|
163 static bool initialize(); |
|
164 |
|
165 #ifdef ASSERT |
|
166 bool is_valid_column_index(int idx) { |
|
167 return idx >= 0 && idx < _num_columns; |
|
168 } |
|
169 #endif |
|
170 |
|
171 }; |
|
172 |
|
173 // Implemented by platform specific |
|
174 bool platform_columns_initialize(); |
|
175 |
|
176 void sample_platform_values(record_t* record); |
|
177 void sample_jvm_values(record_t* record, bool avoid_locking); |
|
178 |
|
179 }; // namespace StatisticsHistory |
|
180 |
|
181 #endif /* HOTSPOT_SHARE_SERVICES_STATHIST_INTERNALS_HPP */ |