#include "components/performance_manager/resource_attribution/cpu_measurement_monitor.h"
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "base/test/test_waitable_event.h"
#include "base/time/time.h"
#include "components/performance_manager/embedder/graph_features.h"
#include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/graph/process_node_impl.h"
#include "components/performance_manager/graph/worker_node_impl.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/public/resource_attribution/cpu_measurement_delegate.h"
#include "components/performance_manager/public/resource_attribution/cpu_proportion_tracker.h"
#include "components/performance_manager/public/resource_attribution/origin_in_browsing_instance_context.h"
#include "components/performance_manager/public/resource_attribution/query_results.h"
#include "components/performance_manager/public/resource_attribution/resource_contexts.h"
#include "components/performance_manager/resource_attribution/performance_manager_aliases.h"
#include "components/performance_manager/resource_attribution/query_params.h"
#include "components/performance_manager/test_support/graph_test_harness.h"
#include "components/performance_manager/test_support/mock_graphs.h"
#include "components/performance_manager/test_support/performance_manager_test_harness.h"
#include "components/performance_manager/test_support/resource_attribution/gtest_util.h"
#include "components/performance_manager/test_support/resource_attribution/measurement_delegates.h"
#include "components/performance_manager/test_support/run_in_graph.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/process_type.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace resource_attribution {
namespace {
AllOf;
Conditional;
Contains;
Field;
IsEmpty;
Not;
Pair;
kBrowsingInstanceForOtherPage;
kBrowsingInstanceForPage;
TestNodeWrapper;
kResourceAttributionIncludeOrigins;
ProcessCPUUsageError;
constexpr base::TimeDelta kTimeBetweenMeasurements = …;
TestNodeWrapper<WorkerNodeImpl> CreateWorkerNodeWithOrigin(
GraphImpl* graph,
ProcessNodeImpl* process_node,
const url::Origin& origin) { … }
struct MockMultiplePagesAndWorkersWithKnownOriginsGraph
: public performance_manager::MockMultiplePagesWithMultipleProcessesGraph { … };
constexpr internal::QueryId kQueryId = …;
constexpr internal::QueryId kOtherQueryId = …;
}
class ResourceAttrCPUMonitorTest
: public performance_manager::GraphTestHarness { … };
TEST_F(ResourceAttrCPUMonitorTest, CreateTiming) { … }
TEST_F(ResourceAttrCPUMonitorTest, ExitTiming) { … }
TEST_F(ResourceAttrCPUMonitorTest, VaryingMeasurements) { … }
TEST_F(ResourceAttrCPUMonitorTest, AllProcessTypes) { … }
TEST_F(ResourceAttrCPUMonitorTest, CPUDistribution) { … }
TEST_F(ResourceAttrCPUMonitorTest, AddRemoveNodes) { … }
TEST_F(ResourceAttrCPUMonitorTest, AddRemoveWorkerClients) { … }
TEST_F(ResourceAttrCPUMonitorTest, NavigateChangesOrigin) { … }
TEST_F(ResourceAttrCPUMonitorTest, BackgroundCPU) { … }
TEST_F(ResourceAttrCPUMonitorTest, OriginInBrowsingInstanceContextLifetime) { … }
TEST_F(ResourceAttrCPUMonitorTest, MeasurementError) { … }
TEST_F(ResourceAttrCPUMonitorTest, CPUProportionTracker) { … }
namespace {
resource_attribution::CPUTimeResult CreateCPUTimeResult(
base::TimeDelta cumulative_cpu,
base::TimeDelta cumulative_background_cpu) { … }
}
TEST_F(ResourceAttrCPUMonitorTest, CPUProportionTrackerBackground) { … }
TEST_F(ResourceAttrCPUMonitorTest, MultipleCPUProportionTrackers) { … }
class ResourceAttrCPUMonitorTimingTest
: public performance_manager::PerformanceManagerTestHarness { … };
TEST_F(ResourceAttrCPUMonitorTimingTest, ProcessLifetime) { … }
}