[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 9 | #include "base/files/file_util.h" |
thestig | 02c965b | 2016-06-14 18:52:23 | [diff] [blame] | 10 | #include "base/native_library.h" |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 11 | #include "base/path_service.h" |
| 12 | #include "base/scoped_native_library.h" |
| 13 | #include "base/strings/utf_string_conversions.h" |
| 14 | #include "base/time/time.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 15 | #include "build/build_config.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 16 | #include "media/media_buildflags.h" |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 17 | #include "testing/gtest/include/gtest/gtest.h" |
Brian Sheedy | a2f39124 | 2019-09-19 20:23:27 | [diff] [blame] | 18 | #include "testing/perf/perf_result_reporter.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 19 | #include "third_party/widevine/cdm/buildflags.h" |
Xiaohan Wang | e89c7b0 | 2018-09-17 18:46:29 | [diff] [blame] | 20 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 21 | |
Xiaohan Wang | 3a2df1e | 2017-07-24 18:34:44 | [diff] [blame] | 22 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 23 | #include "media/cdm/cdm_paths.h" |
| 24 | #endif |
| 25 | |
| 26 | namespace { |
| 27 | |
Sylvain Defresne | d589ae4 | 2019-02-05 18:29:37 | [diff] [blame] | 28 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
| 29 | |
Brian Sheedy | a2f39124 | 2019-09-19 20:23:27 | [diff] [blame] | 30 | constexpr char kMetricLibrarySizeBytes[] = "library_size"; |
| 31 | constexpr char kMetricTimeToLoadLibraryMs[] = "time_to_load_library"; |
| 32 | |
| 33 | perf_test::PerfResultReporter SetUpReporter(const std::string& story) { |
| 34 | perf_test::PerfResultReporter reporter("", story); |
| 35 | reporter.RegisterImportantMetric(kMetricLibrarySizeBytes, "bytes"); |
| 36 | reporter.RegisterImportantMetric(kMetricTimeToLoadLibraryMs, "ms"); |
| 37 | return reporter; |
| 38 | } |
| 39 | |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 40 | // Measures the size (bytes) and time to load (sec) of a native library. |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 41 | // |library_relative_dir| is the relative path based on DIR_MODULE. |
| 42 | void MeasureSizeAndTimeToLoadNativeLibrary( |
| 43 | const base::FilePath& library_relative_dir, |
| 44 | const base::FilePath& library_name) { |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 45 | base::FilePath output_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 46 | ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &output_dir)); |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 47 | output_dir = output_dir.Append(library_relative_dir); |
rockot | cdea1d3 | 2016-05-15 02:25:31 | [diff] [blame] | 48 | base::FilePath library_path = output_dir.Append(library_name); |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 49 | ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); |
| 50 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 51 | int64_t size = 0; |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 52 | ASSERT_TRUE(base::GetFileSize(library_path, &size)); |
Brian Sheedy | a2f39124 | 2019-09-19 20:23:27 | [diff] [blame] | 53 | auto reporter = SetUpReporter(library_name.AsUTF8Unsafe()); |
| 54 | reporter.AddResult(kMetricLibrarySizeBytes, static_cast<size_t>(size)); |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 55 | |
[email protected] | 0f99844 | 2014-03-25 01:59:09 | [diff] [blame] | 56 | base::NativeLibraryLoadError error; |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 57 | base::TimeTicks start = base::TimeTicks::Now(); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 58 | base::NativeLibrary native_library = |
| 59 | base::LoadNativeLibrary(library_path, &error); |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 60 | double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); |
[email protected] | 0f99844 | 2014-03-25 01:59:09 | [diff] [blame] | 61 | ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 62 | base::UnloadNativeLibrary(native_library); |
Brian Sheedy | a2f39124 | 2019-09-19 20:23:27 | [diff] [blame] | 63 | reporter.AddResult(kMetricTimeToLoadLibraryMs, delta); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 64 | } |
| 65 | |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 66 | void MeasureSizeAndTimeToLoadCdm(const std::string& cdm_base_dir, |
| 67 | const std::string& cdm_name) { |
| 68 | MeasureSizeAndTimeToLoadNativeLibrary( |
| 69 | media::GetPlatformSpecificDirectory(cdm_base_dir), |
| 70 | base::FilePath::FromUTF8Unsafe(cdm_name)); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 71 | } |
| 72 | |
Xiaohan Wang | 3a2df1e | 2017-07-24 18:34:44 | [diff] [blame] | 73 | #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 74 | |
| 75 | } // namespace |
| 76 | |
Xiaohan Wang | 3a2df1e | 2017-07-24 18:34:44 | [diff] [blame] | 77 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
Xiaohan Wang | de910d0 | 2018-03-13 03:08:22 | [diff] [blame] | 78 | |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 79 | #if BUILDFLAG(ENABLE_WIDEVINE) |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 80 | TEST(LoadCDMPerfTest, Widevine) { |
thestig | 02c965b | 2016-06-14 18:52:23 | [diff] [blame] | 81 | MeasureSizeAndTimeToLoadCdm( |
| 82 | kWidevineCdmBaseDirectory, |
| 83 | base::GetNativeLibraryName(kWidevineCdmLibraryName)); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 84 | } |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 85 | #endif // BUILDFLAG(ENABLE_WIDEVINE) |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 86 | |
| 87 | TEST(LoadCDMPerfTest, ExternalClearKey) { |
thestig | 02c965b | 2016-06-14 18:52:23 | [diff] [blame] | 88 | MeasureSizeAndTimeToLoadCdm( |
Xiaohan Wang | 17d4ffa | 2017-06-06 19:10:11 | [diff] [blame] | 89 | media::kClearKeyCdmBaseDirectory, |
Xiaohan Wang | d807ec3 | 2018-04-03 01:31:44 | [diff] [blame] | 90 | base::GetLoadableModuleName(media::kClearKeyCdmLibraryName)); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 91 | } |
| 92 | |
Xiaohan Wang | 3a2df1e | 2017-07-24 18:34:44 | [diff] [blame] | 93 | #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) |