brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.17k stars 615 forks source link

execbar broken #580

Closed origintopleft closed 6 years ago

origintopleft commented 6 years ago
${execbar "echo 'scale=2; 51/100' | bc -q"}
${execbar "echo .51"}
${execbar "echo 51"}

all return empty bars, with and without the extra quoting around the whole command. cpubar works fine.

conky 1.10.8, Gentoo Linux.

conky 1.10.8 compiled Thu Jul 12 21:56:59 PDT 2018 for Linux 4.17.4-gentoo-ishimura x86_64

Compiled in features:

System config file: /etc/conky/conky.conf
Package library path: /usr/lib64/conky

 General:
  * portmon
  * IPv6
  * iconv
  * wireless
  * builtin default configuration
  * Imlib2
  * iostats
  * ncurses
  * Internationalization support
  * PulseAudio

 Lua bindings:
  * Cairo
  * Imlib2
 X11:
  * Xdamage extension
  * Xinerama extension (virtual display)
  * Xshape extension (click through)
  * XDBE (double buffer extension)
  * Xft
  * ARGB visual
  * Own window

 Default values:
  * Netdevice: eth0
  * Local configfile: $HOME/.conkyrc
  * Localedir: /usr/share/locale
  * Maximum netdevices: 64
  * Maximum text size: 16384
  * Size text buffer: 256
su8 commented 6 years ago

Turning @lasers code into 1 liners.

conky.config = {
    out_to_x=true,
    out_to_console=false,
    own_window=true,
    update_interval=1,
    default_bar_width=500,
}
conky.text = [[
    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(10,99))'}
    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(11,99))'}
    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(12,99))'}
]]
lasers commented 6 years ago

@su8 We're almost there. What do we do with this issue?

su8 commented 6 years ago

The information get's lost inside evaluate(buffer, p, p_max_size);, and I don't know why. Used multiple printf() calls to track the issue, but nothing turns out to be problematic.

lasers commented 6 years ago

Is it possible to skip updating the bar on empty lines?

