p-e-w / finalterm

At last – a modern terminal emulator (NO LONGER MAINTAINED)
http://finalterm.org
GNU General Public License v3.0
3.84k stars 179 forks source link

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

Closed lwandrebeck closed 9 years ago

ferki commented 9 years ago

This might also fix #328.

p-e-w commented 9 years ago

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!

lwandrebeck commented 9 years ago

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_utf8strlen ( 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_utf8strlen (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 commented 9 years ago

Opened an issue for "ps e" case. See https://github.com/p-e-w/finalterm/issues/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 ?

lwandrebeck commented 9 years ago

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 commented 9 years ago

Thank you, this looks and works great.

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

lwandrebeck commented 9 years ago

My pleasure p-e-w :)