Skip to content

Commit

Permalink
tp: defer including prelude into NotifyEof is called
Browse files Browse the repository at this point in the history
Ensures we can create tables in the prelude.

Change-Id: I9f5027e1cfd8599c7c8a499696807eeb0b4833a4
  • Loading branch information
LalitMaganti committed Oct 19, 2024
1 parent 6715e74 commit bd63e0a
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 65 deletions.
12 changes: 6 additions & 6 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -13618,12 +13618,12 @@ genrule {
"src/trace_processor/perfetto_sql/stdlib/linux/perf/spe.sql",
"src/trace_processor/perfetto_sql/stdlib/linux/threads.sql",
"src/trace_processor/perfetto_sql/stdlib/pkvm/hypervisor.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/casts.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/slices.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/tables.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/tables_views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/trace_bounds.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/casts.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/slices.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/tables_views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/before_eof/tables.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/before_eof/trace_bounds.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/runnable.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/states.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/thread_executing_span.sql",
Expand Down
30 changes: 22 additions & 8 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2973,19 +2973,31 @@ perfetto_filegroup(
],
)

# GN target: //src/trace_processor/perfetto_sql/stdlib/prelude:prelude
# GN target: //src/trace_processor/perfetto_sql/stdlib/prelude/after_eof:after_eof
perfetto_filegroup(
name = "src_trace_processor_perfetto_sql_stdlib_prelude_prelude",
name = "src_trace_processor_perfetto_sql_stdlib_prelude_after_eof_after_eof",
srcs = [
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/casts.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/slices.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/tables_views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/views.sql",
],
)

# GN target: //src/trace_processor/perfetto_sql/stdlib/prelude/before_eof:before_eof
perfetto_filegroup(
name = "src_trace_processor_perfetto_sql_stdlib_prelude_before_eof_before_eof",
srcs = [
"src/trace_processor/perfetto_sql/stdlib/prelude/casts.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/slices.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/tables.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/tables_views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/trace_bounds.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/before_eof/tables.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/before_eof/trace_bounds.sql",
],
)

# GN target: //src/trace_processor/perfetto_sql/stdlib/prelude:prelude
perfetto_filegroup(
name = "src_trace_processor_perfetto_sql_stdlib_prelude_prelude",
)

# GN target: //src/trace_processor/perfetto_sql/stdlib/sched:sched
perfetto_filegroup(
name = "src_trace_processor_perfetto_sql_stdlib_sched_sched",
Expand Down Expand Up @@ -3117,6 +3129,8 @@ perfetto_cc_amalgamated_sql(
":src_trace_processor_perfetto_sql_stdlib_linux_memory_memory",
":src_trace_processor_perfetto_sql_stdlib_linux_perf_perf",
":src_trace_processor_perfetto_sql_stdlib_pkvm_pkvm",
":src_trace_processor_perfetto_sql_stdlib_prelude_after_eof_after_eof",
":src_trace_processor_perfetto_sql_stdlib_prelude_before_eof_before_eof",
":src_trace_processor_perfetto_sql_stdlib_prelude_prelude",
":src_trace_processor_perfetto_sql_stdlib_sched_sched",
":src_trace_processor_perfetto_sql_stdlib_slices_slices",
Expand Down
13 changes: 5 additions & 8 deletions src/trace_processor/perfetto_sql/stdlib/prelude/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 The Android Open Source Project
# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,12 +15,9 @@
import("../../../../../gn/perfetto_sql.gni")

perfetto_sql_source_set("prelude") {
sources = [
"casts.sql",
"slices.sql",
"tables.sql",
"tables_views.sql",
"trace_bounds.sql",
"views.sql",
sources = []
deps = [
"after_eof",
"before_eof",
]
}
24 changes: 24 additions & 0 deletions src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("../../../../../../gn/perfetto_sql.gni")

perfetto_sql_source_set("after_eof") {
sources = [
"casts.sql",
"slices.sql",
"tables_views.sql",
"views.sql",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

INCLUDE PERFETTO MODULE prelude.views;
INCLUDE PERFETTO MODULE prelude.after_eof.views;

-- Given two slice ids, returns whether the first is an ancestor of the second.
CREATE PERFETTO FUNCTION slice_is_ancestor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

INCLUDE PERFETTO MODULE prelude.views;
INCLUDE PERFETTO MODULE prelude.after_eof.views;

-- Tracks are a fundamental concept in trace processor and represent a
-- "timeline" for events of the same type and with the same context. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

INCLUDE PERFETTO MODULE prelude.casts;
INCLUDE PERFETTO MODULE prelude.after_eof.casts;

-- Alias of the `counter` table.
CREATE PERFETTO VIEW counters(
Expand Down Expand Up @@ -146,7 +146,7 @@ CREATE PERFETTO VIEW slices(
-- Alias of `slice.thread_instruction_delta`.
thread_instruction_delta LONG,
-- Alias of `slice.cat`.
cat LONG,
cat STRING,
-- Alias of `slice.slice_id`.
slice_id LONG
) AS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("../../../../../../gn/perfetto_sql.gni")

perfetto_sql_source_set("before_eof") {
sources = [
"tables.sql",
"trace_bounds.sql",
]
}
1 change: 1 addition & 0 deletions src/trace_processor/tables/track_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
doc='Tracks containing gpu_work_period events.',
group='Tracks',
columns={
'uid': 'The uid associated with this track.',
'gpu_id': 'The identifier for the GPU.',
}))

Expand Down
37 changes: 22 additions & 15 deletions src/trace_processor/trace_database_integrationtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ class TraceProcessorIntegrationTest : public ::testing::Test {
if (!status.ok())
return status;
}
return processor_->NotifyEndOfFile();
return NotifyEndOfFile();
}
base::Status NotifyEndOfFile() { return processor_->NotifyEndOfFile(); }

Iterator Query(const std::string& query) {
return processor_->ExecuteQuery(query);
Expand Down Expand Up @@ -289,6 +290,8 @@ TEST_F(TraceProcessorIntegrationTest, SerializeMetricDescriptors) {
}

TEST_F(TraceProcessorIntegrationTest, ComputeMetricsFormattedExtension) {
ASSERT_OK(NotifyEndOfFile());

std::string metric_output;
base::Status status = Processor()->ComputeMetricText(
std::vector<std::string>{"test_chrome_metric"},
Expand All @@ -302,11 +305,12 @@ TEST_F(TraceProcessorIntegrationTest, ComputeMetricsFormattedExtension) {
}

TEST_F(TraceProcessorIntegrationTest, ComputeMetricsFormattedNoExtension) {
ASSERT_OK(NotifyEndOfFile());

std::string metric_output;
base::Status status = Processor()->ComputeMetricText(
ASSERT_OK(Processor()->ComputeMetricText(
std::vector<std::string>{"trace_metadata"},
TraceProcessor::MetricResultFormat::kProtoText, &metric_output);
ASSERT_TRUE(status.ok());
TraceProcessor::MetricResultFormat::kProtoText, &metric_output));
// Check that metric result starts with trace_metadata field. Since this is
// not an extension field, the field name is not fully qualified.
ASSERT_TRUE(metric_output.rfind("trace_metadata {") == 0);
Expand Down Expand Up @@ -410,13 +414,13 @@ TEST_F(TraceProcessorIntegrationTest, MAYBE_Clusterfuzz28766) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesInvariant) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
uint64_t first_restore = RestoreInitialTables();
ASSERT_EQ(RestoreInitialTables(), first_restore);
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesPerfettoSql) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
RestoreInitialTables();

for (int repeat = 0; repeat < 3; repeat++) {
Expand Down Expand Up @@ -465,7 +469,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesPerfettoSql) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesStandardSqlite) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
RestoreInitialTables();

for (int repeat = 0; repeat < 3; repeat++) {
Expand All @@ -491,7 +495,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesStandardSqlite) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesModules) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
RestoreInitialTables();

for (int repeat = 0; repeat < 3; repeat++) {
Expand All @@ -511,7 +515,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesModules) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesSpanJoin) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
RestoreInitialTables();

for (int repeat = 0; repeat < 3; repeat++) {
Expand Down Expand Up @@ -550,7 +554,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesSpanJoin) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesWithClause) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
RestoreInitialTables();

for (int repeat = 0; repeat < 3; repeat++) {
Expand All @@ -567,7 +571,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesWithClause) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesIndex) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
RestoreInitialTables();

