Skip to content

Commit a094708

Browse files
committed
initviz: add support for searching for processes
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 00e3696 commit a094708

File tree

2 files changed

+333
-1
lines changed

2 files changed

+333
-1
lines changed

initviz/draw.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, app_options):
3333
self.charts = True
3434
self.kernel_only = False
3535
self.app_options = app_options
36+
self.search_query = None # Search query for highlighting processes
3637

3738
def proc_tree (self, trace):
3839
if self.kernel_only:
@@ -282,6 +283,7 @@ def transform_point_coords(point, x_base, y_base, \
282283
MIN_IMG_W = 800
283284
CUML_HEIGHT = 2000 # Increased value to accomodate CPU and I/O Graphs
284285
OPTIONS = None
286+
RENDER_OPTIONS = None
285287

286288
def extents(options, xscale, trace):
287289
proc_tree = options.proc_tree(trace)
@@ -389,8 +391,9 @@ def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
389391
#
390392
def render(ctx, options, xscale, trace):
391393
(w, h) = extents (options, xscale, trace)
392-
global OPTIONS
394+
global OPTIONS, RENDER_OPTIONS
393395
OPTIONS = options.app_options
396+
RENDER_OPTIONS = options
394397

395398
proc_tree = options.proc_tree(trace)
396399

@@ -513,12 +516,38 @@ def draw_header (ctx, headers, boot_time):
513516

514517
return header_y
515518

519+
def process_matches_search(proc, search_query):
520+
"""Check if a process matches the search query"""
521+
if not search_query:
522+
return False
523+
search_lower = search_query.lower()
524+
if search_lower in proc.cmd.lower():
525+
return True
526+
if proc.exe and search_lower in proc.exe.lower():
527+
return True
528+
if proc.args:
529+
for arg in proc.args:
530+
if search_lower in arg.lower():
531+
return True
532+
return False
533+
516534
def draw_processes_recursively(ctx, proc, proc_tree, y, proc_h, rect, clip, exit_proc_pos=None) :
517535
x = rect[0] + ((proc.start_time - proc_tree.start_time) * rect[2] / proc_tree.duration)
518536
w = ((proc.duration) * rect[2] / proc_tree.duration)
519537

520538
draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect, clip)
521539
draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h))
540+
541+
# Highlight if process matches search query
542+
if RENDER_OPTIONS and RENDER_OPTIONS.search_query and process_matches_search(proc, RENDER_OPTIONS.search_query):
543+
# Draw a bright yellow/orange border around matching processes
544+
highlight_color = (1.0, 0.7, 0.0, 1.0) # Orange
545+
ctx.set_source_rgba(*highlight_color)
546+
ctx.set_line_width(3)
547+
ctx.rectangle(x, y, w, proc_h)
548+
ctx.stroke()
549+
ctx.set_line_width(1)
550+
522551
ipid = int(proc.pid)
523552
if not OPTIONS.show_all:
524553
cmdString = proc.cmd

0 commit comments

Comments
 (0)