wattson: Fix estimates when entire CPU track missing

When an entire CPU freq or idle track is missing, then some other CPU
estimates won't be calculated.

Add a NULL but defined time range for CPUs that are physically present
on the device but don't have a single freq/idle event triggered. This is
so that interval_intersect() operates on a valid time range.

Test: tools/diff_test_trace_processor.py out/linux/trace_processor_shell --name-filter '.*wattson.*'
Bug: 379160886
Change-Id: I3b3fa24a61c2e348802b064e17d7dc93000f32b2
Signed-off-by: Samuel Wu <wusamuel@google.com>
diff --git a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_freq.sql b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_freq.sql
index 94f8fd7..1256f3b 100644
--- a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_freq.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_freq.sql
@@ -51,4 +51,16 @@
   freq,
   cpu,
   policy
-FROM _cpu_freq;
+FROM _cpu_freq
+UNION ALL
+-- Add empty cpu freq counters for CPUs that are physically present, but did not
+-- have a single freq event register. The time region needs to be defined so
+-- that interval_intersect doesn't remove the undefined time region.
+SELECT
+  trace_start() as ts,
+  trace_dur() as dur,
+  NULL as freq,
+  cpu,
+  NULL as policy
+FROM _dev_cpu_policy_map
+WHERE cpu NOT IN (SELECT cpu FROM first_cpu_freq_slices);
diff --git a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql
index 5c8c6b5..c2170b7 100644
--- a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql
@@ -91,4 +91,15 @@
   idle
 FROM _cpu_idle
 -- Some durations are 0 post-adjustment and won't work with interval intersect
-WHERE dur > 0;
+WHERE dur > 0
+UNION ALL
+-- Add empty cpu idle counters for CPUs that are physically present, but did not
+-- have a single idle event register. The time region needs to be defined so
+-- that interval_intersect doesn't remove the undefined time region.
+SELECT
+  trace_start() as ts,
+  trace_dur() as dur,
+  cpu,
+  NULL as idle
+FROM _dev_cpu_policy_map
+WHERE cpu NOT IN (SELECT cpu FROM first_cpu_idle_slices);