1 // Copyright 2020 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 
5 #ifndef SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_INSTRUMENTATION_TRACING_OBSERVER_TRACED_VALUE_H_
6 #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_INSTRUMENTATION_TRACING_OBSERVER_TRACED_VALUE_H_
7 
8 #include "base/component_export.h"
9 #include "base/macros.h"
10 #include "base/trace_event/memory_dump_manager.h"
11 #include "base/trace_event/trace_event.h"
12 #include "services/resource_coordinator/public/cpp/memory_instrumentation/tracing_observer.h"
13 #include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
14 
15 namespace memory_instrumentation {
16 
17 // Version of TracingObserver that serialized the dump into a TracedValue
COMPONENT_EXPORT(RESOURCE_COORDINATOR_PUBLIC_MEMORY_INSTRUMENTATION)18 class COMPONENT_EXPORT(RESOURCE_COORDINATOR_PUBLIC_MEMORY_INSTRUMENTATION)
19     TracingObserverTracedValue : public TracingObserver {
20  public:
21   TracingObserverTracedValue(base::trace_event::TraceLog*,
22                              base::trace_event::MemoryDumpManager*);
23   ~TracingObserverTracedValue() override;
24 
25   bool AddChromeDumpToTraceIfEnabled(
26       const base::trace_event::MemoryDumpRequestArgs&,
27       const base::ProcessId pid,
28       const base::trace_event::ProcessMemoryDump*,
29       const base::TimeTicks& timestamp) override;
30   bool AddOsDumpToTraceIfEnabled(
31       const base::trace_event::MemoryDumpRequestArgs&,
32       const base::ProcessId,
33       const mojom::OSMemDump&,
34       const std::vector<mojom::VmRegionPtr>&,
35       const base::TimeTicks& timastamp) override;
36 
37   static void MemoryMapsAsValueInto(
38       const std::vector<mojom::VmRegionPtr>& memory_maps,
39       base::trace_event::TracedValue* value,
40       bool is_argument_filtering_enabled);
41 
42   static void AddToTrace(const base::trace_event::MemoryDumpRequestArgs&,
43                          const base::ProcessId,
44                          std::unique_ptr<base::trace_event::TracedValue>);
45 
46   DISALLOW_COPY_AND_ASSIGN(TracingObserverTracedValue);
47 };
48 
49 }  // namespace memory_instrumentation
50 
51 #endif  // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_INSTRUMENTATION_TRACING_OBSERVER_TRACED_VALUE_H_
52