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 | |
22 // Measures the size (bytes) and time to load (sec) of a native library. | 19 // Measures the size (bytes) and time to load (sec) of a native library. |
23 void MeasureSizeAndTimeToLoadNativeLibrary(const std::string& library_base_dir, | 20 void MeasureSizeAndTimeToLoadNativeLibrary(const base::FilePath& library_name) { |
24 const std::string& library_name) { | |
25 base::FilePath output_dir; | 21 base::FilePath output_dir; |
26 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); | 22 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); |
27 output_dir = output_dir.AppendASCII(library_base_dir); | 23 base::FilePath library_path = output_dir.Append(library_name); |
28 base::FilePath library_path = output_dir.AppendASCII(library_name); | |
29 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); | 24 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); |
30 | 25 |
31 int64_t size = 0; | 26 int64_t size = 0; |
32 ASSERT_TRUE(base::GetFileSize(library_path, &size)); | 27 ASSERT_TRUE(base::GetFileSize(library_path, &size)); |
33 perf_test::PrintResult("library_size", "", library_name, | 28 perf_test::PrintResult("library_size", |
34 static_cast<size_t>(size), "bytes", true); | 29 "", |
| 30 library_name.AsUTF8Unsafe(), |
| 31 static_cast<size_t>(size), |
| 32 "bytes", |
| 33 true); |
35 | 34 |
36 base::NativeLibraryLoadError error; | 35 base::NativeLibraryLoadError error; |
37 base::TimeTicks start = base::TimeTicks::Now(); | 36 base::TimeTicks start = base::TimeTicks::Now(); |
38 base::NativeLibrary native_library = | 37 base::NativeLibrary native_library = |
39 base::LoadNativeLibrary(library_path, &error); | 38 base::LoadNativeLibrary(library_path, &error); |
40 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); | 39 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); |
41 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); | 40 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); |
42 base::UnloadNativeLibrary(native_library); | 41 base::UnloadNativeLibrary(native_library); |
43 perf_test::PrintResult("time_to_load_library", "", library_name, delta, "ms", | 42 perf_test::PrintResult("time_to_load_library", |
| 43 "", |
| 44 library_name.AsUTF8Unsafe(), |
| 45 delta, |
| 46 "ms", |
44 true); | 47 true); |
45 } | 48 } |
46 | 49 |
47 // Use the base name of the library to dynamically get the platform specific | 50 // Use the base name of the library to dynamically get the platform specific |
48 // name. See base::GetNativeLibraryName() for details. | 51 // name. See base::GetNativeLibraryName() for details. |
49 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName( | 52 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName( |
50 const std::string& library_base_dir, | |
51 const std::string& base_library_name) { | 53 const std::string& base_library_name) { |
52 MeasureSizeAndTimeToLoadNativeLibrary( | 54 MeasureSizeAndTimeToLoadNativeLibrary(base::FilePath::FromUTF16Unsafe( |
53 library_base_dir, base::UTF16ToUTF8(base::GetNativeLibraryName( | 55 base::GetNativeLibraryName(base::ASCIIToUTF16(base_library_name)))); |
54 base::ASCIIToUTF16(base_library_name)))); | |
55 } | 56 } |
56 | 57 |
57 #if defined(ENABLE_PEPPER_CDMS) | 58 #if defined(ENABLE_PEPPER_CDMS) |
58 #if defined(WIDEVINE_CDM_AVAILABLE) | 59 #if defined(WIDEVINE_CDM_AVAILABLE) |
59 TEST(LoadCDMPerfTest, Widevine) { | 60 TEST(LoadCDMPerfTest, Widevine) { |
60 MeasureSizeAndTimeToLoadNativeLibrary(kWidevineCdmBaseDirectory, | 61 MeasureSizeAndTimeToLoadNativeLibrary( |
61 kWidevineCdmFileName); | 62 base::FilePath::FromUTF8Unsafe(kWidevineCdmFileName)); |
62 } | 63 } |
63 | 64 |
64 TEST(LoadCDMPerfTest, WidevineAdapter) { | 65 TEST(LoadCDMPerfTest, WidevineAdapter) { |
65 MeasureSizeAndTimeToLoadNativeLibrary(kWidevineCdmBaseDirectory, | 66 MeasureSizeAndTimeToLoadNativeLibrary( |
66 kWidevineCdmAdapterFileName); | 67 base::FilePath::FromUTF8Unsafe(kWidevineCdmAdapterFileName)); |
67 } | 68 } |
68 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 69 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
69 | 70 |
70 TEST(LoadCDMPerfTest, ExternalClearKey) { | 71 TEST(LoadCDMPerfTest, ExternalClearKey) { |
71 #if defined(OS_MACOSX) | 72 #if defined(OS_MACOSX) |
72 MeasureSizeAndTimeToLoadNativeLibrary(kClearKeyCdmBaseDirectory, | 73 MeasureSizeAndTimeToLoadNativeLibrary( |
73 "libclearkeycdm.dylib"); | 74 base::FilePath::FromUTF8Unsafe("libclearkeycdm.dylib")); |
74 #else | 75 #else |
75 MeasureSizeAndTimeToLoadNativeLibraryByBaseName(kClearKeyCdmBaseDirectory, | 76 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdm"); |
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(kClearKeyCdmBaseDirectory, | 82 MeasureSizeAndTimeToLoadNativeLibrary( |
83 "clearkeycdmadapter.plugin"); | 83 base::FilePath::FromUTF8Unsafe("clearkeycdmadapter.plugin")); |
84 #else | 84 #else |
85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName(kClearKeyCdmBaseDirectory, | 85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdmadapter"); |
86 "clearkeycdmadapter"); | |
87 #endif // defined(OS_MACOSX) | 86 #endif // defined(OS_MACOSX) |
88 } | 87 } |
89 #endif // defined(ENABLE_PEPPER_CDMS) | 88 #endif // defined(ENABLE_PEPPER_CDMS) |
OLD | NEW |