[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" |
| 18 | #include "testing/perf/perf_test.h" |
Xiaohan Wang | e89c7b0 | 2018-09-17 18:46:29 | [diff] [blame^] | 19 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 20 | |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 21 | #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 22 | |
Xiaohan Wang | 3a2df1e | 2017-07-24 18:34:44 | [diff] [blame] | 23 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 24 | #include "media/cdm/cdm_paths.h" |
| 25 | #endif |
| 26 | |
| 27 | namespace { |
| 28 | |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 29 | // Measures the size (bytes) and time to load (sec) of a native library. |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 30 | // |library_relative_dir| is the relative path based on DIR_MODULE. |
| 31 | void MeasureSizeAndTimeToLoadNativeLibrary( |
| 32 | const base::FilePath& library_relative_dir, |
| 33 | const base::FilePath& library_name) { |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 34 | base::FilePath output_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 35 | ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &output_dir)); |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 36 | output_dir = output_dir.Append(library_relative_dir); |
rockot | cdea1d3 | 2016-05-15 02:25:31 | [diff] [blame] | 37 | base::FilePath library_path = output_dir.Append(library_name); |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 38 | ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); |
| 39 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 40 | int64_t size = 0; |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 41 | ASSERT_TRUE(base::GetFileSize(library_path, &size)); |
rockot | cdea1d3 | 2016-05-15 02:25:31 | [diff] [blame] | 42 | perf_test::PrintResult("library_size", |
| 43 | "", |
| 44 | library_name.AsUTF8Unsafe(), |
| 45 | static_cast<size_t>(size), |
| 46 | "bytes", |
| 47 | true); |
[email protected] | 07e54d4 | 2014-03-19 06:15:09 | [diff] [blame] | 48 | |
[email protected] | 0f99844 | 2014-03-25 01:59:09 | [diff] [blame] | 49 | base::NativeLibraryLoadError error; |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 50 | base::TimeTicks start = base::TimeTicks::Now(); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 51 | base::NativeLibrary native_library = |
| 52 | base::LoadNativeLibrary(library_path, &error); |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 53 | double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); |
[email protected] | 0f99844 | 2014-03-25 01:59:09 | [diff] [blame] | 54 | ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 55 | base::UnloadNativeLibrary(native_library); |
rockot | cdea1d3 | 2016-05-15 02:25:31 | [diff] [blame] | 56 | perf_test::PrintResult("time_to_load_library", |
| 57 | "", |
| 58 | library_name.AsUTF8Unsafe(), |
| 59 | delta, |
| 60 | "ms", |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 61 | true); |
| 62 | } |
| 63 | |
Xiaohan Wang | 3a2df1e | 2017-07-24 18:34:44 | [diff] [blame] | 64 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c3a252b | 2016-05-23 02:35:48 | [diff] [blame] | 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 | |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 79 | #if defined(WIDEVINE_CDM_AVAILABLE) |
| 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 | } |
[email protected] | 3f3325f8 | 2014-03-04 20:00:47 | [diff] [blame] | 85 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 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) |