Skip to content

Commit db89b5a

Browse files
committed
reformat perf for increase coverage
1 parent 7945269 commit db89b5a

9 files changed

Lines changed: 85 additions & 120 deletions

File tree

modules/core/perf/func_tests/perf_tests.cpp

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ TEST(perf_tests, check_perf_pipeline) {
1616
// Create Task
1717
auto test_task = std::make_shared<ppc::test::perf::TestTask<uint32_t>>(in);
1818

19-
// Create Perf attributes
20-
ppc::core::PerfAttr perf_attr;
21-
22-
// Create and init perf results
23-
ppc::core::PerfResults perf_results;
24-
2519
// Create Perf analyzer
2620
ppc::core::Perf perf_analyzer(test_task);
27-
perf_analyzer.PipelineRun(perf_attr, perf_results);
21+
22+
// Create Perf attributes
23+
ppc::core::PerfAttr perf_attr;
24+
perf_analyzer.PipelineRun(perf_attr);
2825

2926
// Get perf statistic
30-
ppc::core::Perf::PrintPerfStatistic(perf_results);
31-
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
27+
perf_analyzer.PrintPerfStatistic();
28+
ASSERT_LE(perf_analyzer.GetPerfResults().time_sec, ppc::core::PerfResults::kMaxTime);
3229
EXPECT_EQ(test_task->Get(), in.size());
3330
}
3431

@@ -39,19 +36,16 @@ TEST(perf_tests, check_perf_pipeline_float) {
3936
// Create Task
4037
auto test_task = std::make_shared<ppc::test::perf::TestTask<float>>(in);
4138

42-
// Create Perf attributes
43-
ppc::core::PerfAttr perf_attr;
44-
45-
// Create and init perf results
46-
ppc::core::PerfResults perf_results;
47-
4839
// Create Perf analyzer
4940
ppc::core::Perf perf_analyzer(test_task);
50-
perf_analyzer.PipelineRun(perf_attr, perf_results);
41+
42+
// Create Perf attributes
43+
ppc::core::PerfAttr perf_attr;
44+
perf_analyzer.PipelineRun(perf_attr);
5145

5246
// Get perf statistic
53-
ppc::core::Perf::PrintPerfStatistic(perf_results);
54-
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
47+
perf_analyzer.PrintPerfStatistic();
48+
ASSERT_LE(perf_analyzer.GetPerfResults().time_sec, ppc::core::PerfResults::kMaxTime);
5549
EXPECT_EQ(test_task->Get(), in.size());
5650
}
5751

@@ -62,6 +56,9 @@ TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
6256
// Create Task
6357
auto test_task = std::make_shared<ppc::test::perf::FakePerfTask<uint8_t>>(in);
6458

59+
// Create Perf analyzer
60+
ppc::core::Perf perf_analyzer(test_task);
61+
6562
// Create Perf attributes
6663
ppc::core::PerfAttr perf_attr;
6764
perf_attr.num_running = 1;
@@ -72,40 +69,28 @@ TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
7269
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
7370
return static_cast<double>(duration) * 1e-9;
7471
};
75-
76-
// Create and init perf results
77-
ppc::core::PerfResults perf_results;
78-
79-
// Create Perf analyzer
80-
ppc::core::Perf perf_analyzer(test_task);
81-
perf_analyzer.PipelineRun(perf_attr, perf_results);
72+
perf_analyzer.PipelineRun(perf_attr);
8273

8374
// Get perf statistic
84-
ASSERT_ANY_THROW(ppc::core::Perf::PrintPerfStatistic(perf_results));
75+
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic());
8576
}
8677

87-
TEST(perf_tests, check_perf_task) {
78+
TEST(perf_tests, check_perf_task_exception) {
8879
// Create data
8980
std::vector<uint32_t> in(2000, 1);
9081

9182
// Create Task
9283
auto test_task = std::make_shared<ppc::test::perf::TestTask<uint32_t>>(in);
9384

94-
// Create Perf attributes
95-
ppc::core::PerfAttr perf_attr;
96-
97-
// Create and init perf results
98-
ppc::core::PerfResults perf_results;
99-
10085
// Create Perf analyzer
10186
ppc::core::Perf perf_analyzer(test_task);
102-
perf_analyzer.TaskRun(perf_attr, perf_results);
10387

10488
// Get perf statistic
105-
perf_results.type_of_running = ppc::core::PerfResults::kNone;
106-
ppc::core::Perf::PrintPerfStatistic(perf_results);
107-
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
108-
EXPECT_EQ(test_task->Get(), in.size());
89+
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic());
90+
91+
// Create Perf attributes
92+
ppc::core::PerfAttr perf_attr;
93+
perf_analyzer.TaskRun(perf_attr);
10994
}
11095

