// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RESOURCE_ATTRIBUTION_QUERIES_H_ #define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RESOURCE_ATTRIBUTION_QUERIES_H_ #include <memory> #include "base/functional/callback_forward.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_refptr.h" #include "base/observer_list_threadsafe.h" #include "base/scoped_observation.h" #include "base/sequence_checker.h" #include "base/task/sequenced_task_runner.h" #include "base/time/time.h" #include "base/types/pass_key.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/public/resource_attribution/resource_types.h" #include "components/performance_manager/public/resource_attribution/type_helpers.h" namespace resource_attribution { namespace internal { class QueryParams; class QueryScheduler; } class QueryBuilder; // An observer that's notified by ScopedResourceUsageQuery whenever new results // are available. class QueryResultObserver { … }; // Repeatedly makes resource attribution queries on a schedule as long as it's // in scope. class ScopedResourceUsageQuery { … }; // Convenience alias for a ScopedObservation that observes a // ScopedResourceUsageQuery. ScopedQueryObservation; // Creates a query to request resource usage measurements on a schedule. // // Use CreateScopedQuery() to return an object that makes repeated measurements // as long as it's in scope, or QueryOnce() to take a single measurement. Before // calling either of these, the query must specify: // // * At least one resource type to measure, with AddResourceType(). // * At least one resource context to attribute the measurements to, with // AddResourceContext() or AddAllContextsOfType(). // // Example usage: // // // To invoke `callback` with the CPU usage of all processes. // QueryBuilder() // .AddAllContextsOfType<ProcessContext>() // .AddResourceType(ResourceType::kCPUTime) // .QueryOnce(callback); // // QueryBuilder is move-only to prevent accidentally copying large state. Use // Clone() to make an explicit copy. class QueryBuilder { … }; } // namespace resource_attribution #endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RESOURCE_ATTRIBUTION_QUERIES_H_