65 ETWTRACEDBG <<
"UpdateAllIsolates with etw_enabled==" << etw_enabled
66 <<
" and options==" << options <<
" acquiring mutex" << std::endl;
70 auto monitor = std::make_shared<EtwIsolateCaptureStateMonitor>(
74 std::weak_ptr<EtwIsolateCaptureStateMonitor> weak_monitor = monitor;
77 [etw_enabled, weak_monitor, options](
auto& pair) {
78 auto& isolate_data = pair.second;
80 ETWTRACEDBG <<
"UpdateAllIsolates enqueing enablelog" << std::endl;
81 isolate_data.EnqueueEnableLog(weak_monitor, options);
83 ETWTRACEDBG <<
"UpdateAllIsolates enqueing disablelog" << std::endl;
84 isolate_data.EnqueueDisableLog();
92 ETWTRACEDBG <<
"UpdateAllIsolates starting WaitFor" << std::endl;
95 << (timeout ?
"timeout" :
"completed") << std::endl;
111void IsolateLoadScriptData::EnableLog(
112 Isolate* isolate,
size_t event_id,
113 std::weak_ptr<EtwIsolateCaptureStateMonitor> weak_monitor,
116 ETWTRACEDBG <<
"EnableLog called with event_id==" << event_id
117 <<
" and options==" << options <<
" taking mutex" << std::endl;
119 auto& data = GetData(isolate);
120 if (event_id > 0 && data.CurrentEventId() != event_id) {
127 data.RemoveAllLoadedScripts();
131 ETWTRACEDBG <<
"Mutex released with event_id==" << event_id << std::endl;
135 EtwIsolateOperations::Instance()->SetEtwCodeEventHandler(isolate, options);
136 isolate->SetETWTracingEnabled(
true);
139 if (
auto monitor = weak_monitor.lock()) {
140 ETWTRACEDBG <<
"monitor->Notify with event_id==" << event_id << std::endl;
146void IsolateLoadScriptData::EnableLogWithFilterDataOnAllIsolates(
147 const uint8_t* data,
size_t size, uint32_t options) {
150 std::string etw_filter_payload;
151 etw_filter_payload.assign(data, data + size);
152 auto monitor = std::make_shared<EtwIsolateCaptureStateMonitor>(
156 std::weak_ptr<EtwIsolateCaptureStateMonitor> weak_monitor = monitor;
158 [&etw_filter_payload, weak_monitor, options](
auto& pair) {
159 auto& isolate_data = pair.second;
160 isolate_data.EnqueueEnableLogWithFilterData(
161 etw_filter_payload, weak_monitor, options);
164 if (!capture_state) {
169 ETWTRACEDBG <<
"EnableLogWithFilterDataOnAllIsolates WaitFor "
170 << (timeout ?
"timeout" :
"completed") << std::endl;
174void IsolateLoadScriptData::DisableLog(
Isolate* isolate,
size_t event_id) {
177 auto& data = GetData(isolate);
178 if (event_id > 0 && data.CurrentEventId() != event_id) {
182 data.RemoveAllLoadedScripts();
184 EtwIsolateOperations::Instance()->ResetEtwCodeEventHandler(isolate);
185 isolate->SetETWTracingEnabled(
false);
189void IsolateLoadScriptData::EnableLogWithFilterData(
190 Isolate* isolate,
size_t event_id,
const std::string& etw_filter_payload,
191 std::weak_ptr<EtwIsolateCaptureStateMonitor> weak_monitor,
193 bool filter_did_match =
false;
194 DCHECK(!etw_filter_payload.empty());
197 ETWTRACEDBG <<
"EnableLogWithFilterData called with event_id==" << event_id
198 <<
" and options==" << options <<
" taking mutex" << std::endl;
201 auto& data = GetData(isolate);
202 if (event_id > 0 && data.CurrentEventId() != event_id) {
207 FilterETWSessionByURLResult filter_etw_session_by_url_result =
208 EtwIsolateOperations::Instance()->RunFilterETWSessionByURLCallback(
209 isolate, etw_filter_payload);
210 filter_did_match = filter_etw_session_by_url_result.enable_etw_tracing;
211 if (filter_did_match) {
212 if (filter_etw_session_by_url_result.trace_interpreter_frames) {
213 isolate->set_etw_trace_interpreted_frames();
218 data.RemoveAllLoadedScripts();
223 if (filter_did_match) {
224 ETWTRACEDBG <<
"Filter was matched with event_id==" << event_id
226 EtwIsolateOperations::Instance()->SetEtwCodeEventHandler(isolate, options);
227 isolate->SetETWTracingEnabled(
true);
231 if (
auto monitor = weak_monitor.lock()) {
232 ETWTRACEDBG <<
"monitor->Notify with event_id==" << event_id << std::endl;
242void IsolateLoadScriptData::EnqueueEnableLog(
243 std::weak_ptr<EtwIsolateCaptureStateMonitor> weak_monitor,
245 size_t event_id = event_id_.fetch_add(1);
246 EtwIsolateOperations::Instance()->RequestInterrupt(
250 std::unique_ptr<EnableInterruptData> interrupt_data(
252 size_t event_id = interrupt_data->event_id;
253 auto weak_monitor = interrupt_data->weak_monitor;
254 uint32_t options = interrupt_data->options;
255 EnableLog(
reinterpret_cast<Isolate*
>(v8_isolate), event_id,
256 weak_monitor, options);
273void IsolateLoadScriptData::EnqueueEnableLogWithFilterData(
274 const std::string& etw_filter_payload,
275 std::weak_ptr<EtwIsolateCaptureStateMonitor> weak_monitor,
277 size_t event_id = event_id_.fetch_add(1);
278 EtwIsolateOperations::Instance()->RequestInterrupt(
282 std::unique_ptr<EnableWithFilterDataInterruptData> interrupt_data(
284 size_t event_id = interrupt_data->event_id;
285 std::string etw_filter_payload = interrupt_data->payload;
286 auto weak_monitor = interrupt_data->weak_monitor;
287 uint32_t options = interrupt_data->options;
288 EnableLogWithFilterData(
reinterpret_cast<Isolate*
>(v8_isolate),
289 event_id, etw_filter_payload, weak_monitor,
293 weak_monitor, options});