11196
TEST(perf_tests, check_perf_task_float) {
@@ -115,19 +100,15 @@ TEST(perf_tests, check_perf_task_float) {
115100
// Create Task
116101
auto test_task = std::make_shared<ppc::test::perf::TestTask<float>>(in);
117102

118-
// Create Perf attributes
119-
ppc::core::PerfAttr perf_attr;
120-
121-
// Create and init perf results
122-
ppc::core::PerfResults perf_results;
123-
124103
// Create Perf analyzer
125104
ppc::core::Perf perf_analyzer(test_task);
126-
perf_analyzer.TaskRun(perf_attr, perf_results);
105+
106+
// Create Perf attributes
107+
ppc::core::PerfAttr perf_attr;
108+
perf_analyzer.TaskRun(perf_attr);
127109

128110
// Get perf statistic
129-
perf_results.type_of_running = ppc::core::PerfResults::kPipeline;
130-
ppc::core::Perf::PrintPerfStatistic(perf_results);
131-
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
111+
perf_analyzer.PrintPerfStatistic();
112+
ASSERT_LE(perf_analyzer.GetPerfResults().time_sec, ppc::core::PerfResults::kMaxTime);
132113
EXPECT_EQ(test_task->Get(), in.size());
133114
}

modules/core/perf/include/perf.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ class Perf {
2525
public:
2626
// Init performance analysis with initialized task and initialized data
2727
explicit Perf(const std::shared_ptr<Task>& task_ptr);
28-
// Set task with an initialized task and initialized data for performance
29-
// analysis c
30-
void SetTask(const std::shared_ptr<Task>& task_ptr);
3128
// Check performance of full task's pipeline: PreProcessing() ->
3229
// Validation() -> Run() -> PostProcessing()
33-
void PipelineRun(const PerfAttr& perf_attr, PerfResults& perf_results) const;
30+
void PipelineRun(const PerfAttr& perf_attr);
3431
// Check performance of task's Run() function
35-
void TaskRun(const PerfAttr& perf_attr, PerfResults& perf_results) const;
32+
void TaskRun(const PerfAttr& perf_attr);
3633
// Pint results for automation checkers
37-
static void PrintPerfStatistic(const PerfResults& perf_results);
34+
void PrintPerfStatistic() const;
35+
// Get performance result structure of the current task
36+
PerfResults GetPerfResults();
3837

3938
private:
39+
PerfResults perf_results_;
4040
std::shared_ptr<Task> task_;
4141
static void CommonRun(const PerfAttr& perf_attr, const std::function<void()>& pipeline, PerfResults& perf_results);
4242
};

modules/core/perf/src/perf.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313

1414
#include "core/task/include/task.hpp"
1515

16-
ppc::core::Perf::Perf(const std::shared_ptr<Task>& task_ptr) { SetTask(task_ptr); }
17-
18-
void ppc::core::Perf::SetTask(const std::shared_ptr<Task>& task_ptr) {
16+
ppc::core::Perf::Perf(const std::shared_ptr<Task>& task_ptr) : task_(task_ptr) {
1917
task_ptr->GetStateOfTesting() = Task::StateOfTesting::kPerf;
20-
this->task_ = task_ptr;
2118
}
2219

23-
void ppc::core::Perf::PipelineRun(const PerfAttr& perf_attr, ppc::core::PerfResults& perf_results) const {
24-
perf_results.type_of_running = PerfResults::TypeOfRunning::kPipeline;
20+
void ppc::core::Perf::PipelineRun(const PerfAttr& perf_attr) {
21+
perf_results_.type_of_running = PerfResults::TypeOfRunning::kPipeline;
2522

2623
CommonRun(
2724
perf_attr,
@@ -31,15 +28,15 @@ void ppc::core::Perf::PipelineRun(const PerfAttr& perf_attr, ppc::core::PerfResu
3128
task_->Run();
3229
task_->PostProcessing();
3330
},
34-
perf_results);
31+
perf_results_);
3532
}
3633

37-
void ppc::core::Perf::TaskRun(const PerfAttr& perf_attr, ppc::core::PerfResults& perf_results) const {
38-
perf_results.type_of_running = PerfResults::TypeOfRunning::kTaskRun;
34+
void ppc::core::Perf::TaskRun(const PerfAttr& perf_attr) {
35+
perf_results_.type_of_running = PerfResults::TypeOfRunning::kTaskRun;
3936

4037
task_->Validation();
4138
task_->PreProcessing();
42-
CommonRun(perf_attr, [&]() { task_->Run(); }, perf_results);
39+
CommonRun(perf_attr, [&]() { task_->Run(); }, perf_results_);
4340
task_->PostProcessing();
4441

4542
task_->Validation();
@@ -58,20 +55,22 @@ void ppc::core::Perf::CommonRun(const PerfAttr& perf_attr, const std::function<v
5855
perf_results.time_sec = end - begin;
5956
}
6057

61-
void ppc::core::Perf::PrintPerfStatistic(const PerfResults& perf_results) {
58+
void ppc::core::Perf::PrintPerfStatistic() const {
6259
std::string relative_path(::testing::UnitTest::GetInstance()->current_test_info()->file());
6360
std::string ppc_regex_template("parallel_programming_course");
6461
std::string perf_regex_template("perf_tests");
6562
std::string type_test_name;
6663

67-
auto time_secs = perf_results.time_sec;
64+
auto time_secs = perf_results_.time_sec;
6865

69-
if (perf_results.type_of_running == PerfResults::TypeOfRunning::kTaskRun) {
66+
if (perf_results_.type_of_running == PerfResults::TypeOfRunning::kTaskRun) {
7067
type_test_name = "task_run";
71-
} else if (perf_results.type_of_running == PerfResults::TypeOfRunning::kPipeline) {
68+
} else if (perf_results_.type_of_running == PerfResults::TypeOfRunning::kPipeline) {
7269
type_test_name = "pipeline";
7370
} else {
74-
type_test_name = "none";
71+
std::stringstream err_msg;
72+
err_msg << '\n' << "The type of performance check for the task was not selected.\n";
73+
throw std::runtime_error(err_msg.str().c_str());
7574
}
7675

7776
auto first_found_position = relative_path.find(ppc_regex_template) + ppc_regex_template.length() + 1;
@@ -94,3 +93,5 @@ void ppc::core::Perf::PrintPerfStatistic(const PerfResults& perf_results) {
9493
throw std::runtime_error(err_msg.str().c_str());
9594
}
9695
}
96+
97+
ppc::core::PerfResults ppc::core::Perf::GetPerfResults() { return perf_results_; }

tasks/all/example/perf_tests/main.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class NesterovAllRunTest : public ::testing::TestWithParam<ppc::core::PerfResult
2323

2424
void ExecuteTest(ppc::core::PerfResults::TypeOfRunning mode) {
2525
auto task = std::make_shared<nesterov_a_test_task_all::TestTaskALL>(input_data);
26+
ppc::core::Perf perf(task);
2627

2728
ppc::core::PerfAttr perf_attr;
2829
const auto t0 = std::chrono::high_resolution_clock::now();
@@ -32,19 +33,16 @@ class NesterovAllRunTest : public ::testing::TestWithParam<ppc::core::PerfResult
3233
return static_cast<double>(ns) * 1e-9;
3334
};
3435

35-
ppc::core::PerfResults perf_results;
36-
ppc::core::Perf perf(task);
37-
3836
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
39-
perf.PipelineRun(perf_attr, perf_results);
37+
perf.PipelineRun(perf_attr);
4038
} else {
41-
perf.TaskRun(perf_attr, perf_results);
39+
perf.TaskRun(perf_attr);
4240
}
4341

4442
int rank = -1;
4543
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4644
if (rank == 0) {
47-
ppc::core::Perf::PrintPerfStatistic(perf_results);
45+
perf.PrintPerfStatistic();
4846
}
4947

5048
ASSERT_EQ(input_data, task->Get());

tasks/mpi/example/perf_tests/main.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class NesterovATaskMPITest : public ::testing::TestWithParam<ppc::core::PerfResu
2525
// Create Task
2626
auto test_task_mpi = std::make_shared<nesterov_a_test_task_mpi::TestTaskMPI>(in);
2727

28+
// Create Perf analyzer
29+
ppc::core::Perf perf_analyzer(test_task_mpi);
30+
2831
// Create Perf attributes
2932
ppc::core::PerfAttr perf_attr;
3033
const auto t0 = std::chrono::high_resolution_clock::now();
@@ -34,22 +37,16 @@ class NesterovATaskMPITest : public ::testing::TestWithParam<ppc::core::PerfResu
3437
return static_cast<double>(duration) * 1e-9;
3538
};
3639

37-
// Create and init perf results
38-
ppc::core::PerfResults perf_results;
39-
40-
// Create Perf analyzer
41-
ppc::core::Perf perf_analyzer(test_task_mpi);
42-
4340
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
44-
perf_analyzer.PipelineRun(perf_attr, perf_results);
41+
perf_analyzer.PipelineRun(perf_attr);
4542
} else {
46-
perf_analyzer.TaskRun(perf_attr, perf_results);
43+
perf_analyzer.TaskRun(perf_attr);
4744
}
4845

4946
int rank = -1;
5047
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5148
if (rank == 0) {
52-
ppc::core::Perf::PrintPerfStatistic(perf_results);
49+
perf_analyzer.PrintPerfStatistic();
5350
}
5451

5552
ASSERT_EQ(in, test_task_mpi->Get());

tasks/omp/example/perf_tests/main.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class NesterovTaskOMPTest : public ::testing::TestWithParam<ppc::core::PerfResul
2424
// Create Task
2525
auto test_task_omp = std::make_shared<nesterov_a_test_task_omp::TestTaskOpenMP>(in);
2626

27+
// Create Perf analyzer
28+
ppc::core::Perf perf_analyzer(test_task_omp);
29+
2730
// Create Perf attributes
2831
ppc::core::PerfAttr perf_attr;
2932
const auto t0 = std::chrono::high_resolution_clock::now();
@@ -33,19 +36,13 @@ class NesterovTaskOMPTest : public ::testing::TestWithParam<ppc::core::PerfResul
3336
return static_cast<double>(duration) * 1e-9;
3437
};
3538

36-
// Create and init perf results
37-
ppc::core::PerfResults perf_results;
38-
39-
// Create Perf analyzer
40-
ppc::core::Perf perf_analyzer(test_task_omp);
41-
4239
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
43-
perf_analyzer.PipelineRun(perf_attr, perf_results);
40+
perf_analyzer.PipelineRun(perf_attr);
4441
} else {
45-
perf_analyzer.TaskRun(perf_attr, perf_results);
42+
perf_analyzer.TaskRun(perf_attr);
4643
}
4744

48-
ppc::core::Perf::PrintPerfStatistic(perf_results);
45+
perf_analyzer.PrintPerfStatistic();
4946

5047
ASSERT_EQ(in, test_task_omp->Get());
5148
}

