samedi 1 juin 2013

xmobar idiocy : do not poll for constant values periodically (or at least do it very slowly)

Out of curiosity, I wanted to see if I needed to `sudo htop` to be
 able to strace a process from within. I picked the most mundane one,
 my second instance of xmobar.

 There's an awful lot of things happening (signals, clock, syscalls..), so I decide to run strace externally to keep only easy to follow syscalls like `read`, `open`:

    $ strace -p `pgrep xmobar | tail -n1` -e read 2>&1 | less

 now inside less you type `&/read` and enjoy the input received by
 xmobar to populate the string template you'll see on screen. Cool.

 Still an awful lot happening

 read(7, "dummy\n", 8096)                = 6
 read(7, "dummy\n", 8096)                = 6
 read(7, "dummy\n", 8096)                = 6
 read(7, "dummy\n", 8096)                = 6
 read(7, "dummy\n", 8096)                = 6
 read(7, "dummy\n", 8096)                = 6
 read(7, "dummy\n", 8096)                = 6
 ...
 read(7, "CK:2728 :: LK:3620", 8096)     = 18 (yes, that's a
 narcissistic reddit karma probe)


 And then I realize that my configuration is absurdly periodically
 polling for constants like `uname` or `whoami`.

 Indeed, here's the haskell code :

 , Run Com "uname" ["-s","-r"] "os" 0
 , Run Com "whoami" [] "who" 0
 , Run Com "/home/dummy/bin/reddit.sh" [] "reddit" 600
 , Run Com "/home/dummy/bin/hackernews" [] "hackernews" 600


So I change the frequency to a large value

 , Run Com "uname" ["-s","-r"] "os" 6000
 , Run Com "whoami" [] "who" 6000
 , Run Com "/home/dummy/bin/reddit.sh" [] "reddit" 600
 , Run Com "/home/dummy/bin/hackernews" [] "hackernews" 600


And, now nothing (almost) happens.

 read(7, "dummy\n", 8096)                = 6
 read(7, "CK:2728 :: LK:3620", 8096)     = 18
 read(7, "", 8096)                       = 0
 read(7, "[0|up to date]\n", 8096)       = 15
 read(7, "[0|up to date]\n", 8096)       = 15
 read(7, "Linux 3.9.4-1-ARCH\n", 8096)   = 19
 # 5 minutes pause
 read(7, "dummy\n", 8096)                = 6
 read(7, "CK:2728 :: LK:3620", 8096)     = 18
 read(7, "", 8096)                       = 0
 read(7, "[0|up to date]\n", 8096)       = 15
 read(7, "[0|up to date]\n", 8096)       = 15
 read(7, "Linux 3.9.4-1-ARCH\n", 8096)   = 19


 It might be unrelated, but for the first time since I used
 xmonad/xmobar I now witness CPU usage below 2% stable, even 0% for
 small period of time. (three times along writing this paragraph)

 <idiot/>

update: 04-10-2013

I just did a little RTFM/Googling to find if xmobar supported a run-once option, and indeed jaort added a way to instruct xmobar to do so. Just use Run Com with a frequency of 0 and it won't run the process again. I re-installed archlinux and for a reason I cannot attach strace to xmobar, but htop can and doesn't show the same amount of activity as before. There's two dozen of waitpid, that are probably a polling policy of xmobar to wait for the process output.. but nothing incoherent. That said, my cpu doesn't reach the 0% of activity as much. <idiot><lost/></idiot>


Aucun commentaire:

Enregistrer un commentaire