Skip to content

Commit 72aa229

Browse files
authored
Merge branch 'main' into fix/high_glibc_attach
2 parents da11145 + 643a701 commit 72aa229

19 files changed

+469
-82
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code owners for this repository
2+
# These users will be requested for review when someone opens a pull request
3+
4+
# Default owners for everything in the repo
5+
* @bppps

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ setup.py
88
.vscode/*
99
*.iml
1010
.qoder/*
11-
.demo/*

flight_profiler/help_descriptions.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
from flight_profiler.utils.env_util import is_linux
1313
from flight_profiler.utils.render_util import (
14+
BOX_HORIZONTAL,
15+
BOX_T_RIGHT,
1416
COLOR_BOLD,
1517
COLOR_BRIGHT_GREEN,
1618
COLOR_END,
19+
COLOR_FAINT,
1720
COLOR_WHITE_255,
21+
ICON_ARROW,
1822
align_prefix,
1923
)
2024

@@ -49,32 +53,36 @@ def help_hint(self) -> str:
4953
return self._help
5054

5155
def _build_help_msg(self) -> str:
56+
# Section title style
57+
section_prefix = f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}{BOX_T_RIGHT}{BOX_HORIZONTAL}"
58+
section_suffix = f"{COLOR_END}"
59+
5260
usage = ""
5361
for single_usage in self._usage:
54-
usage += f" {COLOR_WHITE_255}{single_usage}{COLOR_END}\n"
62+
usage += f" {COLOR_WHITE_255}{ICON_ARROW} {single_usage}{COLOR_END}\n"
5563
examples = ""
5664
for single_example in self._examples:
57-
examples += f" {COLOR_WHITE_255}{single_example}{COLOR_END}\n"
65+
examples += f" {COLOR_FAINT}{ICON_ARROW}{COLOR_END} {COLOR_WHITE_255}{single_example}{COLOR_END}\n"
5866
options = ""
5967
if self._options is not None:
6068
for option in self._options:
61-
options += f"{COLOR_WHITE_255}{option[0].ljust(self._option_offset)}{align_prefix(self._option_offset, option[1])}{COLOR_END}\n"
69+
options += f" {COLOR_WHITE_255}{option[0].ljust(self._option_offset)}{align_prefix(self._option_offset + 2, option[1])}{COLOR_END}\n"
6270

6371
wiki_description = ""
6472
if self._wiki is not None:
6573
wiki_description = (
66-
f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}WIKI:{COLOR_END}\n"
74+
f"{section_prefix} WIKI{section_suffix}\n"
6775
f" {COLOR_WHITE_255}{self._wiki}{COLOR_END}\n\n"
6876
)
6977
return (
70-
f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}USAGE:{COLOR_END}\n"
78+
f"{section_prefix} USAGE{section_suffix}\n"
7179
f"{usage}\n"
72-
f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}SUMMARY:{COLOR_END}\n"
80+
f"{section_prefix} SUMMARY{section_suffix}\n"
7381
f" {COLOR_WHITE_255}{self._summary}{COLOR_END}\n\n"
74-
f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}EXAMPLES:{COLOR_END}\n"
82+
f"{section_prefix} EXAMPLES{section_suffix}\n"
7583
f"{examples}\n"
7684
f"{wiki_description}"
77-
f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}OPTIONS:{COLOR_END}\n"
85+
f"{section_prefix} OPTIONS{section_suffix}\n"
7886
f"{options}"
7987
)
8088

flight_profiler/plugins/getglobal/server_plugin_getglobal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
GetGlobalParser,
88
)
99
from flight_profiler.plugins.server_plugin import Message, ServerPlugin, ServerQueue
10+
from flight_profiler.utils.render_util import build_error_message
1011

1112

1213
class GetGlobalServerPlugin(ServerPlugin):
@@ -27,7 +28,7 @@ async def do_action(self, param):
2728
)
2829
except:
2930
self.out_q.output_msg_nowait(
30-
Message(True, pickle.dumps(traceback.format_exc()))
31+
Message(True, pickle.dumps(build_error_message(traceback.format_exc())))
3132
)
3233

3334

flight_profiler/plugins/help/help_agent.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
)
2222
from flight_profiler.utils.env_util import py_higher_than_314, readline_enable
2323
from flight_profiler.utils.render_util import (
24+
BOX_HORIZONTAL,
25+
CMD_ICON_HELP,
2426
COLOR_BOLD,
2527
COLOR_BRIGHT_GREEN,
2628
COLOR_END,
29+
COLOR_FAINT,
2730
COLOR_WHITE_255,
2831
align_prefix,
32+
get_command_icon,
33+
ljust_display,
2934
)
3035

3136
HELP_COMMANDS_DESCRIPTIONS: List[CommandDescription] = [
@@ -86,12 +91,21 @@ def __init__(self):
8691

8792
def display_all_commands(self):
8893
"""
89-
help default show all command
94+
help default show all command with icons
9095
"""
9196
display_msg = ""
92-
display_msg += f"{COLOR_WHITE_255}{COLOR_BOLD}{'NAME':<15}{align_prefix(15, 'DESCRIPTION')}{COLOR_END}\n"
97+
# Header with icon
98+
display_msg += f"{COLOR_BRIGHT_GREEN}{COLOR_BOLD}{CMD_ICON_HELP} [AVAILABLE COMMANDS]{COLOR_END}\n"
99+
display_msg += f"{COLOR_FAINT}{BOX_HORIZONTAL * 25}{COLOR_END}\n"
100+
# Column headers
101+
display_msg += f"{COLOR_WHITE_255}{COLOR_BOLD}{'':3}{'NAME':<12}{'DESCRIPTION'}{COLOR_END}\n"
93102
for c_idx in range(len(HELP_COMMANDS_NAMES)):
94-
display_msg += f"{COLOR_BRIGHT_GREEN}{HELP_COMMANDS_NAMES[c_idx]:<15}{COLOR_END}{align_prefix(15, HELP_COMMANDS_DESCRIPTIONS[c_idx].summary)}\n"
103+
cmd_name = HELP_COMMANDS_NAMES[c_idx]
104+
cmd_icon = get_command_icon(cmd_name)
105+
# Use ljust_display to handle emoji width correctly
106+
icon_part = ljust_display(cmd_icon, 2)
107+
name_part = ljust_display(cmd_name, 12)
108+
display_msg += f"{COLOR_FAINT}{icon_part}{COLOR_END} {COLOR_BRIGHT_GREEN}{name_part}{COLOR_END}{align_prefix(15, HELP_COMMANDS_DESCRIPTIONS[c_idx].summary)}\n"
95109
return display_msg
96110

97111
def get_command_description(self, command_name: str) -> str:

flight_profiler/plugins/perf/cli_plugin_perf.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
from flight_profiler.help_descriptions import PERF_COMMAND_DESCRIPTION
66
from flight_profiler.plugins.cli_plugin import BaseCliPlugin
77
from flight_profiler.plugins.perf.perf_parser import PerfParams, global_perf_parser
8-
from flight_profiler.utils.cli_util import show_error_info, show_normal_info
8+
from flight_profiler.utils.cli_util import (
9+
show_error_info,
10+
show_info_with_icon,
11+
show_normal_info,
12+
show_success_info,
13+
)
914
from flight_profiler.utils.env_util import is_linux
10-
from flight_profiler.utils.render_util import COLOR_GREEN
1115

1216

1317
class PerfCliPlugin(BaseCliPlugin):
@@ -44,7 +48,7 @@ def __dump_to_flamegraph(self, params: PerfParams, cmd: str):
4448
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
4549
)
4650
try:
47-
show_normal_info(f"Press Control-C to exit.")
51+
show_info_with_icon("Press Control-C to exit.")
4852
self.__capture_process(process, params)
4953
except KeyboardInterrupt:
5054
process.send_signal(signal.SIGINT)
@@ -53,8 +57,8 @@ def __dump_to_flamegraph(self, params: PerfParams, cmd: str):
5357
def __capture_process(self, process: subprocess.Popen, params: PerfParams) -> None:
5458
stdout, stderr = process.communicate()
5559
if process.returncode == 0:
56-
show_normal_info(
57-
f" Flamegraph data has been successfully written to {COLOR_GREEN}{params.filepath}!"
60+
show_success_info(
61+
f"Flamegraph data has been successfully written to {params.filepath}!"
5862
)
5963
else:
6064
show_error_info(stderr.decode())

flight_profiler/plugins/stack/cli_plugin_stack.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from flight_profiler.help_descriptions import STACK_COMMAND_DESCRIPTION
66
from flight_profiler.plugins.cli_plugin import BaseCliPlugin
77
from flight_profiler.plugins.stack.stack_parser import StackParams, global_stack_parser
8-
from flight_profiler.utils.cli_util import show_error_info
8+
from flight_profiler.utils.cli_util import show_error_info, show_success_info
99
from flight_profiler.utils.env_util import is_linux
10-
from flight_profiler.utils.render_util import COLOR_END, COLOR_GREEN
1110

1211

1312
class StackCliPlugin(BaseCliPlugin):
@@ -52,8 +51,8 @@ def __analyze_under_linux(self, params: StackParams):
5251
for line in thread_lines:
5352
print(line, file=f, flush=True)
5453
stack_literal = "native stack" if params.native else "stack"
55-
print(
56-
f"{COLOR_GREEN}write {stack_literal} to {params.filepath} successfully!{COLOR_END}"
54+
show_success_info(
55+
f"Write {stack_literal} to {params.filepath} successfully!"
5756
)
5857

5958
def __show_coroutine_stacks(self, params: StackParams):
@@ -80,8 +79,8 @@ def __show_coroutine_stacks(self, params: StackParams):
8079
with open(params.filepath, "w") as f:
8180
for line in coro_lines:
8281
print(line, file=f, flush=True)
83-
print(
84-
f"{COLOR_GREEN}write coroutine stacks to {params.filepath} successfully!{COLOR_END}"
82+
show_success_info(
83+
f"Write coroutine stacks to {params.filepath} successfully!"
8584
)
8685
finally:
8786
client.close()
@@ -122,8 +121,8 @@ def do_action(self, cmd):
122121
if line:
123122
line = line.decode("utf-8")
124123
f.write(line + "\n")
125-
print(
126-
f"{COLOR_GREEN}write stack to {file_name} successfully!{COLOR_END}"
124+
show_success_info(
125+
f"Write stack to {file_name} successfully!"
127126
)
128127
else:
129128
for line in client.request_stream(body):

flight_profiler/plugins/trace/cli_plugin_trace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def do_action(self, cmd):
5555
else:
5656
wrap: Union[WrapTraceFrame, str] = pickle.loads(content)
5757
if type(wrap) == str:
58-
# error
59-
show_error_info(wrap)
58+
# String message (e.g., spy command hint)
59+
print(wrap)
6060
continue
6161
if (
6262
len(wrap.frames) > 0

flight_profiler/plugins/trace/server_plugin_trace.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from flight_profiler.plugins.trace.trace_agent import TracePoint, global_trace_agent
66
from flight_profiler.plugins.trace.trace_parser import TraceArgumentParser
77
from flight_profiler.utils.args_util import split_regex
8+
from flight_profiler.utils.render_util import build_error_message
89

910

1011
class TraceServerPlugin(ServerPlugin):
@@ -24,7 +25,7 @@ async def do_action(self, param):
2425
global_trace_agent.set_point(point)
2526
# will not return end message, server request will block
2627
except:
27-
await self.out_q.output_msg(Message(True, pickle.dumps(traceback.format_exc())))
28+
await self.out_q.output_msg(Message(True, pickle.dumps(build_error_message(traceback.format_exc()))))
2829
elif splits[0] == "off":
2930
new_param = param[len(splits[0]) :]
3031
try:
@@ -33,9 +34,9 @@ async def do_action(self, param):
3334
global_trace_agent.clear_point(point)
3435
await self.out_q.output_msg(Message(True, None))
3536
except:
36-
await self.out_q.output_msg(Message(True, pickle.dumps(traceback.format_exc())))
37+
await self.out_q.output_msg(Message(True, pickle.dumps(build_error_message(traceback.format_exc()))))
3738
else:
38-
await self.out_q.output_msg(Message(True, pickle.dumps("trace param is illegal.")))
39+
await self.out_q.output_msg(Message(True, pickle.dumps(build_error_message("trace param is illegal."))))
3940

4041

4142
def get_instance(cmd: str, out_q: ServerQueue):

flight_profiler/plugins/trace/trace_render.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
)
99
from flight_profiler.utils.frame_util import global_filepath_operator
1010
from flight_profiler.utils.render_util import (
11+
BOX_HORIZONTAL,
12+
CMD_ICON_TRACE,
1113
COLOR_AWAIT,
1214
COLOR_BRIGHT_GREEN,
1315
COLOR_END,
@@ -76,9 +78,14 @@ def display(self, wrap: WrapTraceFrame) -> str:
7678
concat full frame stack
7779
"""
7880
try:
81+
cost_ms = wrap.frames[0].cost_ns / 1000000
7982
title: str = (
80-
f"{COLOR_WHITE_255}{time_ns_to_formatted_string(wrap.frames[0].start_ns)};thread_name={wrap.thread_name}"
81-
f";thread_id={wrap.thread_id};is_daemon={wrap.is_daemon};cost={wrap.frames[0].cost_ns / 1000000}ms{COLOR_END}\n"
83+
f"{COLOR_FAINT}{BOX_HORIZONTAL * 60}{COLOR_END}\n"
84+
f"{CMD_ICON_TRACE} {COLOR_WHITE_255}{time_ns_to_formatted_string(wrap.frames[0].start_ns)}{COLOR_END} "
85+
f"{COLOR_FAINT}thread={COLOR_END}{wrap.thread_name} "
86+
f"{COLOR_FAINT}tid={COLOR_END}{wrap.thread_id} "
87+
f"{COLOR_FAINT}daemon={COLOR_END}{wrap.is_daemon} "
88+
f"{COLOR_FAINT}cost={COLOR_END}{COLOR_WHITE_255}{cost_ms:.3f}ms{COLOR_END}\n"
8289
)
8390
frame: FlattenTreeTraceFrame = self.preprocess_frame(
8491
build_frame_stack(wrap.frames)

0 commit comments

Comments
 (0)