Commit 3ac11488 authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Use first sample time as profile start time

Now that per-sample timestamps are provided to the ProfileBuilder we
can set the actual profile start time -- the time the first sample
is taken -- rather than using the prior approximation of when the
CallStackProfileBuilder class was created.

This will be used when applying retrospective metadata, to ignore requests
on time ranges prior to the profile start time.

Bug: 1034758
Change-Id: Idf51c4e40dd853408d5f7baee6e9f657d18aa061
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015724
Commit-Queue: Mike Wittman <wittman@chromium.org>
Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740806}
parent 3b14f137
......@@ -53,8 +53,7 @@ CallStackProfileBuilder::CallStackProfileBuilder(
const CallStackProfileParams& profile_params,
const WorkIdRecorder* work_id_recorder,
base::OnceClosure completed_callback)
: work_id_recorder_(work_id_recorder),
profile_start_time_(base::TimeTicks::Now()) {
: work_id_recorder_(work_id_recorder) {
completed_callback_ = std::move(completed_callback);
sampled_profile_.set_process(
ToExecutionContextProcess(profile_params.process));
......@@ -153,6 +152,9 @@ void CallStackProfileBuilder::OnSampleCompleted(
*stack_sample_proto->mutable_metadata() = metadata_.CreateSampleMetadata(
call_stack_profile->mutable_metadata_name_hash());
if (profile_start_time_.is_null())
profile_start_time_ = sample_timestamp;
}
void CallStackProfileBuilder::OnProfileCompleted(
......@@ -174,7 +176,8 @@ void CallStackProfileBuilder::OnProfileCompleted(
HashModuleFilename(module->GetDebugBasename()));
}
PassProfilesToMetricsProvider(std::move(sampled_profile_));
PassProfilesToMetricsProvider(profile_start_time_,
std::move(sampled_profile_));
// Run the completed callback if there is one.
if (!completed_callback_.is_null())
......@@ -202,13 +205,14 @@ void CallStackProfileBuilder::SetParentProfileCollectorForChildProcess(
}
void CallStackProfileBuilder::PassProfilesToMetricsProvider(
base::TimeTicks profile_start_time,
SampledProfile sampled_profile) {
if (sampled_profile.process() == BROWSER_PROCESS) {
GetBrowserProcessReceiverCallbackInstance().Run(profile_start_time_,
GetBrowserProcessReceiverCallbackInstance().Run(profile_start_time,
std::move(sampled_profile));
} else {
g_child_call_stack_profile_collector.Get()
.ChildCallStackProfileCollector::Collect(profile_start_time_,
.ChildCallStackProfileCollector::Collect(profile_start_time,
std::move(sampled_profile));
}
}
......
......@@ -94,7 +94,8 @@ class CallStackProfileBuilder : public base::ProfileBuilder {
protected:
// Test seam.
virtual void PassProfilesToMetricsProvider(SampledProfile sampled_profile);
virtual void PassProfilesToMetricsProvider(base::TimeTicks profile_start_time,
SampledProfile sampled_profile);
private:
// The functor for Stack comparison.
......@@ -128,7 +129,7 @@ class CallStackProfileBuilder : public base::ProfileBuilder {
base::OnceClosure completed_callback_;
// The start time of a profile collection.
const base::TimeTicks profile_start_time_;
base::TimeTicks profile_start_time_;
// Maintains the current metadata to apply to samples.
CallStackProfileMetadata metadata_;
......
......@@ -57,14 +57,22 @@ class TestingCallStackProfileBuilder : public CallStackProfileBuilder {
~TestingCallStackProfileBuilder() override;
const SampledProfile& test_sampled_profile() { return test_sampled_profile_; }
base::TimeTicks test_profile_start_time() const {
return test_profile_start_time_;
}
const SampledProfile& test_sampled_profile() const {
return test_sampled_profile_;
}
protected:
// Overridden for testing.
void PassProfilesToMetricsProvider(SampledProfile sampled_profile) override;
void PassProfilesToMetricsProvider(base::TimeTicks profile_start_time,
SampledProfile sampled_profile) override;
private:
// The completed profile.
// The start time and completed profile.
base::TimeTicks test_profile_start_time_;
SampledProfile test_sampled_profile_;
};
......@@ -79,7 +87,9 @@ TestingCallStackProfileBuilder::TestingCallStackProfileBuilder(
TestingCallStackProfileBuilder::~TestingCallStackProfileBuilder() = default;
void TestingCallStackProfileBuilder::PassProfilesToMetricsProvider(
base::TimeTicks profile_start_time,
SampledProfile sampled_profile) {
test_profile_start_time_ = profile_start_time;
test_sampled_profile_ = std::move(sampled_profile);
}
......@@ -444,6 +454,23 @@ TEST(CallStackProfileBuilderTest, WorkIds) {
EXPECT_TRUE(profile.stack_sample(4).continued_work());
}
TEST(CallStackProfileBuilderTest, ProfileStartTime) {
auto profile_builder =
std::make_unique<TestingCallStackProfileBuilder>(kProfileParams);
TestModule module;
const base::Frame frame = {0x10, &module};
const base::TimeTicks first_sample_time = base::TimeTicks::UnixEpoch();
profile_builder->OnSampleCompleted({frame}, first_sample_time);
profile_builder->OnSampleCompleted(
{frame}, first_sample_time + base::TimeDelta::FromSeconds(1));
profile_builder->OnProfileCompleted(base::TimeDelta::FromSeconds(1),
base::TimeDelta::FromSeconds(1));
EXPECT_EQ(first_sample_time, profile_builder->test_profile_start_time());
}
// A basic test of the metadata functionality at the level of the
// CallStackProfileBuilder. The underlying implementation in
// CallStackProfileMetadata is tested independently.
......
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