aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasika Navarange <rasikan@google.com>2023-11-10 13:50:42 +0000
committerRasika Navarange <rasikan@google.com>2023-11-10 13:50:42 +0000
commit061e829e3b3bdb326e5c7cc4ae5710e131046a1f (patch)
treef1d2a0fb41726dd89e3298cd4a26dc5259220675
parente4c28cb31f2589786859be1f703657401f8c7440 (diff)
downloadperfetto-061e829e3b3bdb326e5c7cc4ae5710e131046a1f.tar.gz
Make CREATE_TABLE_ALLOWLIST paths relative to stdlib root
This will allow running this script for stdlib modules that live outside the Perfetto repo e.g. the Chrome stdlib. Bug: b/287233783 Change-Id: I07c0dfffc2248dbcc4650fe24de150155534431b
-rw-r--r--python/generators/sql_processing/utils.py7
-rwxr-xr-xtools/check_sql_metrics.py20
-rwxr-xr-xtools/check_sql_modules.py20
3 files changed, 23 insertions, 24 deletions
diff --git a/python/generators/sql_processing/utils.py b/python/generators/sql_processing/utils.py
index 2d14819a5..ce37e2e50 100644
--- a/python/generators/sql_processing/utils.py
+++ b/python/generators/sql_processing/utils.py
@@ -192,17 +192,18 @@ def check_banned_create_table_as(sql: str, filename: str,
# Given SQL string check whether there is (not allowlisted) usage of
# CREATE TABLE {name} AS.
-def check_banned_create_table_as(sql: str, filename: str,
+def check_banned_create_table_as(sql: str, filename: str, stdlib_path: str,
allowlist: Dict[str, List[str]]) -> List[str]:
errors = []
for _, matches in match_pattern(CREATE_TABLE_AS_PATTERN, sql).items():
name = matches[0]
- if filename not in allowlist:
+ allowlist_key = filename[len(stdlib_path):]
+ if allowlist_key not in allowlist:
errors.append(f"CREATE TABLE '{name}' is deprecated. "
"Use CREATE PERFETTO TABLE instead.\n"
f"Offending file: {filename}\n")
continue
- if name not in allowlist[filename]:
+ if name not in allowlist[allowlist_key]:
errors.append(
f"Table '{name}' uses CREATE TABLE which is deprecated "
"and this table is not allowlisted. Use CREATE PERFETTO TABLE.\n"
diff --git a/tools/check_sql_metrics.py b/tools/check_sql_metrics.py
index d1e937ea0..b577b43d2 100755
--- a/tools/check_sql_metrics.py
+++ b/tools/check_sql_metrics.py
@@ -34,24 +34,21 @@ from python.generators.sql_processing.utils import match_pattern
from python.generators.sql_processing.utils import DROP_TABLE_VIEW_PATTERN
from python.generators.sql_processing.utils import CREATE_TABLE_VIEW_PATTERN
+# Allowlist path are relative to the metrics root.
CREATE_TABLE_ALLOWLIST = {
- ('/src/trace_processor/metrics/sql/android'
+ ('/android'
'/android_blocking_calls_cuj_metric.sql'): [
'android_cujs', 'relevant_binder_calls_with_names',
'android_blocking_calls_cuj_calls'
],
- '/src/trace_processor/metrics/sql/android/jank/cujs.sql': [
- 'android_jank_cuj'
- ],
- '/src/trace_processor/metrics/sql/chrome/gesture_flow_event.sql': [
+ '/android/jank/cujs.sql': ['android_jank_cuj'],
+ '/chrome/gesture_flow_event.sql': [
'{{prefix}}_latency_info_flow_step_filtered'
],
- '/src/trace_processor/metrics/sql/chrome/gesture_jank.sql': [
+ '/chrome/gesture_jank.sql': [
'{{prefix}}_jank_maybe_null_prev_and_next_without_precompute'
],
- '/src/trace_processor/metrics/sql/experimental/frame_times.sql': [
- 'DisplayCompositorPresentationEvents'
- ]
+ '/experimental/frame_times.sql': ['DisplayCompositorPresentationEvents']
}
@@ -71,7 +68,7 @@ def match_drop_view_pattern_to_dict(sql: str,
return res
-def check(path: str) -> List[str]:
+def check(path: str, metrics_sources: str) -> List[str]:
with open(path) as f:
sql = f.read()
@@ -82,6 +79,7 @@ def check(path: str) -> List[str]:
sql, DROP_TABLE_VIEW_PATTERN)
errors = check_banned_create_table_as(sql,
path.split(ROOT_DIR)[1],
+ metrics_sources.split(ROOT_DIR)[1],
CREATE_TABLE_ALLOWLIST)
errors += check_banned_create_view_as(sql, path.split(ROOT_DIR)[1])
for name, [line, type] in create_table_view_dir.items():
@@ -110,7 +108,7 @@ def main():
for f in files:
path = os.path.join(root, f)
if path.endswith('.sql'):
- errors += check(path)
+ errors += check(path, metrics_sources)
if errors:
sys.stderr.write("\n".join(errors))
diff --git a/tools/check_sql_modules.py b/tools/check_sql_modules.py
index c3228a496..1cacd515e 100755
--- a/tools/check_sql_modules.py
+++ b/tools/check_sql_modules.py
@@ -32,28 +32,27 @@ from python.generators.sql_processing.utils import check_banned_create_view_as
from python.generators.sql_processing.utils import check_banned_words
from python.generators.sql_processing.utils import check_banned_include_all
+# Allowlist path are relative to the stdlib root.
CREATE_TABLE_ALLOWLIST = {
- '/src/trace_processor/perfetto_sql/stdlib/android/binder.sql': [
+ '/android/binder.sql': [
'internal_oom_score', 'internal_async_binder_reply',
'internal_binder_async_txn_raw'
],
- '/src/trace_processor/perfetto_sql/stdlib/android/monitor_contention.sql': [
+ '/android/monitor_contention.sql': [
'internal_isolated', 'android_monitor_contention_chain',
'android_monitor_contention'
],
- '/src/trace_processor/perfetto_sql/stdlib/chrome/tasks.sql': [
+ '/chrome/tasks.sql': [
'internal_chrome_mojo_slices', 'internal_chrome_java_views',
'internal_chrome_scheduler_tasks', 'internal_chrome_tasks'
],
- ('/src/trace_processor/perfetto_sql/stdlib/experimental/'
+ ('/experimental/'
'thread_executing_span.sql'): [
'internal_wakeup', 'experimental_thread_executing_span_graph',
'internal_critical_path', 'internal_wakeup_graph',
'experimental_thread_executing_span_graph'
],
- '/src/trace_processor/perfetto_sql/stdlib/experimental/flat_slices.sql': [
- 'experimental_slice_flattened'
- ]
+ '/experimental/flat_slices.sql': ['experimental_slice_flattened']
}
@@ -117,9 +116,10 @@ def main():
errors += parsed.errors
errors += check_banned_words(sql, path)
- errors += check_banned_create_table_as(sql,
- path.split(ROOT_DIR)[1],
- CREATE_TABLE_ALLOWLIST)
+ errors += check_banned_create_table_as(
+ sql,
+ path.split(ROOT_DIR)[1],
+ args.stdlib_sources.split(ROOT_DIR)[1], CREATE_TABLE_ALLOWLIST)
errors += check_banned_create_view_as(sql, path.split(ROOT_DIR)[1])
errors += check_banned_include_all(sql, path.split(ROOT_DIR)[1])