blob: 87ef9b876d60cecd2e66d3d43b7aa64d8a5aa852 [file] [log] [blame]
[email protected]3f3325f82014-03-04 20:00:471// 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
avi6846aef2015-12-26 01:09:385#include <stddef.h>
6#include <stdint.h>
7
[email protected]3f3325f82014-03-04 20:00:478#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:049#include "base/files/file_util.h"
thestig02c965b2016-06-14 18:52:2310#include "base/native_library.h"
[email protected]3f3325f82014-03-04 20:00:4711#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"
avi6846aef2015-12-26 01:09:3815#include "build/build_config.h"
Scott Violeta35f9a42018-03-22 22:00:4416#include "media/media_buildflags.h"
[email protected]3f3325f82014-03-04 20:00:4717#include "testing/gtest/include/gtest/gtest.h"
Brian Sheedya2f391242019-09-19 20:23:2718#include "testing/perf/perf_result_reporter.h"
Xiaohan Wangf170c732018-09-27 05:45:2619#include "third_party/widevine/cdm/buildflags.h"
Xiaohan Wange89c7b02018-09-17 18:46:2920#include "third_party/widevine/cdm/widevine_cdm_common.h"
xhwangc3a252b2016-05-23 02:35:4821
Xiaohan Wang3a2df1e2017-07-24 18:34:4422#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc3a252b2016-05-23 02:35:4823#include "media/cdm/cdm_paths.h"
24#endif
25
26namespace {
27
Sylvain Defresned589ae42019-02-05 18:29:3728#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
29
Brian Sheedya2f391242019-09-19 20:23:2730constexpr char kMetricLibrarySizeBytes[] = "library_size";
31constexpr char kMetricTimeToLoadLibraryMs[] = "time_to_load_library";
32
33perf_test::PerfResultReporter SetUpReporter(const std::string& story) {
34 perf_test::PerfResultReporter reporter("", story);
35 reporter.RegisterImportantMetric(kMetricLibrarySizeBytes, "bytes");
36 reporter.RegisterImportantMetric(kMetricTimeToLoadLibraryMs, "ms");
37 return reporter;
38}
39
[email protected]07e54d42014-03-19 06:15:0940// Measures the size (bytes) and time to load (sec) of a native library.
xhwangc3a252b2016-05-23 02:35:4841// |library_relative_dir| is the relative path based on DIR_MODULE.
42void MeasureSizeAndTimeToLoadNativeLibrary(
43 const base::FilePath& library_relative_dir,
44 const base::FilePath& library_name) {
[email protected]3f3325f82014-03-04 20:00:4745 base::FilePath output_dir;
Avi Drissman9098f9002018-05-04 00:11:5246 ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &output_dir));
xhwangc3a252b2016-05-23 02:35:4847 output_dir = output_dir.Append(library_relative_dir);
rockotcdea1d32016-05-15 02:25:3148 base::FilePath library_path = output_dir.Append(library_name);
[email protected]07e54d42014-03-19 06:15:0949 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value();
50
avi6846aef2015-12-26 01:09:3851 int64_t size = 0;
[email protected]07e54d42014-03-19 06:15:0952 ASSERT_TRUE(base::GetFileSize(library_path, &size));
Brian Sheedya2f391242019-09-19 20:23:2753 auto reporter = SetUpReporter(library_name.AsUTF8Unsafe());
54 reporter.AddResult(kMetricLibrarySizeBytes, static_cast<size_t>(size));
[email protected]07e54d42014-03-19 06:15:0955
[email protected]0f998442014-03-25 01:59:0956 base::NativeLibraryLoadError error;
charliea3be839702015-01-26 17:35:4157 base::TimeTicks start = base::TimeTicks::Now();
[email protected]3f3325f82014-03-04 20:00:4758 base::NativeLibrary native_library =
59 base::LoadNativeLibrary(library_path, &error);
charliea3be839702015-01-26 17:35:4160 double delta = (base::TimeTicks::Now() - start).InMillisecondsF();
[email protected]0f998442014-03-25 01:59:0961 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString();
[email protected]3f3325f82014-03-04 20:00:4762 base::UnloadNativeLibrary(native_library);
Brian Sheedya2f391242019-09-19 20:23:2763 reporter.AddResult(kMetricTimeToLoadLibraryMs, delta);
[email protected]3f3325f82014-03-04 20:00:4764}
65
xhwangc3a252b2016-05-23 02:35:4866void 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]3f3325f82014-03-04 20:00:4771}
72
Xiaohan Wang3a2df1e2017-07-24 18:34:4473#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc3a252b2016-05-23 02:35:4874
75} // namespace
76
Xiaohan Wang3a2df1e2017-07-24 18:34:4477#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wangde910d02018-03-13 03:08:2278
Xiaohan Wangf170c732018-09-27 05:45:2679#if BUILDFLAG(ENABLE_WIDEVINE)
[email protected]3f3325f82014-03-04 20:00:4780TEST(LoadCDMPerfTest, Widevine) {
thestig02c965b2016-06-14 18:52:2381 MeasureSizeAndTimeToLoadCdm(
82 kWidevineCdmBaseDirectory,
83 base::GetNativeLibraryName(kWidevineCdmLibraryName));
[email protected]3f3325f82014-03-04 20:00:4784}
Xiaohan Wangf170c732018-09-27 05:45:2685#endif // BUILDFLAG(ENABLE_WIDEVINE)
[email protected]3f3325f82014-03-04 20:00:4786
87TEST(LoadCDMPerfTest, ExternalClearKey) {
thestig02c965b2016-06-14 18:52:2388 MeasureSizeAndTimeToLoadCdm(
Xiaohan Wang17d4ffa2017-06-06 19:10:1189 media::kClearKeyCdmBaseDirectory,
Xiaohan Wangd807ec32018-04-03 01:31:4490 base::GetLoadableModuleName(media::kClearKeyCdmLibraryName));
[email protected]3f3325f82014-03-04 20:00:4791}
92
Xiaohan Wang3a2df1e2017-07-24 18:34:4493#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)