v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
etw-isolate-capture-state-monitor-win.cc
Go to the documentation of this file.
1
// Copyright 2024 the V8 project authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include "
src/diagnostics/etw-isolate-capture-state-monitor-win.h
"
6
7
#include "
src/base/platform/condition-variable.h
"
8
#include "
src/base/platform/mutex.h
"
9
#include "
src/base/platform/time.h
"
10
#include "
src/diagnostics/etw-debug-win.h
"
11
12
namespace
v8
{
13
namespace
internal
{
14
namespace
ETWJITInterface {
15
16
EtwIsolateCaptureStateMonitor::EtwIsolateCaptureStateMonitor
(
17
base::Mutex
*
mutex
,
size_t
pending_isolate_count)
18
:
mutex_
(
mutex
), pending_isolate_count_(pending_isolate_count) {}
19
20
bool
EtwIsolateCaptureStateMonitor::WaitFor
(
const
base::TimeDelta
& delta) {
21
wait_started_
=
base::TimeTicks::Now
();
22
base::TimeDelta
remaining = delta;
23
24
if
(
pending_isolate_count_
== 0) {
25
return
true
;
26
}
27
28
ETWTRACEDBG
<<
"Waiting for "
<<
pending_isolate_count_
29
<<
" isolates for up to "
<< remaining.
InMilliseconds
()
30
<< std::endl;
31
while
(
isolates_ready_cv_
.
WaitFor
(
mutex_
, remaining)) {
32
ETWTRACEDBG
<<
"WaitFor woke up: "
<<
pending_isolate_count_
33
<<
" isolates remaining "
<< std::endl;
34
if
(
pending_isolate_count_
== 0) {
35
return
true
;
36
}
37
38
// If the timeout has expired, return false.
39
auto
elapsed =
base::TimeTicks::Now
() -
wait_started_
;
40
if
(elapsed >= remaining) {
41
ETWTRACEDBG
<<
"Elapsed is "
<< elapsed.InMilliseconds()
42
<<
" greater than reminaing "
<< remaining.
InMilliseconds
()
43
<< std::endl;
44
return
false
;
45
}
46
47
// If the condition variable was woken up spuriously, adjust the timeout.
48
remaining -= elapsed;
49
ETWTRACEDBG
<<
"New remaining "
<< remaining.
InMilliseconds
()
50
<<
" resuming waiting"
<< std::endl;
51
}
52
53
// Propagate the WaitFor false return value (timeout before being notified) to
54
// the caller.
55
return
false
;
56
}
57
58
void
EtwIsolateCaptureStateMonitor::Notify
() {
59
{
60
ETWTRACEDBG
<<
"Notify taking mutex"
<< std::endl;
61
base::MutexGuard
lock(
mutex_
);
62
pending_isolate_count_
--;
63
ETWTRACEDBG
<<
"Got mutex and isolate count reduced to "
64
<<
pending_isolate_count_
<< std::endl;
65
}
66
ETWTRACEDBG
<<
"Released mutex preparing to notifyOne "
<< std::endl;
67
isolates_ready_cv_
.
NotifyOne
();
68
ETWTRACEDBG
<<
"Finished notifyOne "
<< std::endl;
69
}
70
71
}
// namespace ETWJITInterface
72
}
// namespace internal
73
}
// namespace v8
v8::base::ConditionVariable::WaitFor
bool WaitFor(Mutex *mutex, const TimeDelta &rel_time) V8_WARN_UNUSED_RESULT
Definition
condition-variable.cc:33
v8::base::ConditionVariable::NotifyOne
void NotifyOne()
Definition
condition-variable.cc:23
v8::base::LockGuard
Definition
mutex.h:192
v8::base::Mutex
Definition
mutex.h:36
v8::base::TimeDelta
Definition
time.h:67
v8::base::TimeDelta::InMilliseconds
int64_t InMilliseconds() const
Definition
time.cc:234
v8::base::TimeTicks::Now
static TimeTicks Now()
Definition
time.cc:736
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::isolates_ready_cv_
base::ConditionVariable isolates_ready_cv_
Definition
etw-isolate-capture-state-monitor-win.h:36
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::wait_started_
base::TimeTicks wait_started_
Definition
etw-isolate-capture-state-monitor-win.h:39
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::pending_isolate_count_
size_t pending_isolate_count_
Definition
etw-isolate-capture-state-monitor-win.h:35
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::EtwIsolateCaptureStateMonitor
EtwIsolateCaptureStateMonitor(base::Mutex *mutex, size_t pending_isolate_count)
Definition
etw-isolate-capture-state-monitor-win.cc:16
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::WaitFor
bool WaitFor(const base::TimeDelta &delta)
Definition
etw-isolate-capture-state-monitor-win.cc:20
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::Notify
void Notify()
Definition
etw-isolate-capture-state-monitor-win.cc:58
v8::internal::ETWJITInterface::EtwIsolateCaptureStateMonitor::mutex_
base::Mutex * mutex_
Definition
etw-isolate-capture-state-monitor-win.h:34
mutex_
base::Mutex & mutex_
Definition
code-memory-access.cc:623
condition-variable.h
etw-debug-win.h
ETWTRACEDBG
#define ETWTRACEDBG
Definition
etw-debug-win.h:26
etw-isolate-capture-state-monitor-win.h
mutex
base::Mutex mutex
Definition
module-compiler.cc:314
mutex.h
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8
Definition
api-arguments-inl.h:19
time.h
src
diagnostics
etw-isolate-capture-state-monitor-win.cc
Generated on Sun Apr 6 2025 21:08:53 for v8 by
1.12.0