Skip to content

Commit

Permalink
More fixes for Windows Compilation with Regex.
Browse files Browse the repository at this point in the history
Change-Id: I6f0c626ef8c45ebc51fe75eb83a0e3af86302a6e
  • Loading branch information
Harkiran Bolaria authored and LalitMaganti committed Jul 6, 2023
1 parent b6d4985 commit 41c5036
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Unreleased:
SDK:
*

v36.1 - 2023-07-06:
Trace Processor:
* Fix compile on Windows.

v36.0 - 2023-07-05:
Tracing service and probes:
* Fixed unnecessary reads of thread files /proc when scraping process names.
Expand Down
2 changes: 2 additions & 0 deletions src/trace_processor/db/query_executor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ TEST(QueryExecutor, StringBinarySearchIsNull) {
ASSERT_EQ(res.Get(0), 2u);
}

#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
TEST(QueryExecutor, StringBinarySearchRegex) {
StringPool pool;
std::vector<std::string> strings{"cheese", "pasta", "pizza",
Expand Down Expand Up @@ -502,6 +503,7 @@ TEST(QueryExecutor, StringBinarySearchRegexWithNum) {

ASSERT_EQ(res.size(), 0u);
}
#endif

} // namespace
} // namespace trace_processor
Expand Down
58 changes: 23 additions & 35 deletions src/trace_processor/db/storage/string_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ struct GlobFullStringPool {
std::vector<uint8_t> matches_;
};

#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)

struct Regex {
bool operator()(StringPool::Id rhs, regex::Regex& pattern) const {
return rhs != StringPool::Id::Null() &&
Expand All @@ -122,8 +120,6 @@ struct RegexFullStringPool {
std::vector<uint8_t> matches_;
};

#endif

struct IsNull {
bool operator()(StringPool::Id rhs, StringPool::Id) const {
return rhs == StringPool::Id::Null();
Expand Down Expand Up @@ -216,31 +212,25 @@ RangeOrBitVector StringStorage::Search(FilterOp op,
GlobFullStringPool{string_pool_, matcher}, builder);
break;
}
case FilterOp::kRegex:
if constexpr (regex::IsRegexSupported()) {
base::StatusOr<regex::Regex> regex =
regex::Regex::Create(sql_val.AsString());
if (!regex.status().ok()) {
break;
}

// For very big string pools (or small ranges) or pools with large
// strings run a standard regex function.
if (range.size() < string_pool_->size() ||
string_pool_->HasLargeString()) {
utils::LinearSearchWithComparator(std::move(regex.value()), start,
Regex{string_pool_}, builder);
break;
}

utils::LinearSearchWithComparator(
StringPool::Id::Null(), start,
RegexFullStringPool{string_pool_, regex.value()}, builder);
case FilterOp::kRegex: {
// Caller should ensure that the regex is valid.
base::StatusOr<regex::Regex> regex =
regex::Regex::Create(sql_val.AsString());
PERFETTO_CHECK(regex.status().ok());

// For very big string pools (or small ranges) or pools with large
// strings run a standard regex function.
if (range.size() < string_pool_->size() ||
string_pool_->HasLargeString()) {
utils::LinearSearchWithComparator(std::move(regex.value()), start,
Regex{string_pool_}, builder);
break;
} else {
PERFETTO_DFATAL("Regex not supported");
}

utils::LinearSearchWithComparator(
StringPool::Id::Null(), start,
RegexFullStringPool{string_pool_, regex.value()}, builder);
break;
}
case FilterOp::kIsNull:
utils::LinearSearchWithComparator(val, start, IsNull(), builder);
break;
Expand Down Expand Up @@ -312,15 +302,13 @@ RangeOrBitVector StringStorage::IndexSearch(FilterOp op,
Glob{string_pool_}, builder);
break;
}
case FilterOp::kRegex:
PERFETTO_CHECK(regex::IsRegexSupported());
if constexpr (regex::IsRegexSupported()) {
base::StatusOr<regex::Regex> regex =
regex::Regex::Create(sql_val.AsString());
utils::IndexSearchWithComparator(std::move(regex.value()), start,
indices, Regex{string_pool_}, builder);
}
case FilterOp::kRegex: {
base::StatusOr<regex::Regex> regex =
regex::Regex::Create(sql_val.AsString());
utils::IndexSearchWithComparator(std::move(regex.value()), start, indices,
Regex{string_pool_}, builder);
break;
}
case FilterOp::kIsNull:
utils::IndexSearchWithComparator(val, start, indices, IsNull(), builder);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/trace_processor/db/storage/string_storage_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ TEST(StringStorageUnittest, LinearSearchGlob) {
ASSERT_EQ(bv.CountSetBits(), 3u);
}

#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
TEST(StringStorageUnittest, LinearSearchRegex) {
std::vector<std::string> strings{"cheese", "pasta", "pizza",
"pierogi", "onion", "fries"};
Expand Down Expand Up @@ -229,6 +230,7 @@ TEST(StringStorageUnittest, LinearSearchRegexMalformed) {

ASSERT_EQ(bv.CountSetBits(), 0u);
}
#endif

TEST(StringStorageUnittest, IndexSearchEq) {
std::vector<std::string> strings{"cheese", "pasta", "pizza",
Expand Down
3 changes: 3 additions & 0 deletions src/trace_processor/util/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define SRC_TRACE_PROCESSOR_UTIL_REGEX_H_

#include <optional>
#include "perfetto/base/compiler.h"
#include "perfetto/ext/base/scoped_file.h"
#include "perfetto/ext/base/status_or.h"

Expand Down Expand Up @@ -69,6 +70,7 @@ class Regex {
}
return Regex(std::move(regex));
#else
base::ignore_result(pattern);
PERFETTO_FATAL("Windows regex is not supported.");
#endif
}
Expand All @@ -79,6 +81,7 @@ class Regex {
PERFETTO_CHECK(regex_);
return regexec(&regex_.value(), s, 0, nullptr, 0) == 0;
#else
base::ignore_result(s);
PERFETTO_FATAL("Windows regex is not supported.");
#endif
}
Expand Down

0 comments on commit 41c5036

Please sign in to comment.