Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

Optimize ps termlet. Runs in ~1.3sec instead of ~2sec on an AMD E-350. #340

Merged
merged 6 commits into from
Aug 24, 2014
Merged

Optimize ps termlet. Runs in ~1.3sec instead of ~2sec on an AMD E-350. #340

merged 6 commits into from
Aug 24, 2014

Conversation

lwandrebeck
Copy link

No description provided.

@ferki
Copy link
Contributor

ferki commented Aug 20, 2014

This might also fix #328.

@p-e-w
Copy link
Owner

p-e-w commented Aug 20, 2014

This works like a charm (around 40% speedup on my system), and as indicated by @ferki probably fixes #328. I have a few style quibbles I'm annotating in the code but besides that, this looks good to merge!

ps "$@" |

while IFS= read -r line; do
# Position of string "PID" in line
pid_index=$(awk -v a="$line" -v b='PID' 'BEGIN{print index(a,b)}')
if [ $lnnb == 0 ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this if block header followed the style of the one below. Also note http://stackoverflow.com/questions/669452/is-preferable-over-in-bash-scripts, though it shouldn't matter much here.

@lwandrebeck
Copy link
Author

OK, I’ll rename the var. I’ll take a look at merging tests too.
I’m for now stuck with « ps e » which gets final term stuck. I’d bet that VARS=bla causes mess, but have yet to find why and where. Of course, the ps termlet executed (echo’d line being modified) in gnome-terminal runs fine, and I don’t get a single line.
Of course, it runs fine under gdb. catching on the fly a running and stuck final term with gdb gives:
0x00000036ec077c7c in g_utf8_strlen (
p=0x2a470d0 "0;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=0", max=-1) at gutf8.c:234
234 p = g_utf8_next_char (p);
(gdb) bt
#0 0x00000036ec077c7c in g_utf8_strlen (p=0x2a470d0 "0;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=0", max=-1) at gutf8.c:234
#1 0x000000000042a164 in terminal_output_text_element_explode (self=0x295beb0 [TerminalOutputTextElement])
at /home/lwandrebeck/projets/finalterm/src/TerminalOutput.vala:927
#2 0x00000000004272c4 in terminal_output_output_line_explode (self=0x29e71a0 [TerminalOutputOutputLine])
at /home/lwandrebeck/projets/finalterm/src/TerminalOutput.vala:768
#3 0x00000000004340f3 in terminal_output_view_render_terminal_cursor (self=0x26f9bc0 [TerminalOutputView])
at /home/lwandrebeck/projets/finalterm/src/TerminalView.vala:349
#4 0x0000000000433a42 in terminal_output_view_render_terminal_output (self=0x26f9bc0 [TerminalOutputView])
at /home/lwandrebeck/projets/finalterm/src/TerminalView.vala:330
#5 0x0000000000418fb3 in _terminal_output_view_render_terminal_output_utilities_schedule_function (self=0x26f9bc0)
at /home/lwandrebeck/projets/finalterm/src/Terminal.vala:118
#6 0x0000000000450065 in _lambda6 (data7=0x21eb2e0) at /home/lwandrebeck/projets/finalterm/src/Utilities.vala:213
and then gdb segfaults…
Trying to dig…

@lwandrebeck
Copy link
Author

Opened an issue for "ps e" case. See #342 .

Have rewritten ps termlet. It’s now even faster (and more commented) than the first changes, runs in under half a second :)
Hope coding style will be fine with you.
Have tried several examples, without finding any bugs.
What do you think of it ?

dir_end_mark=$(text_menu_end '2')
file_begin_mark=$(text_menu_start '1')
file_end_mark=$(text_menu_end '1')
#index=0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good optimization, with zero undesirable side effects. It seems to me that all the commented lines above are unrelated and unnecessary though. Could you please remove them?

@lwandrebeck
Copy link
Author

OK, here we are (I hope) :
Cleaned up useless lines from previous local attempts.
IFS stays as is. Using '\n' breaks output.
ps j will display PPID before PID so we would « break » if we search only for 'PID' instead of ' PID'.
PID is by default displayed without a leading space according to a quick look at procps sources. So I guess we may break at a very small uptime and no PID ≥ 1000 (can’t test as my netbook is in the 31k range), but I think it’s quite unlikely. So I’d vote to keep it as is.

@p-e-w p-e-w merged commit 30cf259 into p-e-w:master Aug 24, 2014
@p-e-w
Copy link
Owner

p-e-w commented Aug 24, 2014

Thank you, this looks and works great.

Merged! I have added your name to the about dialog credits.

@lwandrebeck
Copy link
Author

My pleasure p-e-w :)

@lwandrebeck lwandrebeck deleted the termlets branch August 24, 2014 07:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants