mirror of
https://fuchsia.googlesource.com/third_party/pigweed.googlesource.com/pigweed/pigweed
synced 2024-09-19 21:29:48 +00:00
e596056be5
This CL moves `internal::Framework`, `internal::TestInfo`, and `State` out of pw_perf_test.h and into their own separate files. It also moves performance_test_generic.cc to examples/example_perf_test.cc. Finally, it removes perf_test_test.cc as this file created a no-op unit test. Change-Id: Id5e984cdf80bb7ed801be1f81ebb8cba8c05b91b Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/178914 Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Aaron Green <aarongreen@google.com>
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
// Copyright 2023 The Pigweed Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
// use this file except in compliance with the License. You may obtain a copy of
|
|
// the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
// License for the specific language governing permissions and limitations under
|
|
// the License.
|
|
|
|
#include "pw_perf_test/state.h"
|
|
|
|
#include "pw_log/log.h"
|
|
|
|
namespace pw::perf_test {
|
|
namespace internal {
|
|
|
|
State CreateState(int durations,
|
|
EventHandler& event_handler,
|
|
const char* test_name) {
|
|
return State(durations, event_handler, test_name);
|
|
}
|
|
} // namespace internal
|
|
|
|
bool State::KeepRunning() {
|
|
internal::Timestamp iteration_end = internal::GetCurrentTimestamp();
|
|
if (current_iteration_ == -1) {
|
|
++current_iteration_;
|
|
event_handler_->TestCaseStart(test_info);
|
|
iteration_start_ = internal::GetCurrentTimestamp();
|
|
return true;
|
|
}
|
|
int64_t duration = internal::GetDuration(iteration_start_, iteration_end);
|
|
if (duration > max_) {
|
|
max_ = duration;
|
|
}
|
|
if (duration < min_) {
|
|
min_ = duration;
|
|
}
|
|
total_duration_ += duration;
|
|
++current_iteration_;
|
|
PW_LOG_DEBUG("Iteration number: %d - Duration: %ld",
|
|
current_iteration_,
|
|
static_cast<long>(duration));
|
|
event_handler_->TestCaseIteration({current_iteration_, duration});
|
|
if (current_iteration_ == test_iterations_) {
|
|
PW_LOG_DEBUG("Total Duration: %ld Total Iterations: %d",
|
|
static_cast<long>(total_duration_),
|
|
test_iterations_);
|
|
mean_ = total_duration_ / test_iterations_;
|
|
PW_LOG_DEBUG("Mean: %ld: ", static_cast<long>(mean_));
|
|
PW_LOG_DEBUG("Minimum: %ld", static_cast<long>(min_));
|
|
PW_LOG_DEBUG("Maxmimum: %ld", static_cast<long>(max_));
|
|
event_handler_->TestCaseEnd(test_info,
|
|
Results{mean_, max_, min_, test_iterations_});
|
|
return false;
|
|
}
|
|
iteration_start_ = internal::GetCurrentTimestamp();
|
|
return true;
|
|
}
|
|
|
|
} // namespace pw::perf_test
|