Commit 14a1dec8 authored by alph's avatar alph Committed by Commit bot

Unflake SampleWhenFrameIsNotSetup

Recent flake happened bacause all the samples landed into native code.
The patch makes sure we collect enough JS samples.

BUG=v8:4751
LOG=N

Review URL: https://codereview.chromium.org/1695663002

Cr-Commit-Position: refs/heads/master@{#33953}
parent 47c08f5f
......@@ -745,7 +745,6 @@ void Sampler::TearDown() {
#endif
}
Sampler::Sampler(Isolate* isolate, int interval)
: isolate_(isolate),
interval_(interval),
......@@ -753,17 +752,16 @@ Sampler::Sampler(Isolate* isolate, int interval)
has_processing_thread_(false),
active_(false),
is_counting_samples_(false),
js_and_external_sample_count_(0) {
js_sample_count_(0),
external_sample_count_(0) {
data_ = new PlatformData;
}
Sampler::~Sampler() {
DCHECK(!IsActive());
delete data_;
}
void Sampler::Start() {
DCHECK(!IsActive());
SetActive(true);
......@@ -800,9 +798,8 @@ void Sampler::SampleStack(const v8::RegisterState& state) {
if (sample == NULL) sample = &sample_obj;
sample->Init(isolate_, state, TickSample::kIncludeCEntryFrame, true);
if (is_counting_samples_) {
if (sample->state == JS || sample->state == EXTERNAL) {
++js_and_external_sample_count_;
}
if (sample->state == JS) ++js_sample_count_;
if (sample->state == EXTERNAL) ++external_sample_count_;
}
Tick(sample);
if (sample != &sample_obj) {
......
......@@ -100,12 +100,12 @@ class Sampler {
}
// Used in tests to make sure that stack sampling is performed.
unsigned js_and_external_sample_count() const {
return js_and_external_sample_count_;
}
unsigned js_sample_count() const { return js_sample_count_; }
unsigned external_sample_count() const { return external_sample_count_; }
void StartCountingSamples() {
is_counting_samples_ = true;
js_and_external_sample_count_ = 0;
js_sample_count_ = 0;
external_sample_count_ = 0;
is_counting_samples_ = true;
}
class PlatformData;
......@@ -125,9 +125,10 @@ class Sampler {
base::Atomic32 has_processing_thread_;
base::Atomic32 active_;
PlatformData* data_; // Platform specific data.
// Counts stack samples taken in various VM states.
bool is_counting_samples_;
// Counts stack samples taken in JS VM state.
unsigned js_and_external_sample_count_;
unsigned js_sample_count_;
unsigned external_sample_count_;
DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
};
......
......@@ -417,11 +417,11 @@ TEST(ProfileStartEndTime) {
CHECK(profile->GetStartTime() <= profile->GetEndTime());
}
static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env,
v8::Local<v8::Function> function,
v8::Local<v8::Value> argv[], int argc,
unsigned min_js_samples,
unsigned min_js_samples = 0,
unsigned min_external_samples = 0,
bool collect_samples = false) {
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name = v8_str("my_profile");
......@@ -434,7 +434,8 @@ static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env,
sampler->StartCountingSamples();
do {
function->Call(env, env->Global(), argc, argv).ToLocalChecked();
} while (sampler->js_and_external_sample_count() < min_js_samples);
} while (sampler->js_sample_count() < min_js_samples ||
sampler->external_sample_count() < min_external_samples);
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
......@@ -642,7 +643,7 @@ TEST(CollectCpuProfileSamples) {
v8::Local<v8::Value> args[] = {
v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, arraysize(args), 1000, true);
RunProfiler(env.local(), function, args, arraysize(args), 1000, 0, true);
CHECK_LE(200, profile->GetSamplesCount());
uint64_t end_time = profile->GetEndTime();
......@@ -792,7 +793,7 @@ TEST(NativeAccessorUninitializedIC) {
int32_t repeat_count = 1;
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, arraysize(args), 180);
RunProfiler(env.local(), function, args, arraysize(args), 0, 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
......@@ -845,7 +846,7 @@ TEST(NativeAccessorMonomorphicIC) {
int32_t repeat_count = 100;
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, arraysize(args), 200);
RunProfiler(env.local(), function, args, arraysize(args), 0, 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
......@@ -896,7 +897,7 @@ TEST(NativeMethodUninitializedIC) {
int32_t repeat_count = 1;
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, arraysize(args), 100);
RunProfiler(env.local(), function, args, arraysize(args), 0, 100);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
......@@ -950,7 +951,7 @@ TEST(NativeMethodMonomorphicIC) {
int32_t repeat_count = 100;
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
v8::CpuProfile* profile =
RunProfiler(env.local(), function, args, arraysize(args), 100);
RunProfiler(env.local(), function, args, arraysize(args), 0, 200);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
GetChild(env.local(), root, "start");
......@@ -979,7 +980,7 @@ TEST(BoundFunctionCall) {
CompileRun(bound_function_test_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
......@@ -1497,7 +1498,7 @@ TEST(JsNativeJsRuntimeJsSampleMultiple) {
CompileRun(js_native_js_runtime_multiple_test_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000);
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 500, 500);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment