| File: | jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp |
| Warning: | line 127, column 3 Potential memory leak |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * Copyright (c) 2018, 2019, 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 | ||||
| 27 | // This test performs mocking of certain JVM functionality. This works by | |||
| 28 | // including the source file under test inside an anonymous namespace (which | |||
| 29 | // prevents linking conflicts) with the mocked symbols redefined. | |||
| 30 | ||||
| 31 | // The include list should mirror the one found in the included source file - | |||
| 32 | // with the ones that should pick up the mocks removed. Those should be included | |||
| 33 | // later after the mocks have been defined. | |||
| 34 | ||||
| 35 | #include "logging/log.hpp" | |||
| 36 | #include "jfr/jfrEvents.hpp" | |||
| 37 | #include "jfr/metadata/jfrSerializer.hpp" | |||
| 38 | #include "jfr/periodic/jfrOSInterface.hpp" | |||
| 39 | #include "jfr/utilities/jfrTime.hpp" | |||
| 40 | #include "jfr/utilities/jfrTypes.hpp" | |||
| 41 | #include "runtime/os_perf.hpp" | |||
| 42 | #include "utilities/globalDefinitions.hpp" | |||
| 43 | #include "utilities/growableArray.hpp" | |||
| 44 | ||||
| 45 | #include "unittest.hpp" | |||
| 46 | ||||
| 47 | #include <vector> | |||
| 48 | #include <list> | |||
| 49 | #include <map> | |||
| 50 | ||||
| 51 | namespace { | |||
| 52 | ||||
| 53 | class MockFastUnorderedElapsedCounterSource : public ::FastUnorderedElapsedCounterSource { | |||
| 54 | public: | |||
| 55 | static jlong current_ticks; | |||
| 56 | static Type now() { | |||
| 57 | return current_ticks; | |||
| 58 | } | |||
| 59 | static uint64_t nanoseconds(Type value) { | |||
| 60 | return value; | |||
| 61 | } | |||
| 62 | }; | |||
| 63 | ||||
| 64 | typedef TimeInstant<CounterRepresentation, MockFastUnorderedElapsedCounterSource> MockJfrTicks; | |||
| 65 | typedef TimeInterval<CounterRepresentation, MockFastUnorderedElapsedCounterSource> MockJfrTickspan; | |||
| 66 | ||||
| 67 | class MockJfrCheckpointWriter { | |||
| 68 | public: | |||
| 69 | traceid current; | |||
| 70 | std::map<traceid, std::string> ids; | |||
| 71 | ||||
| 72 | const JfrCheckpointContext context() const { | |||
| 73 | return JfrCheckpointContext(); | |||
| 74 | } | |||
| 75 | intptr_t reserve(size_t size) { | |||
| 76 | return 0; | |||
| 77 | } | |||
| 78 | void write_key(traceid id) { | |||
| 79 | current = id; | |||
| 80 | } | |||
| 81 | void write_type(JfrTypeId id) {} | |||
| 82 | MockJfrCheckpointWriter() {} | |||
| 83 | void write(const char* data) {} | |||
| 84 | void set_context(const JfrCheckpointContext ctx) { } | |||
| 85 | void write_count(u4 nof_entries) { } | |||
| 86 | }; | |||
| 87 | ||||
| 88 | class MockJfrSerializer { | |||
| 89 | public: | |||
| 90 | static bool register_serializer(JfrTypeId id, bool permit_cache, MockJfrSerializer* serializer) { | |||
| 91 | return true; | |||
| 92 | } | |||
| 93 | virtual void on_rotation() {} | |||
| 94 | virtual void serialize(MockJfrCheckpointWriter& writer) {} | |||
| 95 | }; | |||
| 96 | ||||
| 97 | struct MockNetworkInterface { | |||
| 98 | std::string name; | |||
| 99 | uint64_t bytes_in; | |||
| 100 | uint64_t bytes_out; | |||
| 101 | traceid id; | |||
| 102 | MockNetworkInterface(std::string name, uint64_t bytes_in, uint64_t bytes_out, traceid id) : | |||
| 103 | name(name), bytes_in(bytes_in), bytes_out(bytes_out), id(id) {} | |||
| 104 | ||||
| 105 | bool operator==(const MockNetworkInterface& rhs) const { | |||
| 106 | return name == rhs.name; | |||
| 107 | } | |||
| 108 | }; | |||
| 109 | ||||
| 110 | class NetworkInterface : public ::NetworkInterface { | |||
| 111 | public: | |||
| 112 | NetworkInterface(const char* name, uint64_t bytes_in, uint64_t bytes_out, NetworkInterface* next) : | |||
| 113 | ::NetworkInterface(name, bytes_in, bytes_out, next) {} | |||
| 114 | NetworkInterface* next(void) const { | |||
| 115 | return reinterpret_cast<NetworkInterface*>(::NetworkInterface::next()); | |||
| 116 | } | |||
| 117 | }; | |||
| 118 | ||||
| 119 | class MockJfrOSInterface { | |||
| 120 | static std::list<MockNetworkInterface> _interfaces; | |||
| 121 | public: | |||
| 122 | MockJfrOSInterface() {} | |||
| 123 | static int network_utilization(NetworkInterface** network_interfaces) { | |||
| 124 | *network_interfaces = NULL__null; | |||
| 125 | for (std::list<MockNetworkInterface>::const_iterator i = _interfaces.begin(); | |||
| 126 | i != _interfaces.end(); | |||
| 127 | ++i) { | |||
| 128 | NetworkInterface* cur = new NetworkInterface(i->name.c_str(), i->bytes_in, i->bytes_out, *network_interfaces); | |||
| 129 | *network_interfaces = cur; | |||
| 130 | } | |||
| 131 | return OS_OK; | |||
| 132 | } | |||
| 133 | static MockNetworkInterface& add_interface(const std::string& name, traceid id) { | |||
| 134 | MockNetworkInterface iface(name, 0, 0, id); | |||
| 135 | _interfaces.push_front(iface); | |||
| 136 | return _interfaces.front(); | |||
| 137 | } | |||
| 138 | static void remove_interface(const MockNetworkInterface& iface) { | |||
| 139 | _interfaces.remove(iface); | |||
| 140 | } | |||
| 141 | static void clear_interfaces() { | |||
| 142 | _interfaces.clear(); | |||
| 143 | } | |||
| 144 | static const MockNetworkInterface& get_interface(traceid id) { | |||
| 145 | std::list<MockNetworkInterface>::const_iterator i = _interfaces.begin(); | |||
| 146 | for (; i != _interfaces.end(); ++i) { | |||
| 147 | if (i->id == id) { | |||
| 148 | break; | |||
| 149 | } | |||
| 150 | } | |||
| 151 | return *i; | |||
| 152 | } | |||
| 153 | }; | |||
| 154 | ||||
| 155 | std::list<MockNetworkInterface> MockJfrOSInterface::_interfaces; | |||
| 156 | ||||
| 157 | class MockEventNetworkUtilization : public ::EventNetworkUtilization { | |||
| 158 | public: | |||
| 159 | std::string iface; | |||
| 160 | s8 readRate; | |||
| 161 | s8 writeRate; | |||
| 162 | static std::vector<MockEventNetworkUtilization> committed; | |||
| 163 | MockJfrCheckpointWriter writer; | |||
| 164 | ||||
| 165 | public: | |||
| 166 | MockEventNetworkUtilization(EventStartTime timing=TIMED) : | |||
| 167 | ::EventNetworkUtilization(timing) {} | |||
| 168 | ||||
| 169 | void set_networkInterface(traceid new_value) { | |||
| 170 | const MockNetworkInterface& entry = MockJfrOSInterface::get_interface(new_value); | |||
| 171 | iface = entry.name; | |||
| 172 | } | |||
| 173 | void set_readRate(s8 new_value) { | |||
| 174 | readRate = new_value; | |||
| 175 | } | |||
| 176 | void set_writeRate(s8 new_value) { | |||
| 177 | writeRate = new_value; | |||
| 178 | } | |||
| 179 | ||||
| 180 | void commit() { | |||
| 181 | committed.push_back(*this); | |||
| 182 | } | |||
| 183 | ||||
| 184 | void set_starttime(const MockJfrTicks& time) {} | |||
| 185 | void set_endtime(const MockJfrTicks& time) {} | |||
| 186 | ||||
| 187 | static const MockEventNetworkUtilization& get_committed(const std::string& name) { | |||
| 188 | static MockEventNetworkUtilization placeholder; | |||
| 189 | for (std::vector<MockEventNetworkUtilization>::const_iterator i = committed.begin(); | |||
| 190 | i != committed.end(); | |||
| 191 | ++i) { | |||
| 192 | if (name == i->iface) { | |||
| 193 | return *i; | |||
| 194 | } | |||
| 195 | } | |||
| 196 | return placeholder; | |||
| 197 | } | |||
| 198 | }; | |||
| 199 | ||||
| 200 | std::vector<MockEventNetworkUtilization> MockEventNetworkUtilization::committed; | |||
| 201 | ||||
| 202 | jlong MockFastUnorderedElapsedCounterSource::current_ticks; | |||
| 203 | ||||
| 204 | // Reincluding source files in the anonymous namespace unfortunately seems to | |||
| 205 | // behave strangely with precompiled headers (only when using gcc though) | |||
| 206 | #ifndef DONT_USE_PRECOMPILED_HEADER | |||
| 207 | #define DONT_USE_PRECOMPILED_HEADER | |||
| 208 | #endif | |||
| 209 | ||||
| 210 | #define EventNetworkUtilization MockEventNetworkUtilization | |||
| 211 | #define FastUnorderedElapsedCounterSource MockFastUnorderedElapsedCounterSource | |||
| 212 | #define JfrOSInterface MockJfrOSInterface | |||
| 213 | #define JfrSerializer MockJfrSerializer | |||
| 214 | #define JfrCheckpointWriter MockJfrCheckpointWriter | |||
| 215 | #define JfrTicks MockJfrTicks | |||
| 216 | #define JfrTickspan MockJfrTickspan | |||
| 217 | ||||
| 218 | #include "jfr/periodic/jfrNetworkUtilization.hpp" | |||
| 219 | #include "jfr/periodic/jfrNetworkUtilization.cpp" | |||
| 220 | ||||
| 221 | #undef EventNetworkUtilization | |||
| 222 | #undef FastUnorderedElapsedCounterSource | |||
| 223 | #undef JfrOSInterface | |||
| 224 | #undef JfrSerializer | |||
| 225 | #undef JfrCheckpointWriter | |||
| 226 | #undef JfrTicks | |||
| 227 | #undef JfrTickspan | |||
| 228 | ||||
| 229 | } // anonymous namespace | |||
| 230 | ||||
| 231 | class JfrTestNetworkUtilization : public ::testing::Test { | |||
| 232 | protected: | |||
| 233 | void SetUp() { | |||
| 234 | MockEventNetworkUtilization::committed.clear(); | |||
| 235 | MockJfrOSInterface::clear_interfaces(); | |||
| 236 | // Ensure that tests are separated in time | |||
| 237 | MockFastUnorderedElapsedCounterSource::current_ticks += 1 * NANOSECS_PER_SEC; | |||
| 238 | } | |||
| 239 | ||||
| 240 | void TearDown() { | |||
| 241 | JfrNetworkUtilization::destroy(); | |||
| 242 | } | |||
| 243 | }; | |||
| 244 | ||||
| 245 | static traceid id = 0; | |||
| 246 | ||||
| 247 | TEST_VM_F(JfrTestNetworkUtilization, RequestFunctionBasic)class JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test : public JfrTestNetworkUtilization { public: JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test (JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test const &) = delete; void operator=(JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test const &) = delete;};::testing::TestInfo* const JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "JfrTestNetworkUtilization", "RequestFunctionBasic_vm", __null , __null, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 247), (::testing::internal::GetTypeId<JfrTestNetworkUtilization >()), JfrTestNetworkUtilization::SetUpTestCase, JfrTestNetworkUtilization ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test>); void JfrTestNetworkUtilization_RequestFunctionBasic_vm_Test:: TestBody() { | |||
| 248 | ||||
| 249 | MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0", ++id); | |||
| 250 | JfrNetworkUtilization::send_events(); | |||
| 251 | ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u", "MockEventNetworkUtilization::committed.size()", 0u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 251, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 252 | ||||
| 253 | eth0.bytes_in += 10; | |||
| 254 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 255 | ||||
| 256 | JfrNetworkUtilization::send_events(); | |||
| 257 | ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "MockEventNetworkUtilization::committed.size()", 1u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 257, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 258 | MockEventNetworkUtilization& e = MockEventNetworkUtilization::committed[0]; | |||
| 259 | EXPECT_EQ(40, e.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(40)) == 1)>::Compare("40", "e.readRate", 40, e.readRate))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 259, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 260 | EXPECT_EQ(0, e.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "e.writeRate" , 0, e.writeRate))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 260, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 261 | EXPECT_STREQ("eth0", e.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth0\"", "e.iface.c_str()" , "eth0", e.iface.c_str()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 261, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 262 | } | |||
| 263 | ||||
| 264 | TEST_VM_F(JfrTestNetworkUtilization, RequestFunctionMultiple)class JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test : public JfrTestNetworkUtilization { public: JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test (JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test const &) = delete; void operator=(JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test const &) = delete;};::testing::TestInfo* const JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "JfrTestNetworkUtilization", "RequestFunctionMultiple_vm", __null , __null, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 264), (::testing::internal::GetTypeId<JfrTestNetworkUtilization >()), JfrTestNetworkUtilization::SetUpTestCase, JfrTestNetworkUtilization ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test> );void JfrTestNetworkUtilization_RequestFunctionMultiple_vm_Test ::TestBody() { | |||
| 265 | ||||
| 266 | MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0", ++id); | |||
| 267 | MockNetworkInterface& eth1 = MockJfrOSInterface::add_interface("eth1", ++id); | |||
| 268 | MockNetworkInterface& ppp0 = MockJfrOSInterface::add_interface("ppp0", ++id); | |||
| 269 | JfrNetworkUtilization::send_events(); | |||
| 270 | ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u", "MockEventNetworkUtilization::committed.size()", 0u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 270, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 271 | ||||
| 272 | eth0.bytes_in += 10; | |||
| 273 | eth1.bytes_in += 100; | |||
| 274 | ppp0.bytes_out += 50; | |||
| 275 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 276 | ||||
| 277 | JfrNetworkUtilization::send_events(); | |||
| 278 | ASSERT_EQ(3u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(3u)) == 1)>::Compare("3u", "MockEventNetworkUtilization::committed.size()", 3u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 278, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 279 | const MockEventNetworkUtilization& eth0_event = MockEventNetworkUtilization::get_committed("eth0"); | |||
| 280 | const MockEventNetworkUtilization& eth1_event = MockEventNetworkUtilization::get_committed("eth1"); | |||
| 281 | const MockEventNetworkUtilization& ppp0_event = MockEventNetworkUtilization::get_committed("ppp0"); | |||
| 282 | ||||
| 283 | EXPECT_EQ(40, eth0_event.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(40)) == 1)>::Compare("40", "eth0_event.readRate", 40, eth0_event.readRate))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 283, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 284 | EXPECT_EQ(0, eth0_event.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "eth0_event.writeRate" , 0, eth0_event.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 284, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 285 | EXPECT_STREQ("eth0", eth0_event.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth0\"", "eth0_event.iface.c_str()" , "eth0", eth0_event.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 285, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 286 | ||||
| 287 | EXPECT_EQ(400, eth1_event.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(400)) == 1)>::Compare("400" , "eth1_event.readRate", 400, eth1_event.readRate))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 287, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 288 | EXPECT_EQ(0, eth1_event.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "eth1_event.writeRate" , 0, eth1_event.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 288, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 289 | EXPECT_STREQ("eth1", eth1_event.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth1\"", "eth1_event.iface.c_str()" , "eth1", eth1_event.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 289, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 290 | ||||
| 291 | EXPECT_EQ(0, ppp0_event.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "ppp0_event.readRate" , 0, ppp0_event.readRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 291, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 292 | EXPECT_EQ(200, ppp0_event.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(200)) == 1)>::Compare("200" , "ppp0_event.writeRate", 200, ppp0_event.writeRate))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 292, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 293 | EXPECT_STREQ("ppp0", ppp0_event.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"ppp0\"", "ppp0_event.iface.c_str()" , "ppp0", ppp0_event.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 293, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 294 | } | |||
| 295 | ||||
| 296 | TEST_VM_F(JfrTestNetworkUtilization, InterfaceRemoved)class JfrTestNetworkUtilization_InterfaceRemoved_vm_Test : public JfrTestNetworkUtilization { public: JfrTestNetworkUtilization_InterfaceRemoved_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); JfrTestNetworkUtilization_InterfaceRemoved_vm_Test (JfrTestNetworkUtilization_InterfaceRemoved_vm_Test const & ) = delete; void operator=(JfrTestNetworkUtilization_InterfaceRemoved_vm_Test const &) = delete;};::testing::TestInfo* const JfrTestNetworkUtilization_InterfaceRemoved_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "JfrTestNetworkUtilization", "InterfaceRemoved_vm", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 296), (::testing::internal::GetTypeId<JfrTestNetworkUtilization >()), JfrTestNetworkUtilization::SetUpTestCase, JfrTestNetworkUtilization ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< JfrTestNetworkUtilization_InterfaceRemoved_vm_Test>);void JfrTestNetworkUtilization_InterfaceRemoved_vm_Test::TestBody () { | |||
| 297 | MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0", ++id); | |||
| 298 | MockNetworkInterface& eth1 = MockJfrOSInterface::add_interface("eth1", ++id); | |||
| 299 | JfrNetworkUtilization::send_events(); | |||
| 300 | ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u", "MockEventNetworkUtilization::committed.size()", 0u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 300, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 301 | ||||
| 302 | eth0.bytes_in += 10; | |||
| 303 | eth1.bytes_in += 20; | |||
| 304 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 305 | ||||
| 306 | JfrNetworkUtilization::send_events(); | |||
| 307 | ASSERT_EQ(2u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(2u)) == 1)>::Compare("2u", "MockEventNetworkUtilization::committed.size()", 2u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 307, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 308 | const MockEventNetworkUtilization& eth0_event = MockEventNetworkUtilization::get_committed("eth0"); | |||
| 309 | const MockEventNetworkUtilization& eth1_event = MockEventNetworkUtilization::get_committed("eth1"); | |||
| 310 | ||||
| 311 | EXPECT_EQ(40, eth0_event.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(40)) == 1)>::Compare("40", "eth0_event.readRate", 40, eth0_event.readRate))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 311, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 312 | EXPECT_EQ(0, eth0_event.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "eth0_event.writeRate" , 0, eth0_event.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 312, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 313 | EXPECT_STREQ("eth0", eth0_event.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth0\"", "eth0_event.iface.c_str()" , "eth0", eth0_event.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 313, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 314 | ||||
| 315 | EXPECT_EQ(80, eth1_event.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(80)) == 1)>::Compare("80", "eth1_event.readRate", 80, eth1_event.readRate))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 315, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 316 | EXPECT_EQ(0, eth1_event.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "eth1_event.writeRate" , 0, eth1_event.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 316, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 317 | EXPECT_STREQ("eth1", eth1_event.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth1\"", "eth1_event.iface.c_str()" , "eth1", eth1_event.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 317, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 318 | ||||
| 319 | MockJfrOSInterface::remove_interface(eth0); | |||
| 320 | MockEventNetworkUtilization::committed.clear(); | |||
| 321 | ||||
| 322 | eth1.bytes_in += 10; | |||
| 323 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 324 | JfrNetworkUtilization::send_events(); | |||
| 325 | ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "MockEventNetworkUtilization::committed.size()", 1u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 325, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 326 | const MockEventNetworkUtilization& eth1_event_v2 = MockEventNetworkUtilization::get_committed("eth1"); | |||
| 327 | ||||
| 328 | EXPECT_EQ(40, eth1_event_v2.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(40)) == 1)>::Compare("40", "eth1_event_v2.readRate", 40, eth1_event_v2.readRate))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 328, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 329 | EXPECT_EQ(0, eth1_event_v2.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "eth1_event_v2.writeRate" , 0, eth1_event_v2.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 329, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 330 | EXPECT_STREQ("eth1", eth1_event_v2.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth1\"", "eth1_event_v2.iface.c_str()" , "eth1", eth1_event_v2.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 330, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 331 | } | |||
| 332 | ||||
| 333 | TEST_VM_F(JfrTestNetworkUtilization, InterfaceReset)class JfrTestNetworkUtilization_InterfaceReset_vm_Test : public JfrTestNetworkUtilization { public: JfrTestNetworkUtilization_InterfaceReset_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); JfrTestNetworkUtilization_InterfaceReset_vm_Test (JfrTestNetworkUtilization_InterfaceReset_vm_Test const & ) = delete; void operator=(JfrTestNetworkUtilization_InterfaceReset_vm_Test const &) = delete;};::testing::TestInfo* const JfrTestNetworkUtilization_InterfaceReset_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "JfrTestNetworkUtilization", "InterfaceReset_vm", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 333), (::testing::internal::GetTypeId<JfrTestNetworkUtilization >()), JfrTestNetworkUtilization::SetUpTestCase, JfrTestNetworkUtilization ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< JfrTestNetworkUtilization_InterfaceReset_vm_Test>);void JfrTestNetworkUtilization_InterfaceReset_vm_Test ::TestBody() { | |||
| 334 | MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0", ++id); | |||
| 335 | JfrNetworkUtilization::send_events(); | |||
| ||||
| 336 | ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u", "MockEventNetworkUtilization::committed.size()", 0u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 336, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 337 | ||||
| 338 | eth0.bytes_in += 10; | |||
| 339 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 340 | ||||
| 341 | JfrNetworkUtilization::send_events(); | |||
| 342 | ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "MockEventNetworkUtilization::committed.size()", 1u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 342, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 343 | const MockEventNetworkUtilization& event = MockEventNetworkUtilization::committed[0]; | |||
| 344 | EXPECT_EQ(40, event.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(40)) == 1)>::Compare("40", "event.readRate", 40, event.readRate))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 344, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 345 | EXPECT_EQ(0, event.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "event.writeRate" , 0, event.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 345, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 346 | EXPECT_STREQ("eth0", event.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth0\"", "event.iface.c_str()" , "eth0", event.iface.c_str()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 346, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 347 | ||||
| 348 | eth0.bytes_in = 0; | |||
| 349 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 350 | MockEventNetworkUtilization::committed.clear(); | |||
| 351 | ||||
| 352 | JfrNetworkUtilization::send_events(); | |||
| 353 | ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u", "MockEventNetworkUtilization::committed.size()", 0u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 353, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 354 | ||||
| 355 | eth0.bytes_in = 10; | |||
| 356 | MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC; | |||
| 357 | ||||
| 358 | JfrNetworkUtilization::send_events(); | |||
| 359 | ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "MockEventNetworkUtilization::committed.size()", 1u, MockEventNetworkUtilization ::committed.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 359, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 360 | const MockEventNetworkUtilization& event_v2 = MockEventNetworkUtilization::committed[0]; | |||
| 361 | EXPECT_EQ(40, event_v2.readRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(40)) == 1)>::Compare("40", "event_v2.readRate", 40, event_v2.readRate))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 361, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 362 | EXPECT_EQ(0, event_v2.writeRate)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0)) == 1)>::Compare("0", "event_v2.writeRate" , 0, event_v2.writeRate))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 362, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 363 | EXPECT_STREQ("eth0", event_v2.iface.c_str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth0\"", "event_v2.iface.c_str()" , "eth0", event_v2.iface.c_str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/jfr/test_networkUtilization.cpp" , 363, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 364 | } |
| 1 | /* | ||||
| 2 | * Copyright (c) 2019, 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 "logging/log.hpp" | ||||
| 27 | #include "jfr/jfrEvents.hpp" | ||||
| 28 | #include "jfr/metadata/jfrSerializer.hpp" | ||||
| 29 | #include "jfr/periodic/jfrNetworkUtilization.hpp" | ||||
| 30 | #include "jfr/periodic/jfrOSInterface.hpp" | ||||
| 31 | #include "jfr/utilities/jfrTime.hpp" | ||||
| 32 | #include "jfr/utilities/jfrTypes.hpp" | ||||
| 33 | #include "runtime/os_perf.hpp" | ||||
| 34 | #include "utilities/globalDefinitions.hpp" | ||||
| 35 | #include "utilities/growableArray.hpp" | ||||
| 36 | |||||
| 37 | struct InterfaceEntry { | ||||
| 38 | char* name; | ||||
| 39 | traceid id; | ||||
| 40 | uint64_t bytes_in; | ||||
| 41 | uint64_t bytes_out; | ||||
| 42 | mutable bool written; | ||||
| 43 | }; | ||||
| 44 | |||||
| 45 | static GrowableArray<InterfaceEntry>* _interfaces = NULL__null; | ||||
| 46 | |||||
| 47 | void JfrNetworkUtilization::destroy() { | ||||
| 48 | if (_interfaces != NULL__null) { | ||||
| 49 | for (int i = 0; i < _interfaces->length(); ++i) { | ||||
| 50 | FREE_C_HEAP_ARRAY(char, _interfaces->at(i).name)FreeHeap((char*)(_interfaces->at(i).name)); | ||||
| 51 | } | ||||
| 52 | delete _interfaces; | ||||
| 53 | _interfaces = NULL__null; | ||||
| 54 | } | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | static InterfaceEntry& new_entry(const NetworkInterface* iface, GrowableArray<InterfaceEntry>* interfaces) { | ||||
| 58 | assert(iface != NULL, "invariant")do { if (!(iface != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp" , 58, "assert(" "iface != __null" ") failed", "invariant"); :: breakpoint(); } } while (0); | ||||
| 59 | assert(interfaces != NULL, "invariant")do { if (!(interfaces != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp" , 59, "assert(" "interfaces != __null" ") failed", "invariant" ); ::breakpoint(); } } while (0); | ||||
| 60 | |||||
| 61 | // single threaded premise | ||||
| 62 | static traceid interface_id = 0; | ||||
| 63 | |||||
| 64 | const char* name = iface->get_name(); | ||||
| 65 | assert(name != NULL, "invariant")do { if (!(name != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp" , 65, "assert(" "name != __null" ") failed", "invariant"); :: breakpoint(); } } while (0); | ||||
| 66 | |||||
| 67 | InterfaceEntry entry; | ||||
| 68 | const size_t length = strlen(name); | ||||
| 69 | entry.name = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal)(char*) (AllocateHeap((length + 1) * sizeof(char), mtInternal )); | ||||
| 70 | strncpy(entry.name, name, length + 1); | ||||
| 71 | entry.id = ++interface_id; | ||||
| 72 | entry.bytes_in = iface->get_bytes_in(); | ||||
| 73 | entry.bytes_out = iface->get_bytes_out(); | ||||
| 74 | entry.written = false; | ||||
| 75 | return _interfaces->at(_interfaces->append(entry)); | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | static GrowableArray<InterfaceEntry>* get_interfaces() { | ||||
| 79 | if (_interfaces == NULL__null) { | ||||
| 80 | _interfaces = new(ResourceObj::C_HEAP, mtTracing) GrowableArray<InterfaceEntry>(10, mtTracing); | ||||
| 81 | } | ||||
| 82 | return _interfaces; | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | static InterfaceEntry& get_entry(const NetworkInterface* iface) { | ||||
| 86 | // Remember the index we started at last time, since we're most likely looking at them | ||||
| 87 | // in the same order every time. | ||||
| 88 | static int saved_index = -1; | ||||
| 89 | |||||
| 90 | GrowableArray<InterfaceEntry>* interfaces = get_interfaces(); | ||||
| 91 | assert(interfaces != NULL, "invariant")do { if (!(interfaces != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp" , 91, "assert(" "interfaces != __null" ") failed", "invariant" ); ::breakpoint(); } } while (0); | ||||
| 92 | for (int i = 0; i < _interfaces->length(); ++i) { | ||||
| 93 | saved_index = (saved_index + 1) % _interfaces->length(); | ||||
| 94 | if (strcmp(_interfaces->at(saved_index).name, iface->get_name()) == 0) { | ||||
| 95 | return _interfaces->at(saved_index); | ||||
| 96 | } | ||||
| 97 | } | ||||
| 98 | return new_entry(iface, interfaces); | ||||
| 99 | } | ||||
| 100 | |||||
| 101 | // If current counters are less than previous we assume the interface has been reset | ||||
| 102 | // If no bytes have been either sent or received, we'll also skip the event | ||||
| 103 | static uint64_t rate_per_second(uint64_t current, uint64_t old, const JfrTickspan& interval) { | ||||
| 104 | assert(interval.value() > 0, "invariant")do { if (!(interval.value() > 0)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp" , 104, "assert(" "interval.value() > 0" ") failed", "invariant" ); ::breakpoint(); } } while (0); | ||||
| 105 | if (current <= old) { | ||||
| 106 | return 0; | ||||
| 107 | } | ||||
| 108 | return ((current - old) * NANOSECS_PER_SEC) / interval.nanoseconds(); | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | class JfrNetworkInterfaceName : public JfrSerializer { | ||||
| 112 | public: | ||||
| 113 | void serialize(JfrCheckpointWriter& writer) {} // we write each constant lazily | ||||
| 114 | |||||
| 115 | void on_rotation() { | ||||
| 116 | for (int i = 0; i < _interfaces->length(); ++i) { | ||||
| 117 | const InterfaceEntry& entry = _interfaces->at(i); | ||||
| 118 | if (entry.written) { | ||||
| 119 | entry.written = false; | ||||
| 120 | } | ||||
| 121 | } | ||||
| 122 | } | ||||
| 123 | }; | ||||
| 124 | |||||
| 125 | static bool register_network_interface_name_serializer() { | ||||
| 126 | assert(_interfaces != NULL, "invariant")do { if (!(_interfaces != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp" , 126, "assert(" "_interfaces != __null" ") failed", "invariant" ); ::breakpoint(); } } while (0); | ||||
| 127 | return JfrSerializer::register_serializer(TYPE_NETWORKINTERFACENAME, | ||||
| |||||
| 128 | false, // disallow caching; we want a callback every rotation | ||||
| 129 | new JfrNetworkInterfaceName()); | ||||
| 130 | } | ||||
| 131 | |||||
| 132 | static void write_interface_constant(const InterfaceEntry& entry) { | ||||
| 133 | if (entry.written) { | ||||
| 134 | return; | ||||
| 135 | } | ||||
| 136 | JfrCheckpointWriter writer; | ||||
| 137 | writer.write_type(TYPE_NETWORKINTERFACENAME); | ||||
| 138 | writer.write_count(1); | ||||
| 139 | writer.write_key(entry.id); | ||||
| 140 | writer.write(entry.name); | ||||
| 141 | entry.written = true; | ||||
| 142 | } | ||||
| 143 | |||||
| 144 | static bool get_interfaces(NetworkInterface** network_interfaces) { | ||||
| 145 | const int ret_val = JfrOSInterface::network_utilization(network_interfaces); | ||||
| 146 | if (ret_val == OS_ERR) { | ||||
| 147 | log_debug(jfr, system)(!(LogImpl<(LogTag::_jfr), (LogTag::_system), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Debug))) ? (void)0 : LogImpl<(LogTag ::_jfr), (LogTag::_system), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Debug>("Unable to generate network utilization events"); | ||||
| 148 | return false; | ||||
| 149 | } | ||||
| 150 | return ret_val != FUNCTIONALITY_NOT_IMPLEMENTED-8; | ||||
| 151 | } | ||||
| 152 | |||||
| 153 | void JfrNetworkUtilization::send_events() { | ||||
| 154 | ResourceMark rm; | ||||
| 155 | NetworkInterface* network_interfaces; | ||||
| 156 | if (!get_interfaces(&network_interfaces)) { | ||||
| 157 | return; | ||||
| 158 | } | ||||
| 159 | static JfrTicks last_sample_instant; | ||||
| 160 | const JfrTicks cur_time = JfrTicks::now(); | ||||
| 161 | if (cur_time > last_sample_instant) { | ||||
| 162 | const JfrTickspan interval = cur_time - last_sample_instant; | ||||
| 163 | for (NetworkInterface *cur = network_interfaces; cur != NULL__null; cur = cur->next()) { | ||||
| 164 | InterfaceEntry& entry = get_entry(cur); | ||||
| 165 | const uint64_t current_bytes_in = cur->get_bytes_in(); | ||||
| 166 | const uint64_t current_bytes_out = cur->get_bytes_out(); | ||||
| 167 | const uint64_t read_rate = rate_per_second(current_bytes_in, entry.bytes_in, interval); | ||||
| 168 | const uint64_t write_rate = rate_per_second(current_bytes_out, entry.bytes_out, interval); | ||||
| 169 | if (read_rate > 0 || write_rate > 0) { | ||||
| 170 | write_interface_constant(entry); | ||||
| 171 | EventNetworkUtilization event(UNTIMED); | ||||
| 172 | event.set_starttime(cur_time); | ||||
| 173 | event.set_endtime(cur_time); | ||||
| 174 | event.set_networkInterface(entry.id); | ||||
| 175 | event.set_readRate(8 * read_rate); | ||||
| 176 | event.set_writeRate(8 * write_rate); | ||||
| 177 | event.commit(); | ||||
| 178 | } | ||||
| 179 | // update existing entry with new values | ||||
| 180 | entry.bytes_in = current_bytes_in; | ||||
| 181 | entry.bytes_out = current_bytes_out; | ||||
| 182 | } | ||||
| 183 | } | ||||
| 184 | last_sample_instant = cur_time; | ||||
| 185 | |||||
| 186 | static bool is_serializer_registered = false; | ||||
| 187 | if (!is_serializer_registered
| ||||
| 188 | is_serializer_registered = register_network_interface_name_serializer(); | ||||
| 189 | } | ||||
| 190 | } |