su8 commented 6 years ago
diff --git a/src/exec.cc b/src/exec.cc
index bc6bf47b..d3044d63 100644
--- a/src/exec.cc
+++ b/src/exec.cc
@@ -192,6 +192,7 @@ static void remove_deleted_chars(char *string) {
  * @param[in] buf output of a command executed by an exec_cb object
  * @return number between 0.0 and 100.0
  */
+static double cached_result = 0.0;
 static inline double get_barnum(const char *buf) {
   double barnum;

@@ -199,7 +200,7 @@ static inline double get_barnum(const char *buf) {
     NORM_ERR(
         "reading exec value failed (perhaps it's not the "
         "correct format?)");
-    return 0.0;
+    return cached_result;
   }
   if (barnum > 100.0 || barnum < 0.0) {
     NORM_ERR(
@@ -208,6 +209,7 @@ static inline double get_barnum(const char *buf) {
     return 0.0;
   }

+  cached_result = barnum;
   return barnum;
 }
lasers commented 6 years ago

Looks good to me. Maybe we shouldn't NORM_ERR on empty lines? And leave a small comment there too... don't reset execbars on invalid values. see #580 ?

su8 commented 6 years ago

Go ahead and open up a new PR with those changes.

lasers commented 6 years ago

I don't know how to C++. :)

lasers commented 6 years ago

Maybe it should be one or two time cache use? What if the song is not playing anymore? Will it keep printing the cached_result because it's now getting empty lines?

su8 commented 6 years ago

Whenever the result is correct the variable will be updated to that result, so 0.0 is correct one as well as 100.0

lasers commented 6 years ago

@su8 One issue down? :heart_eyes_cat:

@lavacano201014 Please test #646 asap to make this problem go away. Thx. :smile_cat:

lasers commented 6 years ago

Closed via #646.

origintopleft commented 6 years ago

it works! thank you

j4nu5 commented 5 years ago

@lasers @su8 I think #646 does not really solve the problem and in fact causes another problem:

I have a dynamic list of execbars:

${exec tail -n1 /tmp/build-logs/*.status | egrep "^[0-9]+$" | awk '{print "${execbar echo " $0 "}"}'}
${execp tail -n1 /tmp/build-logs/*.status | egrep "^[0-9]+$" | awk '{print "${execbar echo " $0 "}"}'}

(The exec line is for referencing the real value for the bar for debugging).

646 Caching the result of execbars makes them display incorrect progress information. Specifically, some of the progress bars use previous values from other progress bars. Attaching a gif for reference.

conky

@lasers Requesting to re-open the issue.

lasers commented 5 years ago

@j4nu5 Can you paste the gif config?

lasers commented 5 years ago

@j4nu5 I think this might be the https://github.com/brndnmtthws/conky/issues/580#issuecomment-411788147 issue where all ${...} are identical.

j4nu5 commented 5 years ago

@j4nu5 Can you paste the gif config?

conky.config = {
    alignment = 'top_right',
    background = false,
    border_width = 1,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    draw_borders = false,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = false,
    use_xft = true,
    font = 'FuraMono Nerd Font Medium:size=12',
    gap_x = 5,
    gap_y = 60,
    minimum_height = 5,
    minimum_width = 400,
    maximum_width = 400,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    double_buffer = true,
    own_window = true,
    own_window_transparent = true,
    own_window_argb_visual = true,
    own_window_class = 'Conky',
    own_window_type = 'panel',
    stippled_borders = 0,
    update_interval = 1.0,
    uppercase = false,
    use_spacer = 'none',
    show_graph_scale = false,
    show_graph_range = false
}

conky.text = [[
${scroll 50 $nodename - $sysname $kernel on $machine | }
$hr
${color grey}Uptime:$color $uptime
${color grey}Frequency (in MHz):$color $freq
${color grey}Frequency (in GHz):$color $freq_g
${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}
${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}
${color grey}CPU Usage:$color $cpu% ${cpubar 4}
${color grey}Processes:$color $processes  ${color grey}Running:$color $running_processes
$hr
${color grey}File systems:
 / $color${fs_used /}/${fs_size /} ${fs_bar 6 /}
${color grey}Networking:
Up:$color ${upspeed eth0} ${color grey} - Down:$color ${downspeed eth0}
$hr
${color grey}Name              PID   CPU%   MEM%
${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
$hr
Builds
${exec tail -n1 /tmp/build-logs/*.status | egrep "^[0-9]+$" | awk '{print "${execbar echo " $0 "}"}'}
${execp tail -n1 /tmp/build-logs/*.status | egrep "^[0-9]+$" | awk '{print "${execbar echo " $0 "}"}'}

${exec tail -v -n5 /tmp/build-logs/*.log}
]]

I don't think there is anything special in my config except:

${exec tail -n1 /tmp/build-logs/*.status | egrep "^[0-9]+$" | awk '{print "${execbar echo " $0 "}"}'}
${execp tail -n1 /tmp/build-logs/*.status | egrep "^[0-9]+$" | awk '{print "${execbar echo " $0 "}"}'}
j4nu5 commented 5 years ago

Just to be clear: I have long running builds that post their build progress to /tmp/build-logs/*.status I am tailing those files and fetching this number to draw a bunch of progress bars.

You may have to write another bunch of shell scripts to post a series of monotonically increasing % numbers to /tmp/build-logs/*.status if you want to use my exact config.

j4nu5 commented 5 years ago

@j4nu5 I think this might be the #580 (comment) issue where all ${...} are identical.

@lasers Hmm, not sure. To me, #646 seems like the root cause (for the progress bar value re-use at least).

lasers commented 5 years ago

Try https://github.com/brndnmtthws/conky/issues/580#issuecomment-412919751. Random bars, then with this diff... you get all same bars... which might be similar to yours because of same exec* keys in the config.

I think that it is the issue. If you place them in scripts, then you may have working bars.

diff --git a/wow b/wow2
index 619d2f5..997f166 100644
--- a/wow
+++ b/wow2
@@ -7,6 +7,6 @@ conky.config = {
 }
 conky.text = [[
     ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(10,99))'}
-    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(11,99))'}
-    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(12,99))'}
+    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(10,99))'}
+    ${execp python -c 'from random import randint;print("BAR: ${execbar echo %s}" % randint(10,99))'}
 ]]
lasers commented 5 years ago

@j4nu5 Can you make a new issue and we'll continue there? To be sure, you can try reverting that commit (or drop the cache code)... to see it's still happening.