diff options
author | Isabella Gottardi <isabella.gottardi@arm.com> | 2021-04-07 17:15:31 +0100 |
---|---|---|
committer | Alexander Efremov <alexander.efremov@arm.com> | 2021-04-12 14:00:49 +0000 |
commit | 8df12f37531d57a10cba2f8b2e8b6a9065202dd5 (patch) | |
tree | ba833d15649c3b0f885d57b40d3916970b3fd2c8 /tests | |
parent | 37ce22ebc9cf3e8529d9914c0eed0f718243d961 (diff) | |
download | ml-embedded-evaluation-kit-8df12f37531d57a10cba2f8b2e8b6a9065202dd5.tar.gz |
MLECO-1870: Cherry pick profiling changes from dev to open source repo
* Documentation update
Change-Id: If85e7ebc44498840b291c408f14e66a5a5faa424
Signed-off-by: Isabella Gottardi <isabella.gottardi@arm.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common/ProfilerTests.cc | 95 | ||||
-rw-r--r-- | tests/use_case/img_class/ImgClassificationUCTest.cc | 6 | ||||
-rw-r--r-- | tests/use_case/kws/KWSHandlerTest.cc | 5 |
3 files changed, 80 insertions, 26 deletions
diff --git a/tests/common/ProfilerTests.cc b/tests/common/ProfilerTests.cc index caf492b..1435dde 100644 --- a/tests/common/ProfilerTests.cc +++ b/tests/common/ProfilerTests.cc @@ -34,28 +34,73 @@ TEST_CASE("Common: Test Profiler") hal_init(&platform, &data_acq, &data_psn, &timer); hal_platform_init(&platform); - /* An invalid profiler shouldn't be of much use. */ - arm::app::Profiler profilerInvalid {nullptr, "test_invalid"}; - REQUIRE(false == profilerInvalid.StartProfiling()); - REQUIRE(false == profilerInvalid.StopProfiling()); - - arm::app::Profiler profilerValid{&platform, "test_valid"}; - REQUIRE(true == profilerValid.StartProfiling()); - REQUIRE(true == profilerValid.StopProfiling()); - - std::string strProfile = profilerValid.GetResultsAndReset(); - REQUIRE(std::string::npos != strProfile.find("test_valid")); - -#if defined(CPU_PROFILE_ENABLED) - /* We should have milliseconds elapsed. */ - REQUIRE(std::string::npos != strProfile.find("ms")); -#endif /* defined(CPU_PROFILE_ENABLED) */ - - /* Abuse should fail: */ - REQUIRE(false == profilerValid.StopProfiling()); /* We need to start it first. */ - REQUIRE(true == profilerValid.StartProfiling()); /* Should be able to start it fine. */ - REQUIRE(false == profilerValid.StartProfiling()); /* Can't restart it without resetting. */ - profilerValid.Reset(); /* Reset. */ - REQUIRE(true == profilerValid.StartProfiling()); /* Can start it again now. */ - REQUIRE(true == profilerValid.StopProfiling()); /* Can start it again now. */ -} + /* An invalid profiler shouldn't be of much use */ + SECTION("Test invalid profiler") { + arm::app::Profiler profilerInvalid{nullptr, "test_invalid"}; + REQUIRE(false == profilerInvalid.StartProfiling()); + REQUIRE(false == profilerInvalid.StopProfiling()); + } + + SECTION("Test valid profiler") { + arm::app::Profiler profilerValid{&platform, "test_valid"}; + REQUIRE(true == profilerValid.StartProfiling()); + REQUIRE(true == profilerValid.StopProfiling()); + std::vector<arm::app::ProfileResult> results; + profilerValid.GetAllResultsAndReset(results); + REQUIRE(results.size() == 1); + REQUIRE(results[0].name == "test_valid"); + /* Abuse should still fail: */ + REQUIRE(false == profilerValid.StopProfiling()); /* We need to start it first */ + REQUIRE(true == profilerValid.StartProfiling()); /* Should be able to start it fine */ + REQUIRE(false == profilerValid.StartProfiling()); /* Can't restart it without resetting */ + profilerValid.Reset(); + REQUIRE(true == profilerValid.StartProfiling()); /* Can start it again now.. */ + REQUIRE(true == profilerValid.StopProfiling()); + } + + SECTION("Test multiple profilers") { + arm::app::Profiler profilerValid{&platform, "one"}; + REQUIRE(true == profilerValid.StartProfiling()); + REQUIRE(true == profilerValid.StopProfiling()); + + REQUIRE(true == profilerValid.StartProfiling("two")); + REQUIRE(true == profilerValid.StopProfiling()); + REQUIRE(true == profilerValid.StartProfiling("two")); + REQUIRE(true == profilerValid.StopProfiling()); + + std::vector<arm::app::ProfileResult> results; + profilerValid.GetAllResultsAndReset(results); + REQUIRE(results.size() == 2); + REQUIRE(results[0].name == "one"); + REQUIRE(results[0].samplesNum == 1); + REQUIRE(results[1].name == "two"); + REQUIRE(results[1].samplesNum == 2); + } + +#if defined (CPU_PROFILE_ENABLED) + SECTION("Test CPU profiler") { + + arm::app::Profiler profilerCPU{&platform, "test cpu"}; + std::vector<arm::app::ProfileResult> results; + profilerCPU.StartProfiling(); + profilerCPU.StopProfiling(); + profilerCPU.GetAllResultsAndReset(results); + REQUIRE(results.size() == 1); + bool foundTime = false; + bool foundCPU_ACTIVE = false; + for(arm::app::Statistics& stat: results[0].data) { + + if (!foundTime) { + foundTime = stat.name == "Time"; + } + + if (!foundCPU_ACTIVE) { + foundCPU_ACTIVE = stat.name == "CPU ACTIVE"; + } + + } + REQUIRE(foundTime); + REQUIRE(foundCPU_ACTIVE); + } +#endif /* defined (CPU_PROFILE_ENABLED) */ +}
\ No newline at end of file diff --git a/tests/use_case/img_class/ImgClassificationUCTest.cc b/tests/use_case/img_class/ImgClassificationUCTest.cc index abfcc44..b989415 100644 --- a/tests/use_case/img_class/ImgClassificationUCTest.cc +++ b/tests/use_case/img_class/ImgClassificationUCTest.cc @@ -53,7 +53,7 @@ TEST_CASE("Inference by index", "[.]") hal_platform_init(&platform); /* Model wrapper object. */ - arm::app::MobileNetModel model; + arm::app::MobileNetModel model; /* Load the model. */ REQUIRE(model.Init()); @@ -61,6 +61,8 @@ TEST_CASE("Inference by index", "[.]") /* Instantiate application context. */ arm::app::ApplicationContext caseContext; + arm::app::Profiler profiler{&platform, "img_class"}; + caseContext.Set<arm::app::Profiler&>("profiler", profiler); caseContext.Set<hal_platform&>("platform", platform); caseContext.Set<arm::app::Model&>("model", model); caseContext.Set<uint32_t>("imgIndex", 0); @@ -99,6 +101,8 @@ TEST_CASE("Inference run all images", "[.]") /* Instantiate application context. */ arm::app::ApplicationContext caseContext; + arm::app::Profiler profiler{&platform, "img_class"}; + caseContext.Set<arm::app::Profiler&>("profiler", profiler); caseContext.Set<hal_platform&>("platform", platform); caseContext.Set<arm::app::Model&>("model", model); caseContext.Set<uint32_t>("imgIndex", 0); diff --git a/tests/use_case/kws/KWSHandlerTest.cc b/tests/use_case/kws/KWSHandlerTest.cc index dee2f6f..50e5a83 100644 --- a/tests/use_case/kws/KWSHandlerTest.cc +++ b/tests/use_case/kws/KWSHandlerTest.cc @@ -60,6 +60,9 @@ TEST_CASE("Inference by index") /* Instantiate application context. */ arm::app::ApplicationContext caseContext; + + arm::app::Profiler profiler{&platform, "kws"}; + caseContext.Set<arm::app::Profiler&>("profiler", profiler); caseContext.Set<hal_platform&>("platform", platform); caseContext.Set<arm::app::Model&>("model", model); caseContext.Set<int>("frameLength", g_FrameLength); /* 640 sample length for DSCNN. */ @@ -137,6 +140,8 @@ TEST_CASE("Inference run all clips") /* Instantiate application context. */ arm::app::ApplicationContext caseContext; + arm::app::Profiler profiler{&platform, "kws"}; + caseContext.Set<arm::app::Profiler&>("profiler", profiler); caseContext.Set<hal_platform&>("platform", platform); caseContext.Set<arm::app::Model&>("model", model); caseContext.Set<uint32_t>("clipIndex", 0); |