File: tab_footprint_aggregator.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (78 lines) | stat: -rw-r--r-- 3,069 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_METRICS_TAB_FOOTPRINT_AGGREGATOR_H_
#define CHROME_BROWSER_METRICS_TAB_FOOTPRINT_AGGREGATOR_H_

#include <map>
#include <vector>

#include "base/process/process_handle.h"
#include "services/metrics/public/cpp/ukm_source_id.h"

namespace ukm {
class UkmRecorder;
}

// Given information about which render processes are responsible for hosting
// the main- and sub-frames of a page instance, this class produces
// |Memory_TabFootprint| UKM records. |Memory_TabFootprint| records can be used
// to analyze and monitor the effective memory footprints that real world sites
// impose.
class TabFootprintAggregator {
 public:
  TabFootprintAggregator();
  ~TabFootprintAggregator();

  typedef uint64_t PageId;

  // Tracks the process identified by |pid| as the host of the main-frame for
  // the tab identified by |page_id|. |pmf_kb| should be the private memory
  // footprint of the process. |sid| should be the source id of the tab's
  // top-level navigation.
  void AssociateMainFrame(ukm::SourceId sid,
                          base::ProcessId pid,
                          PageId page_id,
                          uint64_t pmf_kb);

  // Tracks the process identified by |pid| as the host of one or more
  // sub-frames for the tab identified by |page_id|. |pmf_kb| should be the
  // private memory footprint of the process. |sid| should be the source id of
  // the tab's top-level navigation.
  void AssociateSubFrame(ukm::SourceId sid,
                         base::ProcessId pid,
                         PageId page_id,
                         uint64_t pmf_kb);

  // Serializes this aggregator's current state as a collection of
  // |Memory_TabFootprint| events which get written to the given recorder.
  void RecordPmfs(ukm::UkmRecorder* ukm_recorder) const;

 private:
  void AssociateFrame(ukm::SourceId sid,
                      base::ProcessId pid,
                      PageId page_id,
                      uint64_t pmf_kb);

 private:
  // For a given tab, this tracks what renderer process hosts the main frame.
  std::map<PageId, base::ProcessId> page_to_main_frame_process_;

  // This tracks the tabs who have a frame hosted by a given process.
  std::map<base::ProcessId, std::vector<PageId>> process_to_pages_;

  // For a given tab, this tracks which processes host some frame in the tab.
  std::map<PageId, std::vector<base::ProcessId>> page_to_processes_;

  // Tracks the pmf (in kilobytes) of a given process.
  std::map<base::ProcessId, uint64_t> process_to_pmf_;

  // Tracks the main frame's |ukm::SourceId| for a given tab. Conceptually,
  // distinct |ukm::SourceId|s correspond to distinct URLs. Note that, although
  // multiple tabs can navigate to the same top-level URL, an individual tab
  // can only be at a single URL at a time.
  std::map<PageId, ukm::SourceId> page_to_source_id_;
};

#endif  // CHROME_BROWSER_METRICS_TAB_FOOTPRINT_AGGREGATOR_H_