dkogan / feedgnuplot

Tool to plot realtime and stored data from the commandline, using gnuplot.
Other
710 stars 37 forks source link

Plot windows stealing focus preventing ctrl+c exit strategy. #37

Closed topherbuckley closed 4 years ago

topherbuckley commented 5 years ago

Issue:

Plot windows steal focus not allowing me to return to the shell prompt to ctrl+c to exit.

Expected Behavior

Run a script that pipes a stream of data to feedgunplot, it opens a window, and feeds data to it, while remaining in the background. Then, even if data stream is not finished, I can return to the bash terminal and force it to close/exit.

Background

feedgunplot v1.48 OS: Ubuntu 18.04.03 Windows Manager: Regolith based on i3wm

I'm using feedgnuplot to plot some android logcat data , and it plots everything as expected, but even after reading the --exit section of the man pages, I cannot seem to figure out how to exit the plot window without turning the data source off, or other hacky workarounds.

The reason I cannot use the typical ctrl+c exit command is that feedgnuplot seems to be creating a new window with each loop containing new data (note this is on the order of milliseconds), and my window manager is always shifting focus to this "new" window so I cannot even return to the terminal that initialized the plot window to enter the control+c command. Note this behavior also prevents me from simply force closing the plot window itself, as it will just be regenerated on the next loop. Is my understanding of the plot window generation true here (i.e. it is generating a new window with each update)? Or is it a single window, and something I need to address with my windows manager.

I can hold ctrl+c and mouse click the terminal window frantically until is slips between the millisecond loops, or I can turn off the data source then the feedgnuplot window no longer updates, and the window manager no longer forces focus there, so I can return to the terminal and control+c to close the plot window.

As I often want to open multiple plots based on the data I am seeing, I don't want to shut down my data source each time, so I am hoping for a way to prevent this feedgnuplot window from stealing focus every few milliseconds without:

The code I am using to generate the plot is as follows:

{
adb logcat -c
while true; do
        sleep 1;
        adb logcat -v raw $logcatTag *:S;
done
} | feedgnuplot --lines --stream $updateTime --exit

All the bash variables are standard strings that I set througha CLI.

dkogan commented 5 years ago

Hi. A few thoughts:

  1. feedgnuplot opens a single gnuplot process, issuing a new "plot" command with each update. If a plot window is already up, gnuplot should be reusing that window, and the window manager should not be focusing it. If no window exists already (if you closed it, for instance) then you WILL get a new window. You're saying that with each update you get a new window? (if so, what happens to the old window?) Or you're saying that the existing window is reused, but for some reason your WM is re-focusing it? Neither should be happening. Without knowing anything else, you can try other interactive gnuplot terminals ("--terminal qt" or "--terminal wxt" or "--terminal x11" in feedgnuplot).

  2. Is $updateTime really some small number of milliseconds? There should be very little reason to want to update the window that quickly, since you as a human wouldn't be able to perceive that. A slower update rate would still plot all the data, it just wouldn't do it as fast.

topherbuckley commented 5 years ago

Thanks for the speedy reply!

  1. Do you know of a way to differentiate between the two cases you mention? I checked the feedgnuplot and gnuplot processes using ps -a | grep gnu every 1 second and the PID values were not changing, so I assume this is not a "new" window as I previously assumed, but are there any other processes I should be looking for? For sure the WM is focusing on the plot windows every iteration. This is evidenced by the fact that each plot window flashes with each iteration. This is a result of my setup using i3wm and compton to highlight which window is being focused when the focus changes, and the fact that regardless of wherever I click, the mouse recenters on the plot center, and I am unable to type anything until the plots stop. I tried using the --terminal qt, or --terminal wxt or --terminal x11, but no changes to this behavior. Are these positional arguments (i.e. can I just add them to the end of my command anywhere?)
{
adb logcat -c
while true; do
        sleep 1;
        adb logcat -v raw $logcatTag *:S;
done
} | feedgnuplot --lines --stream $updateTime --exit --terminal qt
  1. Ah, I see. Yes, it is currently set to 0.001 as setting it to 0 or 'trigger' did not seem to be working (another bug?). I can set this to something a bit slower, but my data has a refresh rate of 20ms. I'll play around with this, but it does need to be quite responsive to fast fluctuations in order to be helpful for what I'm analyzing.
topherbuckley commented 4 years ago

A few more things I have tried/found out since initially posting:

I can recreate this situation with the example stream plot from your Readme, so I don't think it is anything inherently wrong with my use-case:

$ while true; do sleep 1; cat /proc/net/dev; done | gawk '/wlan0/ {if(b) {print $2-b; fflush()} b=$2}' | feedgnuplot --lines --stream --xlen 10 --ylabel 'Bytes/sec' --xlabel seconds

I also wanted to add that I don't see this type of behavior for another streaming plot (pyqtgraph). Though there are far to many differences there to blame any one thing.

Also, I though it may be due to some compton functionality interference, so I killed that process, but the issue still persists.

I tried this out on a non-i3wm desktop environment, a while back and didn't seem to have this issue.

I tried this out on a coworker's Macbook, and this issue also existed there.

Repkap11 commented 4 years ago

I had exactly the same problem. I'm also using i3 and want to quickly updating a streaming plot. I'm also looking at logcat...

I fixed this problem by adding set term x11 1 noraise to the commands sent to gnuplot. See: https://stackoverflow.com/questions/11785448/keep-gnuplot-auto-refresh-window-inactive This is possible using the --dump flag and pipes.

Heres an example:

{ echo "set term x11 1 noraise" ; while true; do sleep 0.05; cat /proc/net/dev; done | gawk '/wlan0/ {if(b) {print $2-b; fflush()} b=$2}' | feedgnuplot --lines --stream --xlen 10 --ylabel 'Bytes/sec' --xlabel seconds --exit --dump ; } | gnuplot

dkogan commented 4 years ago

Right. I don't think this is a bug with anything, just your window manager behaving in a particular way. "noraise" is a fine way to do this. By the way, you don't need the feedgnuplot --dump | gnuplot. You can feedgnuplot --terminal "x11 1 noraise" instead

dkogan commented 4 years ago

And I just tested "feedgnuplot --stream trigger" again; it works ok. If you're seeing problems, file another bug, and we can talk about your issue.

Repkap11 commented 4 years ago

No problems, just sharing my solution to this issue.

beaugunderson commented 4 years ago

Noting that on macOS --terminal "qt noraise" also works (my gnuplot doesn't support an x11 terminal type).