FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
WebKit/Source/JavaScriptCore/profiler/ProfilerDatabase.cpp at main · WebKit/WebKit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebKit
/
WebKit
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Pull requests
2.6k
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
profiler
/
ProfilerDatabase.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
202 lines (166 loc) · 5.8 KB
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
profiler
/
ProfilerDatabase.cpp
Copy path
File metadata and controls
202 lines (166 loc) · 5.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Copyright (C) 2012-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#
include
"
config.h
"
#
include
"
ProfilerDatabase.h
"
#
include
"
CodeBlock.h
"
#
include
"
JSCInlines.h
"
#
include
"
JSONObject.h
"
#
include
"
ObjectConstructor.h
"
#
include
"
ProfilerDumper.h
"
#
include
<
wtf/FilePrintStream.h
>
#
include
<
wtf/TZoneMallocInlines.h
>
namespace
JSC
{
namespace
Profiler
{
WTF_MAKE_TZONE_ALLOCATED_IMPL
(Database);
static
Lock registrationLock;
static
Database* firstDatabase;
Database::Database
(
VM
& vm)
: m_databaseID(DatabaseID::generate())
, m_vm(vm)
, m_shouldSaveAtExit(
false
)
, m_nextRegisteredDatabase(
nullptr
)
{
}
Database::~Database
()
{
if
(m_shouldSaveAtExit) {
removeDatabaseFromAtExit
();
performAtExitSave
();
}
}
Bytecodes*
Database::ensureBytecodesFor
(CodeBlock* codeBlock)
{
Locker locker { m_lock };
return
ensureBytecodesFor
(locker, codeBlock);
}
Bytecodes*
Database::ensureBytecodesFor
(
const
AbstractLocker&, CodeBlock* codeBlock)
{
codeBlock = codeBlock->
baselineAlternative
();
UncheckedKeyHashMap<CodeBlock*, Bytecodes*>::iterator iter = m_bytecodesMap.
find
(codeBlock);
if
(iter != m_bytecodesMap.
end
())
return
iter->
value
;
m_bytecodes.
append
(
Bytecodes
(m_bytecodes.
size
(), codeBlock));
Bytecodes* result = &m_bytecodes.
last
();
m_bytecodesMap.
add
(codeBlock, result);
return
result;
}
void
Database::notifyDestruction
(CodeBlock* codeBlock)
{
Locker locker { m_lock };
m_bytecodesMap.
remove
(codeBlock);
m_compilationMap.
remove
(codeBlock);
}
void
Database::addCompilation
(CodeBlock* codeBlock, Ref<Compilation>&& compilation)
{
Locker locker { m_lock };
m_compilations.
append
(compilation.
copyRef
());
m_compilationMap.
set
(codeBlock,
WTF::move
(compilation));
}
Ref<
JSON
::Value>
Database::toJSON
()
const
{
Dumper
dumper
(*
this
);
auto
result =
JSON::Object::create
();
auto
bytecodes =
JSON::Array::create
();
for
(
unsigned
i =
0
; i < m_bytecodes.
size
(); ++i)
bytecodes->
pushValue
(m_bytecodes[i].
toJSON
(dumper));
result->
setValue
(dumper.
keys
().
m_bytecodes
,
WTF::move
(bytecodes));
auto
compilations =
JSON::Array::create
();
for
(
unsigned
i =
0
; i < m_compilations.
size
(); ++i)
compilations->
pushValue
(m_compilations[i]->
toJSON
(dumper));
result->
setValue
(dumper.
keys
().
m_compilations
,
WTF::move
(compilations));
auto
events =
JSON::Array::create
();
for
(
unsigned
i =
0
; i < m_events.
size
(); ++i)
events->
pushValue
(m_events[i].
toJSON
(dumper));
result->
setValue
(dumper.
keys
().
m_events
,
WTF::move
(events));
return
result;
}
bool
Database::save
(
const
char
* filename)
const
{
auto
out =
FilePrintStream::open
(filename,
"
w
"
);
if
(!out)
return
false
;
out->
print
(
toJSON
().
get
());
return
true
;
}
void
Database::registerToSaveAtExit
(
const
char
* filename)
{
m_atExitSaveFilename = filename;
if
(m_shouldSaveAtExit)
return
;
addDatabaseToAtExit
();
m_shouldSaveAtExit =
true
;
}
void
Database::logEvent
(CodeBlock* codeBlock,
const
char
* summary,
const
CString& detail)
{
Locker locker { m_lock };
Bytecodes* bytecodes =
ensureBytecodesFor
(locker, codeBlock);
Compilation* compilation = m_compilationMap.
get
(codeBlock);
m_events.
append
(
Event
(
WallTime::now
(), bytecodes, compilation, summary, detail));
}
void
Database::addDatabaseToAtExit
()
{
static
std::once_flag onceKey;
std::call_once
(onceKey, [] {
atexit
(atExitCallback);
});
{
Locker locker { registrationLock };
m_nextRegisteredDatabase = firstDatabase;
firstDatabase =
this
;
}
}
void
Database::removeDatabaseFromAtExit
()
{
Locker locker { registrationLock };
for
(Database** current = &firstDatabase; *current; current = &(*current)->
m_nextRegisteredDatabase
) {
if
(*current !=
this
)
continue
;
*current = m_nextRegisteredDatabase;
m_nextRegisteredDatabase =
nullptr
;
m_shouldSaveAtExit =
false
;
break
;
}
}
void
Database::performAtExitSave
()
const
{
JSLockHolder
lock
(m_vm);
save
(m_atExitSaveFilename.
data
());
}
Database*
Database::removeFirstAtExitDatabase
()
{
Locker locker { registrationLock };
Database* result = firstDatabase;
if
(result) {
firstDatabase = result->
m_nextRegisteredDatabase
;
result->
m_nextRegisteredDatabase
=
nullptr
;
result->
m_shouldSaveAtExit
=
false
;
}
return
result;
}
void
Database::atExitCallback
()
{
while
(Database* database =
removeFirstAtExitDatabase
())
database->
performAtExitSave
();
}
} }
//
namespace JSC::Profiler
Back
|
FazBrowse Home
|
New Git URL