This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: time:ing non-cygwin apps


The stats time.exe is giving you is likely the CPU time consumed
by the hidden bash.exe rather than the time consumed by your own
native win32 app.  Which would explain the discrepancy in the result.

Let me explain...

As you said, when you compile with -mno-cygwin, you get a native
win32 executable.  It doesn't depend on cygwin1.dll

The behavior I've observed is that when bash runs a native win32
process, it does a fork/exec maneuver just like it normally would
to start any child process.  The result is that you get a hidden
bash.exe process.  I say "hidden" because it doesn't show up in a
"ps" but an extra bash.exe does show up in WinNT/Win2k Task Manager.
Furthermore, a "ps" reveals that the native win32 program you just
started gets assigned PID=WINPID=the-pid-of-the-hidden-bash.exe

I have studied cygwin's fork/exec code and it looks like this
is the clever way that cygwin gets around the fact that Win32's
CreateProcess and friends don't really support the idea of
a process changing its identity midstream... which is exactly
what exec, execvp, etc. accomplish for you on Unix.
It's really quite ingenious how cygwin does it.  I am impressed.

But it makes for a few strange interactions with native win32 apps,
because you always have this hidden bash.exe process that is sort
of a proxy between the parent and child.
The time.exe thing you are seeing is only one of them.  Another odd
symptom is that when the "hidden" bash.exe gets a SIGINT from its
parent it terminates your native win32 app before it gets a
chance to run its CTRL-C and CTRL-BREAK handler (or signal handler
if you tried to use that approach), which is bad if you've got
some cleanup code in your native win32 app that needs to happen
before the process exits.  Or if you're running Sun's
JVM which attempts to dump a stack trace when it gets a
CTRL-BREAK on the console.

I won't go into more details now... I don't want to get flamed
too badly at this point.  I have a couple of ideas regarding how
to overcome this issue, but want to do some more experimenting
before I propose them to the developers or submit a patch or whatnot.
Hopefully if any of the above is incorrect the cygwin developers
can set me straight... since they've got much more history with this
stuff than I do.

"I am not a cygwin developer or maintainer, just an interested
user."  Thought I should clarify that lest you think I was
speaking no behalf of anyone on the cygwin list besides myself ;->

Troy

-----Original Message-----
From: Jesper Eskilson [mailto:jojo@virtutech.se]
Sent: Wednesday, September 05, 2001 4:55 AM
To: Cygwin Mailinglist
Subject: time:ing non-cygwin apps



Hi,

I'm trying to get some useful information about the execution time of
non-cygwin app. To illustrate, run the following shell-script:

--[ cygwintime.sh ]--

#!/bin/bash

cat > foo.c <<EOF
int main() {
  int i;
  for (i=0; i < 1000000000; i++);
}
EOF

gcc foo.c -o foo-cygwin
gcc -mno-cygwin foo.c -o foo-native

time ./foo-cygwin
time ./foo-native

--[ ... ]--

On my machine, I get the following output:

[0][SEBASTIAN] ~ -> ./cygwintime.sh

real    0m4.426s
user    0m4.346s
sys     0m0.010s

real    0m4.006s
user    0m0.010s
sys     0m0.010s
[0][SEBASTIAN] ~ ->


Note that the -mno-cygwin application takes almost no user or sys
time, but several seconds real time, as if the time command is unable
to report the time of non-cygwin applications. 

Naturally, I'd like to get similar results in both cases. Is there any
way I can get round this? (Is it a bug or a feature? ;-))

/Jesprer
-- 
-------------------------------------------------------------------------
Jesper Eskilson                                         jojo@virtutech.se
Virtutech                                         http://www.virtutech.se
-------------------------------------------------------------------------

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]