tasks/seq/example/perf_tests/main.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class NesterovTaskSeqTest : public ::testing::TestWithParam<ppc::core::PerfResul
2424
// Create Task
2525
auto test_task_sequential = std::make_shared<nesterov_a_test_task_seq::TestTaskSequential>(in);
2626

27+
// Create Perf analyzer
28+
ppc::core::Perf perf_analyzer(test_task_sequential);
29+
2730
// Create Perf attributes
2831
ppc::core::PerfAttr perf_attr;
2932
const auto t0 = std::chrono::high_resolution_clock::now();
@@ -33,19 +36,13 @@ class NesterovTaskSeqTest : public ::testing::TestWithParam<ppc::core::PerfResul
3336
return static_cast<double>(duration) * 1e-9;
3437
};
3538

36-
// Create and init perf results
37-
ppc::core::PerfResults perf_results;
38-
39-
// Create Perf analyzer
40-
ppc::core::Perf perf_analyzer(test_task_sequential);
41-
4239
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
43-
perf_analyzer.PipelineRun(perf_attr, perf_results);
40+
perf_analyzer.PipelineRun(perf_attr);
4441
} else {
45-
perf_analyzer.TaskRun(perf_attr, perf_results);
42+
perf_analyzer.TaskRun(perf_attr);
4643
}
4744

48-
ppc::core::Perf::PrintPerfStatistic(perf_results);
45+
perf_analyzer.PrintPerfStatistic();
4946

5047
ASSERT_EQ(in, test_task_sequential->Get());
5148
}

0 commit comments

Comments
 (0)