#include "src/trace_processor/perfetto_sql/intrinsics/table_functions/experimental_slice_layout.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "perfetto/base/compiler.h"
#include "perfetto/ext/base/status_or.h"
#include "perfetto/trace_processor/basic_types.h"
#include "src/base/test/status_matchers.h"
#include "src/trace_processor/containers/string_pool.h"
#include "src/trace_processor/db/column.h"
#include "src/trace_processor/perfetto_sql/intrinsics/table_functions/tables_py.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/tables/slice_tables_py.h"
#include "src/trace_processor/tables/track_tables_py.h"
#include "test/gtest_and_gmock.h"
namespace perfetto::trace_processor {
namespace {
std::string ToVis(const Table& table) { … }
void ExpectOutput(const Table& table, const std::string& expected) { … }
tables::SliceTable::Id Insert(tables::SliceTable* table,
int64_t ts,
int64_t dur,
uint32_t track_id,
StringId name,
std::optional<tables::SliceTable::Id> parent_id) { … }
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name = pool.InternString("SingleRow");
Insert(&slice_table, 1 , 5 , 1 , name,
std::nullopt );
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
#####
)");
}
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name = pool.InternString("SingleRow");
auto id = Insert(&slice_table, 1 , 5 , 1 , name,
std::nullopt);
Insert(&slice_table, 1 , 5 , 1 , name, id);
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
#####
#####
)");
}
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name = pool.InternString("MultipleRows");
auto a = Insert(&slice_table, 1 , 5 , 1 , name,
std::nullopt);
auto b = Insert(&slice_table, 1 , 4 , 1 , name, a);
auto c = Insert(&slice_table, 1 , 3 , 1 , name, b);
auto d = Insert(&slice_table, 1 , 2 , 1 , name, c);
auto e = Insert(&slice_table, 1 , 1 , 1 , name, d);
base::ignore_result(e);
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
#####
####
###
##
#
)");
}
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name1 = pool.InternString("Slice1");
StringId name2 = pool.InternString("Slice2");
StringId name3 = pool.InternString("Slice3");
StringId name4 = pool.InternString("Track4");
auto a = Insert(&slice_table, 1 , 4 , 1 , name1,
std::nullopt);
auto b = Insert(&slice_table, 1 , 2 , 1 , name2, a);
auto x = Insert(&slice_table, 4 , 4 , 2 , name3,
std::nullopt);
auto y = Insert(&slice_table, 4 , 2 , 2 , name4, x);
base::ignore_result(b);
base::ignore_result(y);
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1,2")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
####
##
####
##
)");
}
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name1 = pool.InternString("Slice1");
StringId name2 = pool.InternString("Slice2");
StringId name3 = pool.InternString("Slice3");
StringId name4 = pool.InternString("Slice4");
StringId name5 = pool.InternString("Slice5");
StringId name6 = pool.InternString("Slice6");
auto a = Insert(&slice_table, 0 , 4 , 1 , name1,
std::nullopt);
auto b = Insert(&slice_table, 0 , 2 , 1 , name2, a);
auto p = Insert(&slice_table, 3 , 4 , 2 , name3,
std::nullopt);
auto q = Insert(&slice_table, 3 , 2 , 2 , name4, p);
auto x = Insert(&slice_table, 5 , 4 , 1 , name5,
std::nullopt);
auto y = Insert(&slice_table, 5 , 2 , 1 , name6, x);
base::ignore_result(b);
base::ignore_result(q);
base::ignore_result(y);
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1,2")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
#### ####
## ##
####
##
)");
}
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name = pool.InternString("Slice");
auto a = Insert(&slice_table, 0 , 1 , 1 , name,
std::nullopt);
base::ignore_result(a);
auto c = Insert(&slice_table, 0 , 10 , 2 , name,
std::nullopt);
auto d = Insert(&slice_table, 0 , 9 , 2 , name, c);
base::ignore_result(d);
auto p = Insert(&slice_table, 3 , 4 , 3 , name,
std::nullopt);
auto q = Insert(&slice_table, 3 , 3 , 3 , name, p);
auto r = Insert(&slice_table, 3 , 2 , 3 , name, q);
auto s = Insert(&slice_table, 3 , 1 , 3 , name, r);
base::ignore_result(s);
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1,2,3")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
#
##########
#########
####
###
##
#
)");
}
TEST(…) {
StringPool pool;
tables::SliceTable slice_table(&pool);
StringId name1 = pool.InternString("Slice1");
StringId name2 = pool.InternString("Slice2");
StringId name3 = pool.InternString("Slice3");
StringId name4 = pool.InternString("Slice4");
StringId name5 = pool.InternString("Slice5");
auto a = Insert(&slice_table, 0 , 4 , 1 , name1,
std::nullopt);
auto b = Insert(&slice_table, 0 , 2 , 1 , name2, a);
auto p = Insert(&slice_table, 3 , 4 , 2 , name3,
std::nullopt);
auto q = Insert(&slice_table, 3 , 2 , 2 , name4, p);
Insert(&slice_table, 0 , 9 , 3 , name5,
std::nullopt);
base::ignore_result(b);
base::ignore_result(q);
ExperimentalSliceLayout gen(&pool, &slice_table);
base::StatusOr<std::unique_ptr<Table>> table =
gen.ComputeTable({SqlValue::String("1,2")});
EXPECT_OK(…);
ExpectOutput(**table, R"(
####
##
####
##
)");
}
}
}