/* * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
#include"precompiled.hpp"
// This test performs mocking of certain JVM functionality. This works by // including the source file under test inside an anonymous namespace (which // prevents linking conflicts) with the mocked symbols redefined.
// The include list should mirror the one found in the included source file - // with the ones that should pick up the mocks removed. Those should be included // later after the mocks have been defined.
// Reincluding source files in the anonymous namespace unfortunately seems to // behave strangely with precompiled headers (only when using gcc though) #ifndef DONT_USE_PRECOMPILED_HEADER #define DONT_USE_PRECOMPILED_HEADER #endif
// First call will not report above 100%
MockOs::user_cpu_time = 200 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time = 100 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, 200 * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.5, event.user);
EXPECT_FLOAT_EQ(0.5, event.system);
// Second call will see an extra 100 millisecs user time from the remainder
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (200 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.25, event.user);
EXPECT_FLOAT_EQ(0, event.system);
// Third call: make sure there are no leftovers
MockOs::user_cpu_time += 50 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time += 50 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (200 + 400 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.125, event.user);
EXPECT_FLOAT_EQ(0.125, event.system);
}
// Setup a non zero base // Previously there was a bug when cur_user_time would be reset to zero and test that uses zero base would fail to detect it
MockOs::user_cpu_time = 100 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time = 100 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, 400 * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.25, event.user);
EXPECT_FLOAT_EQ(0.25, event.system);
// First call will not report above 100%
MockOs::user_cpu_time += 200 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time += 100 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (400 + 200) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.5, event.user);
EXPECT_FLOAT_EQ(0.5, event.system);
// Second call will see an extra 100 millisecs user time from the remainder
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (400 + 200 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.25, event.user);
EXPECT_FLOAT_EQ(0, event.system);
// Third call: make sure there are no leftovers
MockOs::user_cpu_time += 50 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time += 50 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (400 + 200 + 400 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.125, event.user);
EXPECT_FLOAT_EQ(0.125, event.system);
}
// First call will not report above 100%
MockOs::user_cpu_time = 100 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time = 300 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, 200 * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0, event.user);
EXPECT_FLOAT_EQ(1, event.system);
// Second call will see an extra 100 millisecs user and system time from the remainder
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (200 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.25, event.user);
EXPECT_FLOAT_EQ(0.25, event.system);
// Third call: make sure there are no leftovers
MockOs::user_cpu_time += 50 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time += 50 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (200 + 400 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.125, event.user);
EXPECT_FLOAT_EQ(0.125, event.system);
}
// Setup a non zero base // Previously there was a bug when cur_user_time would be reset to zero and test that uses zero base would fail to detect it
MockOs::user_cpu_time = 100 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time = 100 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, 400 * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.25, event.user);
EXPECT_FLOAT_EQ(0.25, event.system);
// First call will not report above 100%
MockOs::user_cpu_time += 100 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time += 300 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (400 + 200) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0, event.user);
EXPECT_FLOAT_EQ(1, event.system);
// Second call will see an extra 100 millisecs user and system time from the remainder
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (400 + 200 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.25, event.user);
EXPECT_FLOAT_EQ(0.25, event.system);
// Third call: make sure there are no leftovers
MockOs::user_cpu_time += 50 * NANOSECS_PER_MILLISEC;
MockOs::system_cpu_time += 50 * NANOSECS_PER_MILLISEC;
EXPECT_TRUE(JfrThreadCPULoadEvent::update_event(event, thread, (400 + 200 + 400 + 400) * NANOSECS_PER_MILLISEC, 1));
EXPECT_FLOAT_EQ(0.125, event.user);
EXPECT_FLOAT_EQ(0.125, event.system);
}
// As seen in an actual run - caused by different resolution for total and user time // Total time User time (Calculated system time) // 200 100 100 // 210 200 10 // 400 300 100
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.