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

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

Issue 1989893004: 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
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
18 19
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
19 // Measures the size (bytes) and time to load (sec) of a native library. 27 // Measures the size (bytes) and time to load (sec) of a native library.
20 void MeasureSizeAndTimeToLoadNativeLibrary(const base::FilePath& library_name) { 28 void MeasureSizeAndTimeToLoadNativeLibrary(const base::FilePath& library_dir,
ddorwin 2016/05/19 00:04:26 s/dir/relative_path/?
xhwang 2016/05/20 00:22:35 Done.
29 const base::FilePath& library_name) {
21 base::FilePath output_dir; 30 base::FilePath output_dir;
22 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); 31 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir));
32 output_dir = output_dir.Append(library_dir);
23 base::FilePath library_path = output_dir.Append(library_name); 33 base::FilePath library_path = output_dir.Append(library_name);
24 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); 34 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value();
25 35
26 int64_t size = 0; 36 int64_t size = 0;
27 ASSERT_TRUE(base::GetFileSize(library_path, &size)); 37 ASSERT_TRUE(base::GetFileSize(library_path, &size));
28 perf_test::PrintResult("library_size", 38 perf_test::PrintResult("library_size",
29 "", 39 "",
30 library_name.AsUTF8Unsafe(), 40 library_name.AsUTF8Unsafe(),
31 static_cast<size_t>(size), 41 static_cast<size_t>(size),
32 "bytes", 42 "bytes",
33 true); 43 true);
34 44
35 base::NativeLibraryLoadError error; 45 base::NativeLibraryLoadError error;
36 base::TimeTicks start = base::TimeTicks::Now(); 46 base::TimeTicks start = base::TimeTicks::Now();
37 base::NativeLibrary native_library = 47 base::NativeLibrary native_library =
38 base::LoadNativeLibrary(library_path, &error); 48 base::LoadNativeLibrary(library_path, &error);
39 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); 49 double delta = (base::TimeTicks::Now() - start).InMillisecondsF();
40 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); 50 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString();
41 base::UnloadNativeLibrary(native_library); 51 base::UnloadNativeLibrary(native_library);
42 perf_test::PrintResult("time_to_load_library", 52 perf_test::PrintResult("time_to_load_library",
43 "", 53 "",
44 library_name.AsUTF8Unsafe(), 54 library_name.AsUTF8Unsafe(),
45 delta, 55 delta,
46 "ms", 56 "ms",
47 true); 57 true);
48 } 58 }
49 59
50 // Use the base name of the library to dynamically get the platform specific 60 #if defined(ENABLE_PEPPER_CDMS)
51 // name. See base::GetNativeLibraryName() for details. 61
52 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName( 62 // File name of the ClearKey CDM on different platforms.
53 const std::string& base_library_name) { 63 // TODO(xhwang): Consolidate this with external_clear_key_test_helper.cc.
54 MeasureSizeAndTimeToLoadNativeLibrary(base::FilePath::FromUTF16Unsafe( 64 const char kClearKeyCdmFileName[] =
55 base::GetNativeLibraryName(base::ASCIIToUTF16(base_library_name)))); 65 #if defined(OS_MACOSX)
66 "libclearkeycdm.dylib";
67 #elif defined(OS_WIN)
68 "clearkeycdm.dll";
69 #else // OS_LINUX, etc.
70 "libclearkeycdm.so";
71 #endif
72
73 void MeasureSizeAndTimeToLoadCdm(const std::string& cdm_base_dir,
74 const std::string& cdm_name) {
75 MeasureSizeAndTimeToLoadNativeLibrary(
76 media::GetPlatformSpecificDirectory(cdm_base_dir),
77 base::FilePath::FromUTF8Unsafe(cdm_name));
56 } 78 }
57 79
80 #endif // defined(ENABLE_PEPPER_CDMS)
81
82 } // namespace
83
58 #if defined(ENABLE_PEPPER_CDMS) 84 #if defined(ENABLE_PEPPER_CDMS)
59 #if defined(WIDEVINE_CDM_AVAILABLE) 85 #if defined(WIDEVINE_CDM_AVAILABLE)
60 TEST(LoadCDMPerfTest, Widevine) { 86 TEST(LoadCDMPerfTest, Widevine) {
61 MeasureSizeAndTimeToLoadNativeLibrary( 87 MeasureSizeAndTimeToLoadCdm(kWidevineCdmBaseDirectory, kWidevineCdmFileName);
62 base::FilePath::FromUTF8Unsafe(kWidevineCdmFileName));
63 } 88 }
64 89
65 TEST(LoadCDMPerfTest, WidevineAdapter) { 90 TEST(LoadCDMPerfTest, WidevineAdapter) {
66 MeasureSizeAndTimeToLoadNativeLibrary( 91 MeasureSizeAndTimeToLoadCdm(kWidevineCdmBaseDirectory,
67 base::FilePath::FromUTF8Unsafe(kWidevineCdmAdapterFileName)); 92 kWidevineCdmAdapterFileName);
68 } 93 }
69 #endif // defined(WIDEVINE_CDM_AVAILABLE) 94 #endif // defined(WIDEVINE_CDM_AVAILABLE)
70 95
71 TEST(LoadCDMPerfTest, ExternalClearKey) { 96 TEST(LoadCDMPerfTest, ExternalClearKey) {
72 #if defined(OS_MACOSX) 97 MeasureSizeAndTimeToLoadCdm(kClearKeyCdmBaseDirectory, kClearKeyCdmFileName);
73 MeasureSizeAndTimeToLoadNativeLibrary(
74 base::FilePath::FromUTF8Unsafe("libclearkeycdm.dylib"));
75 #else
76 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdm");
77 #endif // defined(OS_MACOSX)
78 } 98 }
79 99
80 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { 100 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) {
81 #if defined(OS_MACOSX) 101 MeasureSizeAndTimeToLoadCdm(kClearKeyCdmBaseDirectory,
82 MeasureSizeAndTimeToLoadNativeLibrary( 102 kClearKeyCdmAdapterFileName);
83 base::FilePath::FromUTF8Unsafe("clearkeycdmadapter.plugin"));
84 #else
85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdmadapter");
86 #endif // defined(OS_MACOSX)
87 } 103 }
88 #endif // defined(ENABLE_PEPPER_CDMS) 104 #endif // defined(ENABLE_PEPPER_CDMS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698