| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <string> |
| 36 |
#include <gtest/gtest.h> |
| 37 |
#include <stk_util/parallel/Parallel.hpp> |
| 38 |
#include <stk_util/diag/Timer.hpp> |
| 39 |
#include <stk_util/diag/PrintTimer.hpp> |
| 40 |
|
| 41 |
#include <stk_unit_test_utils/timer.hpp> |
| 42 |
#include <vector> |
| 43 |
#include <iostream> |
| 44 |
#include <chrono> |
| 45 |
#include <thread> |
| 46 |
|
| 47 |
TEST(PrintTimersTable, performance) |
| 48 |
{ |
| 49 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 50 |
|
| 51 |
const unsigned NUM_BATCHES = 5; |
| 52 |
const unsigned NUM_RUNS = 5; |
| 53 |
|
| 54 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 55 |
batchTimer.initialize_batch_timer(); |
| 56 |
|
| 57 |
for(unsigned b=0; b<NUM_BATCHES; ++b) { |
| 58 |
batchTimer.start_batch_timer(); |
| 59 |
|
| 60 |
for(unsigned r=0; r<NUM_RUNS; ++r) { |
| 61 |
constexpr int CHILDMASK1 = 1; |
| 62 |
using namespace std::chrono_literals; |
| 63 |
|
| 64 |
stk::diag::TimerSet enabledTimerSet(CHILDMASK1); |
| 65 |
stk::diag::Timer rootTimer(stk::diag::createRootTimer("root-timer", enabledTimerSet)); |
| 66 |
stk::diag::Timer child1("child1-timer", CHILDMASK1, rootTimer); |
| 67 |
stk::diag::Timer child2("child2-timer", CHILDMASK1, rootTimer); |
| 68 |
stk::diag::Timer child3("child3-timer", CHILDMASK1, rootTimer); |
| 69 |
stk::diag::Timer child4("child4-timer", CHILDMASK1, rootTimer); |
| 70 |
stk::diag::Timer child5("child5-timer", CHILDMASK1, rootTimer); |
| 71 |
|
| 72 |
rootTimer.start(); |
| 73 |
std::this_thread::sleep_for(20ms); |
| 74 |
|
| 75 |
{ |
| 76 |
stk::diag::TimeBlock timeBlock1(child1, comm); |
| 77 |
std::this_thread::sleep_for(100ms); |
| 78 |
|
| 79 |
{ |
| 80 |
stk::diag::TimeBlock timeBlock2(child2, comm); |
| 81 |
std::this_thread::sleep_for(100ms); |
| 82 |
|
| 83 |
{ |
| 84 |
stk::diag::TimeBlock timeBlock3(child3, comm); |
| 85 |
std::this_thread::sleep_for(100ms); |
| 86 |
|
| 87 |
{ |
| 88 |
stk::diag::TimeBlock timeBlock4(child4, comm); |
| 89 |
std::this_thread::sleep_for(100ms); |
| 90 |
|
| 91 |
{ |
| 92 |
stk::diag::TimeBlock timeBlock5(child5, comm); |
| 93 |
std::this_thread::sleep_for(100ms); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
std::ostringstream oss; |
| 101 |
stk::diag::printTimersTable(oss, rootTimer, stk::diag::METRICS_ALL, false, comm); |
| 102 |
|
| 103 |
stk::diag::deleteRootTimer(rootTimer); |
| 104 |
} |
| 105 |
|
| 106 |
batchTimer.stop_batch_timer(); |
| 107 |
} |
| 108 |
|
| 109 |
batchTimer.print_batch_timing(NUM_RUNS); |
| 110 |
} |
| 111 |
|