/src/mozilla-central/layout/base/AutoProfilerStyleMarker.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_AutoProfilerStyleMarker_h |
8 | | #define mozilla_AutoProfilerStyleMarker_h |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "mozilla/ServoTraversalStatistics.h" |
12 | | #include "mozilla/TimeStamp.h" |
13 | | #include "GeckoProfiler.h" |
14 | | #include "ProfilerMarkerPayload.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | class MOZ_RAII AutoProfilerStyleMarker |
19 | | { |
20 | | public: |
21 | | explicit AutoProfilerStyleMarker(UniqueProfilerBacktrace aCause) |
22 | | : mActive(profiler_is_active()) |
23 | | , mStartTime(TimeStamp::Now()) |
24 | | , mCause(std::move(aCause)) |
25 | 0 | { |
26 | 0 | if (!mActive) { |
27 | 0 | return; |
28 | 0 | } |
29 | 0 | MOZ_ASSERT(!ServoTraversalStatistics::sActive, |
30 | 0 | "Nested AutoProfilerStyleMarker"); |
31 | 0 | ServoTraversalStatistics::sSingleton = ServoTraversalStatistics(); |
32 | 0 | ServoTraversalStatistics::sActive = true; |
33 | 0 | } |
34 | | |
35 | | ~AutoProfilerStyleMarker() |
36 | 0 | { |
37 | 0 | if (!mActive) { |
38 | 0 | return; |
39 | 0 | } |
40 | 0 | ServoTraversalStatistics::sActive = false; |
41 | 0 | profiler_add_marker("Styles", MakeUnique<StyleMarkerPayload>( |
42 | 0 | mStartTime, TimeStamp::Now(), std::move(mCause), |
43 | 0 | ServoTraversalStatistics::sSingleton)); |
44 | 0 | } |
45 | | |
46 | | private: |
47 | | bool mActive; |
48 | | TimeStamp mStartTime; |
49 | | UniqueProfilerBacktrace mCause; |
50 | | }; |
51 | | |
52 | | } // namespace mozilla |
53 | | |
54 | | #endif // mozilla_AutoProfilerStyleMarker_h |