File: DocumentParserTiming.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (115 lines) | stat: -rw-r--r-- 4,685 bytes parent folder | download
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DocumentParserTiming_h
#define DocumentParserTiming_h

#include "core/dom/Document.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "wtf/Noncopyable.h"

namespace blink {

// DocumentParserTiming is responsible for tracking parser-related timings for a
// given document.
class DocumentParserTiming final
    : public GarbageCollectedFinalized<DocumentParserTiming>,
      public Supplement<Document> {
  WTF_MAKE_NONCOPYABLE(DocumentParserTiming);
  USING_GARBAGE_COLLECTED_MIXIN(DocumentParserTiming);

 public:
  virtual ~DocumentParserTiming() {}

  static DocumentParserTiming& from(Document&);

  // markParserStart and markParserStop methods record the time that the
  // parser was first started/stopped, and notify that the document parser
  // timing has changed. These methods do nothing (early return) if a time has
  // already been recorded for the given parser event, or if a parser has
  // already been detached.
  void markParserStart();
  void markParserStop();

  // markParserDetached records that the parser is detached from the
  // document. A single document may have multiple parsers, if e.g. the
  // document is re-opened using document.write. DocumentParserTiming only
  // wants to record parser start and stop time for the first parser. To avoid
  // recording parser start and stop times for re-opened documents, we keep
  // track of whether a parser has been detached, and avoid recording
  // start/stop times for subsequent parsers, after the first parser has been
  // detached.
  void markParserDetached();

  // Record a duration of time that the parser yielded due to loading a
  // script, in seconds. scriptInsertedViaDocumentWrite indicates whether the
  // script causing blocking was inserted via document.write. This may be
  // called multiple times, once for each time the parser yields on a script
  // load.
  void recordParserBlockedOnScriptLoadDuration(
      double duration,
      bool scriptInsertedViaDocumentWrite);

  // Record a duration of time that the parser spent executing a script, in
  // seconds. scriptInsertedViaDocumentWrite indicates whether the script
  // being executed was inserted via document.write. This may be called
  // multiple times, once for each time the parser executes a script.
  void recordParserBlockedOnScriptExecutionDuration(
      double duration,
      bool scriptInsertedViaDocumentWrite);

  // The getters below return monotonically-increasing seconds, or zero if the
  // given parser event has not yet occurred.  See the comments for
  // monotonicallyIncreasingTime in wtf/CurrentTime.h for additional details.

  double parserStart() const { return m_parserStart; }
  double parserStop() const { return m_parserStop; }

  // Returns the sum of all blocking script load durations reported via
  // recordParseBlockedOnScriptLoadDuration.
  double parserBlockedOnScriptLoadDuration() const {
    return m_parserBlockedOnScriptLoadDuration;
  }

  // Returns the sum of all blocking script load durations due to
  // document.write reported via recordParseBlockedOnScriptLoadDuration. Note
  // that some uncommon cases are not currently covered by this method. See
  // crbug/600711 for details.
  double parserBlockedOnScriptLoadFromDocumentWriteDuration() const {
    return m_parserBlockedOnScriptLoadFromDocumentWriteDuration;
  }

  // Returns the sum of all script execution durations reported via
  // recordParseBlockedOnScriptExecutionDuration.
  double parserBlockedOnScriptExecutionDuration() const {
    return m_parserBlockedOnScriptExecutionDuration;
  }

  // Returns the sum of all script execution durations due to
  // document.write reported via recordParseBlockedOnScriptExecutionDuration.
  // Note that some uncommon cases are not currently covered by this method. See
  // crbug/600711 for details.
  double parserBlockedOnScriptExecutionFromDocumentWriteDuration() const {
    return m_parserBlockedOnScriptExecutionFromDocumentWriteDuration;
  }

  DECLARE_VIRTUAL_TRACE();

 private:
  explicit DocumentParserTiming(Document&);
  void notifyDocumentParserTimingChanged();

  double m_parserStart = 0.0;
  double m_parserStop = 0.0;
  double m_parserBlockedOnScriptLoadDuration = 0.0;
  double m_parserBlockedOnScriptLoadFromDocumentWriteDuration = 0.0;
  double m_parserBlockedOnScriptExecutionDuration = 0.0;
  double m_parserBlockedOnScriptExecutionFromDocumentWriteDuration = 0.0;
  bool m_parserDetached = false;
};

}  // namespace blink

#endif