Skip to content

Commit

Permalink
Merge "Speed up dmabuf query" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkos authored and Gerrit Code Review committed Oct 4, 2024
2 parents 30881e3 + 45ee619 commit e5a4160
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/trace_processor/perfetto_sql/stdlib/android/memory/dmabuf.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

INCLUDE PERFETTO MODULE android.binder;
INCLUDE PERFETTO MODULE slices.with_context;

-- Raw ftrace events
CREATE PERFETTO TABLE _raw_dmabuf_events AS
SELECT
Expand All @@ -29,25 +26,33 @@ WHERE tt.name = 'mem.dma_heap_change';

-- gralloc binder reply slices
CREATE PERFETTO TABLE _gralloc_binders AS
WITH gralloc_threads AS (
SELECT utid
FROM process JOIN thread USING (upid)
WHERE process.name GLOB '/vendor/bin/hw/android.hardware.graphics.allocator*'
)
SELECT
id AS gralloc_binder_reply_id,
utid,
ts,
dur
FROM thread_slice
WHERE process_name GLOB '/vendor/bin/hw/android.hardware.graphics.allocator*'
AND name = 'binder reply';
flow.slice_out AS client_slice_id,
gralloc_slice.ts,
gralloc_slice.dur,
thread_track.utid
FROM slice gralloc_slice
JOIN thread_track ON gralloc_slice.track_id = thread_track.id
JOIN gralloc_threads USING (utid)
JOIN flow ON gralloc_slice.id = flow.slice_in
WHERE gralloc_slice.name = 'binder reply'
;

-- Match gralloc thread allocations to inbound binders
CREATE PERFETTO TABLE _attributed_dmabufs AS
SELECT
r.inode,
r.ts,
r.buf_size,
IFNULL(b.client_utid, r.utid) AS attr_utid
IFNULL(client_thread.utid, r.utid) AS attr_utid
FROM _raw_dmabuf_events r
LEFT JOIN _gralloc_binders gb ON r.utid = gb.utid AND r.ts BETWEEN gb.ts AND gb.ts + gb.dur
LEFT JOIN android_binder_txns b ON gb.gralloc_binder_reply_id = b.binder_reply_id
LEFT JOIN thread_track client_thread ON gb.client_slice_id = client_thread.id
ORDER BY r.inode, r.ts;

CREATE PERFETTO FUNCTION _alloc_source(is_alloc BOOL, inode INT, ts INT)
Expand Down

0 comments on commit e5a4160

Please sign in to comment.