for (int repeat = 0; repeat < 3; repeat++) {
Expand Down Expand Up @@ -605,7 +609,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesTraceBounds) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesDependents) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
{
auto it = Query("create perfetto table foo as select 1 as x");
ASSERT_FALSE(it.Next());
Expand All @@ -625,7 +629,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreInitialTablesDependents) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreDependentFunction) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
{
auto it =
Query("create perfetto function foo0() returns INT as select 1 as x");
Expand All @@ -645,7 +649,7 @@ TEST_F(TraceProcessorIntegrationTest, RestoreDependentFunction) {
}

TEST_F(TraceProcessorIntegrationTest, RestoreDependentTableFunction) {
ASSERT_OK(Processor()->NotifyEndOfFile());
ASSERT_OK(NotifyEndOfFile());
{
auto it = Query(
"create perfetto function foo0() returns TABLE(x INT) "
Expand Down Expand Up @@ -735,6 +739,7 @@ TEST_F(TraceProcessorIntegrationTest, TraceWithUuidReadInParts) {
}

TEST_F(TraceProcessorIntegrationTest, ErrorMessageExecuteQuery) {
ASSERT_OK(NotifyEndOfFile());
auto it = Query("select t from slice");
ASSERT_FALSE(it.Next());
ASSERT_FALSE(it.Status().ok());
Expand All @@ -748,6 +753,7 @@ no such column: t)"));
}

TEST_F(TraceProcessorIntegrationTest, ErrorMessageMetricFile) {
ASSERT_OK(NotifyEndOfFile());
ASSERT_TRUE(
Processor()->RegisterMetric("foo/bar.sql", "select t from slice").ok());

Expand All @@ -767,6 +773,7 @@ no such column: t)");
}

TEST_F(TraceProcessorIntegrationTest, ErrorMessageModule) {
ASSERT_OK(NotifyEndOfFile());
SqlPackage module;
module.name = "foo";
module.modules.push_back(std::make_pair("foo.bar", "select t from slice"));
Expand Down Expand Up @@ -819,7 +826,7 @@ TEST_F(TraceProcessorIntegrationTest, InvalidTrace) {
->Parse(TraceBlobView(
TraceBlob::CopyFrom(kBadData, sizeof(kBadData))))
.ok());
Processor()->NotifyEndOfFile();
NotifyEndOfFile();
}

TEST_F(TraceProcessorIntegrationTest, NoNotifyEndOfFileCalled) {
Expand Down
Loading

0 comments on commit bd63e0a

Please sign in to comment.