Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/load_library_perf_test.cc

Issue 2001953002: Revert of media: Use platform specific folders for CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
19 18
20 #if defined(ENABLE_PEPPER_CDMS)
21 #include "chrome/browser/media/pepper_cdm_test_helper.h"
22 #include "media/cdm/cdm_paths.h"
23 #endif
24
25 namespace {
26
27 // 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.
28 // |library_relative_dir| is the relative path based on DIR_MODULE. 20 void MeasureSizeAndTimeToLoadNativeLibrary(const base::FilePath& library_name) {
29 void MeasureSizeAndTimeToLoadNativeLibrary(
30 const base::FilePath& library_relative_dir,
31 const base::FilePath& library_name) {
32 base::FilePath output_dir; 21 base::FilePath output_dir;
33 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); 22 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir));
34 output_dir = output_dir.Append(library_relative_dir);
35 base::FilePath library_path = output_dir.Append(library_name); 23 base::FilePath library_path = output_dir.Append(library_name);
36 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); 24 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value();
37 25
38 int64_t size = 0; 26 int64_t size = 0;
39 ASSERT_TRUE(base::GetFileSize(library_path, &size)); 27 ASSERT_TRUE(base::GetFileSize(library_path, &size));
40 perf_test::PrintResult("library_size", 28 perf_test::PrintResult("library_size",
41 "", 29 "",
42 library_name.AsUTF8Unsafe(), 30 library_name.AsUTF8Unsafe(),
43 static_cast<size_t>(size), 31 static_cast<size_t>(size),
44 "bytes", 32 "bytes",
45 true); 33 true);
46 34
47 base::NativeLibraryLoadError error; 35 base::NativeLibraryLoadError error;
48 base::TimeTicks start = base::TimeTicks::Now(); 36 base::TimeTicks start = base::TimeTicks::Now();
49 base::NativeLibrary native_library = 37 base::NativeLibrary native_library =
50 base::LoadNativeLibrary(library_path, &error); 38 base::LoadNativeLibrary(library_path, &error);
51 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); 39 double delta = (base::TimeTicks::Now() - start).InMillisecondsF();
52 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); 40 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString();
53 base::UnloadNativeLibrary(native_library); 41 base::UnloadNativeLibrary(native_library);
54 perf_test::PrintResult("time_to_load_library", 42 perf_test::PrintResult("time_to_load_library",
55 "", 43 "",
56 library_name.AsUTF8Unsafe(), 44 library_name.AsUTF8Unsafe(),
57 delta, 45 delta,
58 "ms", 46 "ms",
59 true); 47 true);
60 } 48 }
61 49
62 #if defined(ENABLE_PEPPER_CDMS) 50 // Use the base name of the library to dynamically get the platform specific
63 51 // name. See base::GetNativeLibraryName() for details.
64 // File name of the ClearKey CDM on different platforms. 52 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName(
65 // TODO(xhwang): Consolidate this with external_clear_key_test_helper.cc. 53 const std::string& base_library_name) {
66 const char kClearKeyCdmFileName[] = 54 MeasureSizeAndTimeToLoadNativeLibrary(base::FilePath::FromUTF16Unsafe(
67 #if defined(OS_MACOSX) 55 base::GetNativeLibraryName(base::ASCIIToUTF16(base_library_name))));
68 "libclearkeycdm.dylib";
69 #elif defined(OS_WIN)
70 "clearkeycdm.dll";
71 #else // OS_LINUX, etc.
72 "libclearkeycdm.so";
73 #endif
74
75 void MeasureSizeAndTimeToLoadCdm(const std::string& cdm_base_dir,
76 const std::string& cdm_name) {
77 MeasureSizeAndTimeToLoadNativeLibrary(
78 media::GetPlatformSpecificDirectory(cdm_base_dir),
79 base::FilePath::FromUTF8Unsafe(cdm_name));
80 } 56 }
81 57
82 #endif // defined(ENABLE_PEPPER_CDMS)
83
84 } // namespace
85
86 #if defined(ENABLE_PEPPER_CDMS) 58 #if defined(ENABLE_PEPPER_CDMS)
87 #if defined(WIDEVINE_CDM_AVAILABLE) 59 #if defined(WIDEVINE_CDM_AVAILABLE)
88 TEST(LoadCDMPerfTest, Widevine) { 60 TEST(LoadCDMPerfTest, Widevine) {
89 MeasureSizeAndTimeToLoadCdm(kWidevineCdmBaseDirectory, kWidevineCdmFileName); 61 MeasureSizeAndTimeToLoadNativeLibrary(
62 base::FilePath::FromUTF8Unsafe(kWidevineCdmFileName));
90 } 63 }
91 64
92 TEST(LoadCDMPerfTest, WidevineAdapter) { 65 TEST(LoadCDMPerfTest, WidevineAdapter) {
93 MeasureSizeAndTimeToLoadCdm(kWidevineCdmBaseDirectory, 66 MeasureSizeAndTimeToLoadNativeLibrary(
94 kWidevineCdmAdapterFileName); 67 base::FilePath::FromUTF8Unsafe(kWidevineCdmAdapterFileName));
95 } 68 }
96 #endif // defined(WIDEVINE_CDM_AVAILABLE) 69 #endif // defined(WIDEVINE_CDM_AVAILABLE)
97 70
98 TEST(LoadCDMPerfTest, ExternalClearKey) { 71 TEST(LoadCDMPerfTest, ExternalClearKey) {
99 MeasureSizeAndTimeToLoadCdm(kClearKeyCdmBaseDirectory, kClearKeyCdmFileName); 72 #if defined(OS_MACOSX)
73 MeasureSizeAndTimeToLoadNativeLibrary(
74 base::FilePath::FromUTF8Unsafe("libclearkeycdm.dylib"));
75 #else
76 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdm");
77 #endif // defined(OS_MACOSX)
100 } 78 }
101 79
102 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { 80 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) {
103 MeasureSizeAndTimeToLoadCdm(kClearKeyCdmBaseDirectory, 81 #if defined(OS_MACOSX)
104 kClearKeyCdmAdapterFileName); 82 MeasureSizeAndTimeToLoadNativeLibrary(
83 base::FilePath::FromUTF8Unsafe("clearkeycdmadapter.plugin"));
84 #else
85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdmadapter");
86 #endif // defined(OS_MACOSX)
105 } 87 }
106 #endif // defined(ENABLE_PEPPER_CDMS) 88 #endif // defined(ENABLE_PEPPER_CDMS)
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_browsertest.cc ('k') | chrome/browser/media/encrypted_media_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698