OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/scoped_native_library.h" | 11 #include "base/scoped_native_library.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/perf/perf_test.h" | 16 #include "testing/perf/perf_test.h" |
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
18 | 18 |
| 19 // Base path for Clear Key CDM (relative to the chrome executable). |
| 20 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm"; |
| 21 |
19 // Measures the size (bytes) and time to load (sec) of a native library. | 22 // Measures the size (bytes) and time to load (sec) of a native library. |
20 void MeasureSizeAndTimeToLoadNativeLibrary(const base::FilePath& library_name) { | 23 void MeasureSizeAndTimeToLoadNativeLibrary(const std::string& library_base_dir, |
| 24 const std::string& library_name) { |
21 base::FilePath output_dir; | 25 base::FilePath output_dir; |
22 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); | 26 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); |
23 base::FilePath library_path = output_dir.Append(library_name); | 27 output_dir = output_dir.AppendASCII(library_base_dir); |
| 28 base::FilePath library_path = output_dir.AppendASCII(library_name); |
24 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); | 29 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); |
25 | 30 |
26 int64_t size = 0; | 31 int64_t size = 0; |
27 ASSERT_TRUE(base::GetFileSize(library_path, &size)); | 32 ASSERT_TRUE(base::GetFileSize(library_path, &size)); |
28 perf_test::PrintResult("library_size", | 33 perf_test::PrintResult("library_size", "", library_name, |
29 "", | 34 static_cast<size_t>(size), "bytes", true); |
30 library_name.AsUTF8Unsafe(), | |
31 static_cast<size_t>(size), | |
32 "bytes", | |
33 true); | |
34 | 35 |
35 base::NativeLibraryLoadError error; | 36 base::NativeLibraryLoadError error; |
36 base::TimeTicks start = base::TimeTicks::Now(); | 37 base::TimeTicks start = base::TimeTicks::Now(); |
37 base::NativeLibrary native_library = | 38 base::NativeLibrary native_library = |
38 base::LoadNativeLibrary(library_path, &error); | 39 base::LoadNativeLibrary(library_path, &error); |
39 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); | 40 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); |
40 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); | 41 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); |
41 base::UnloadNativeLibrary(native_library); | 42 base::UnloadNativeLibrary(native_library); |
42 perf_test::PrintResult("time_to_load_library", | 43 perf_test::PrintResult("time_to_load_library", "", library_name, delta, "ms", |
43 "", | |
44 library_name.AsUTF8Unsafe(), | |
45 delta, | |
46 "ms", | |
47 true); | 44 true); |
48 } | 45 } |
49 | 46 |
50 // Use the base name of the library to dynamically get the platform specific | 47 // Use the base name of the library to dynamically get the platform specific |
51 // name. See base::GetNativeLibraryName() for details. | 48 // name. See base::GetNativeLibraryName() for details. |
52 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName( | 49 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName( |
| 50 const std::string& library_base_dir, |
53 const std::string& base_library_name) { | 51 const std::string& base_library_name) { |
54 MeasureSizeAndTimeToLoadNativeLibrary(base::FilePath::FromUTF16Unsafe( | 52 MeasureSizeAndTimeToLoadNativeLibrary( |
55 base::GetNativeLibraryName(base::ASCIIToUTF16(base_library_name)))); | 53 library_base_dir, base::UTF16ToUTF8(base::GetNativeLibraryName( |
| 54 base::ASCIIToUTF16(base_library_name)))); |
56 } | 55 } |
57 | 56 |
58 #if defined(ENABLE_PEPPER_CDMS) | 57 #if defined(ENABLE_PEPPER_CDMS) |
59 #if defined(WIDEVINE_CDM_AVAILABLE) | 58 #if defined(WIDEVINE_CDM_AVAILABLE) |
60 TEST(LoadCDMPerfTest, Widevine) { | 59 TEST(LoadCDMPerfTest, Widevine) { |
61 MeasureSizeAndTimeToLoadNativeLibrary( | 60 MeasureSizeAndTimeToLoadNativeLibrary(kWidevineCdmBaseDirectory, |
62 base::FilePath::FromUTF8Unsafe(kWidevineCdmFileName)); | 61 kWidevineCdmFileName); |
63 } | 62 } |
64 | 63 |
65 TEST(LoadCDMPerfTest, WidevineAdapter) { | 64 TEST(LoadCDMPerfTest, WidevineAdapter) { |
66 MeasureSizeAndTimeToLoadNativeLibrary( | 65 MeasureSizeAndTimeToLoadNativeLibrary(kWidevineCdmBaseDirectory, |
67 base::FilePath::FromUTF8Unsafe(kWidevineCdmAdapterFileName)); | 66 kWidevineCdmAdapterFileName); |
68 } | 67 } |
69 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 68 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
70 | 69 |
71 TEST(LoadCDMPerfTest, ExternalClearKey) { | 70 TEST(LoadCDMPerfTest, ExternalClearKey) { |
72 #if defined(OS_MACOSX) | 71 #if defined(OS_MACOSX) |
73 MeasureSizeAndTimeToLoadNativeLibrary( | 72 MeasureSizeAndTimeToLoadNativeLibrary(kClearKeyCdmBaseDirectory, |
74 base::FilePath::FromUTF8Unsafe("libclearkeycdm.dylib")); | 73 "libclearkeycdm.dylib"); |
75 #else | 74 #else |
76 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdm"); | 75 MeasureSizeAndTimeToLoadNativeLibraryByBaseName(kClearKeyCdmBaseDirectory, |
| 76 "clearkeycdm"); |
77 #endif // defined(OS_MACOSX) | 77 #endif // defined(OS_MACOSX) |
78 } | 78 } |
79 | 79 |
80 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { | 80 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { |
81 #if defined(OS_MACOSX) | 81 #if defined(OS_MACOSX) |
82 MeasureSizeAndTimeToLoadNativeLibrary( | 82 MeasureSizeAndTimeToLoadNativeLibrary(kClearKeyCdmBaseDirectory, |
83 base::FilePath::FromUTF8Unsafe("clearkeycdmadapter.plugin")); | 83 "clearkeycdmadapter.plugin"); |
84 #else | 84 #else |
85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdmadapter"); | 85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName(kClearKeyCdmBaseDirectory, |
| 86 "clearkeycdmadapter"); |
86 #endif // defined(OS_MACOSX) | 87 #endif // defined(OS_MACOSX) |
87 } | 88 } |
88 #endif // defined(ENABLE_PEPPER_CDMS) | 89 #endif // defined(ENABLE_PEPPER_CDMS) |
OLD | NEW |