Page 1 of 1

"Import -window X" works with a delay

Posted: 2010-04-17T02:29:54-07:00
by Self-Perfection
Here is an example:

Code: Select all

$time import -verbose -window 0x03c0001e -pause 0 -delay 0 /dev/shm/pic.bmp
/dev/shm/pic.bmp PS 266x158 16-bit DirectClass 123KB 0.010u 0:00.009

real    0m0.821s
user    0m0.017s
sys     0m0.003s
This takes screenshot of a fairly small window, uses no compression and stores result in ramfs, all kind of pauses seems to be set to zero. Used CPU time is almost equal zero (as expected), but actual operation takes almost a second (!). This delay seems to be independent of KDE compositing being turned on or off and the size of target window. System info:

Code: Select all

13:15:43:~$ import -version
Version: ImageMagick 6.6.0-10 2010-03-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP 

13:15:46:~$ uname -a
Linux Atlantis 2.6.33-ARCH #1 SMP PREEMPT Mon Apr 5 05:57:38 UTC 2010 i686 AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ AuthenticAMD GNU/Linux

Re: "Import -window X" works with a delay

Posted: 2010-04-17T05:59:14-07:00
by magick
Add -screen to your command line. Does that resolve the delay?

Re: "Import -window X" works with a delay

Posted: 2010-04-17T07:25:59-07:00
by Self-Perfection
Actually with -screen it's even worse.

Code: Select all

17:30:35:~$ time import -verbose -screen -window $winid -pause 0 -delay 0 /dev/shm/pic-screen.bmp
/dev/shm/pic.bmp PS 266x158 1600x1200+4+23 16-bit DirectClass 123KB 0.020u 0:00.029

real    0m1.898s
user    0m1.200s
sys     0m0.137s
17:30:45:~$ time import -verbose -window $winid -pause 0 -delay 0 /dev/shm/pic.bmp
/dev/shm/pic.bmp PS 266x158 16-bit DirectClass 123KB 0.010u 0:00.009

real    0m0.819s
user    0m0.017s
sys     0m0.000s
If KDE4 desktop effects are disabled pic-screen.bmp contains what I see on the screen in place of target window, if other window overlaps target I get part of overlapping window in resulting picture.
If KDE4 desktop effects are enabled pic-screen.bmp contains what I would see on the screen in place of target window if the only windows opened were my two konsole (KDE console emulator) windows opened and brought to the active desktop.
Image
Very strange. The lower Konsole window was on second desktop but I took screenshot on first.

Re: "Import -window X" works with a delay

Posted: 2010-04-22T09:32:35-07:00
by Self-Perfection
Bump. Imagemagick version in my distro updated to 6.6.1-4 but problem remains. I checked import -window command on other PC with Ubuntu 9.10 and got the same pause. But finally I found a way to retrieve screenshot faster:

Code: Select all

$ time dash -c 'import -verbose -window 0x0420001e import.png'
import.png PS 301x231 16-bit DirectClass 16.4KB 0.100u 0:00.070

real    0m0.900s
user    0m0.107s
sys     0m0.000s
$ time dash -c 'xwd -id 0x0420001e|convert -verbose - xwd.png'
-=>/tmp/magick-XX6yNgCL XWD 301x231 301x231+0+0 8-bit DirectClass 281KB 0.000u 0:00.009
-=>xwd.png XWD 301x231 301x231+0+0 8-bit DirectClass 12.3KB 0.010u 0:00.010

real    0m0.123s
user    0m0.023s
sys     0m0.003s

Re: "Import -window X" works with a delay

Posted: 2012-02-05T12:41:39-07:00
by Self-Perfection
Version 6.7.5 and the bug is still exists. strace shows, that while import is working it stops for 0.8s at some point

Code: Select all

nanosleep({0, 800000000}, NULL) = 0 <0.800084>
I've traced this delay till XImportImage function (magick/xwindow.c). At some this function do call

Code: Select all

XDelay(display,SuspendTime << 4);
for reason I can't understand. Where does SuspendTime declared? Does XDelay at this point do anything useful?

Re: "Import -window X" works with a delay

Posted: 2012-02-05T13:29:21-07:00
by magick
We're not sure why the delay was introduced. It might have been a race condition that has long since been resolved. Comment out the delay and rebuild / reinstall ImageMagick. Does that resolve the problem?

Re: "Import -window X" works with a delay

Posted: 2012-02-07T12:57:46-07:00
by Self-Perfection
I managed to recompile imagemagick without that suspicious XDelay call - works just as fine, as with it. And, finally, fast! Woot!

Code: Select all

$ time import   -window 0x02a003fb -verbose -silent  w.bmp
w.bmp PS 562x252 16-bit DirectClass 422KB 0.020u 0:00.030

real    0m0.054s
user    0m0.033s
sys     0m0.007s
So here is may patch to resolve this issue

Code: Select all

--- magick/xwindow.c.orig       2011-12-19 05:54:26.000000000 +0400
+++ magick/xwindow.c    2012-02-07 23:07:06.679775268 +0400
@@ -4963,7 +4963,6 @@
           if ((ximage_info->frame == MagickFalse) &&
               (prior_target != MagickFalse))
             target=prior_target;
-          XDelay(display,SuspendTime << 4);
         }
     }
   if (ximage_info->screen)