forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetdump_filter.cpp
More file actions
95 lines (79 loc) · 2.38 KB
/
Copy pathetdump_filter.cpp
File metadata and controls
95 lines (79 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <executorch/devtools/etdump/etdump_filter.h>
#include <executorch/runtime/core/error.h>
using ::executorch::runtime::DelegateDebugIntId;
using ::executorch::runtime::Error;
using ::executorch::runtime::kUnsetDelegateDebugIntId;
namespace executorch {
namespace etdump {
ETDumpFilter::ETDumpFilter() = default;
Result<bool> ETDumpFilter::add_regex(string_view pattern) {
auto regex = std::make_unique<re2::RE2>(pattern.data());
if (!regex->ok()) {
return Error::InvalidArgument; // Error during regex compilation
}
regex_patterns_.emplace_back(std::move(regex));
return true;
}
Result<bool> ETDumpFilter::set_debug_handle_range(size_t start, size_t end) {
if (start >= end) {
return Error::InvalidArgument; // Start is greater than end
}
if (start < 0 || end < 0) {
return Error::InvalidArgument; // Start or end is negative
}
range_start_ = start;
range_end_ = end;
return true;
}
Result<bool> ETDumpFilter::filter_name_(const char* name) {
if (name == nullptr) {
return Error::InvalidArgument;
}
if (regex_patterns_.empty()) {
return true;
}
for (const auto& regex : regex_patterns_) {
if (RE2::FullMatch(name, *regex)) {
return true;
}
}
return false;
}
Result<bool> ETDumpFilter::filter_delegate_debug_index_(
DelegateDebugIntId debug_handle) {
if (debug_handle == kUnsetDelegateDebugIntId) {
return Error::InvalidArgument; // Delegate debug index is unset
}
if (range_start_ == 0 && range_end_ == 0) {
return true;
}
if (debug_handle < range_start_ || debug_handle >= range_end_) {
return false;
}
return true;
}
Result<bool> ETDumpFilter::filter(
const char* name,
DelegateDebugIntId delegate_debug_index) {
if ((name == nullptr) == (delegate_debug_index == kUnsetDelegateDebugIntId)) {
return Error::InvalidArgument; // Name and delegate debug index should be
// both set or unset
}
if (name) {
return filter_name_(name);
} else {
return filter_delegate_debug_index_(delegate_debug_index);
}
}
size_t ETDumpFilter::get_n_regex() const {
return regex_patterns_.size();
}
} // namespace etdump
} // namespace executorch