1/*
2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if ENABLE(RESOURCE_USAGE)
29
30#include <array>
31#include <wtf/MonotonicTime.h>
32#include <wtf/Vector.h>
33#include <wtf/text/WTFString.h>
34
35namespace WebCore {
36
37// v(name, id, subcategory)
38#define WEBCORE_EACH_MEMORY_CATEGORIES(v) \
39 v(bmalloc, 0, false) \
40 v(LibcMalloc, 1, false) \
41 v(JSJIT, 2, false) \
42 v(WebAssembly, 3, false) \
43 v(Images, 4, false) \
44 v(GCHeap, 5, true) \
45 v(GCOwned, 6, true) \
46 v(Other, 7, false) \
47 v(Layers, 8, false) \
48
49namespace MemoryCategory {
50#define WEBCORE_DEFINE_MEMORY_CATEGORY(name, id, subcategory) static constexpr unsigned name = id;
51WEBCORE_EACH_MEMORY_CATEGORIES(WEBCORE_DEFINE_MEMORY_CATEGORY)
52#undef WEBCORE_DEFINE_MEMORY_CATEGORY
53
54#define WEBCORE_DEFINE_MEMORY_CATEGORY(name, id, subcategory) + 1
55static constexpr unsigned NumberOfCategories = 0 WEBCORE_EACH_MEMORY_CATEGORIES(WEBCORE_DEFINE_MEMORY_CATEGORY);
56#undef WEBCORE_DEFINE_MEMORY_CATEGORY
57}
58
59struct MemoryCategoryInfo {
60 constexpr MemoryCategoryInfo() = default; // Needed for std::array.
61 constexpr MemoryCategoryInfo(unsigned category, bool subcategory = false)
62 : isSubcategory(subcategory)
63 , type(category)
64 {
65 }
66
67 size_t totalSize() const { return dirtySize + externalSize; }
68
69 size_t dirtySize { 0 };
70 size_t reclaimableSize { 0 };
71 size_t externalSize { 0 };
72 bool isSubcategory { false };
73 unsigned type { MemoryCategory::NumberOfCategories };
74};
75
76struct ThreadCPUInfo {
77 enum class Type : uint8_t {
78 Unknown,
79 Main,
80 WebKit,
81 };
82
83 String name;
84 String identifier;
85 float cpu { 0 };
86 Type type { ThreadCPUInfo::Type::Unknown };
87};
88
89struct ResourceUsageData {
90 ResourceUsageData() = default;
91
92 float cpu { 0 };
93 float cpuExcludingDebuggerThreads { 0 };
94 Vector<ThreadCPUInfo> cpuThreads;
95
96 size_t totalDirtySize { 0 };
97 size_t totalExternalSize { 0 };
98 std::array<MemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories { {
99#define WEBCORE_DEFINE_MEMORY_CATEGORY(name, id, subcategory) MemoryCategoryInfo { MemoryCategory::name, subcategory },
100WEBCORE_EACH_MEMORY_CATEGORIES(WEBCORE_DEFINE_MEMORY_CATEGORY)
101#undef WEBCORE_DEFINE_MEMORY_CATEGORY
102 } };
103 MonotonicTime timestamp { MonotonicTime::now() };
104 MonotonicTime timeOfNextEdenCollection { MonotonicTime::nan() };
105 MonotonicTime timeOfNextFullCollection { MonotonicTime::nan() };
106};
107
108} // namespace WebCore
109
110#endif // ResourceUsageData_h
111