Profiling Cygwin

There are a couple of steps you need to do to profile cygwin itself (newlib and winsup). This is preliminary documentation but ought to be applicable to the Beta 20.1 net release. Don't expect things to go smoothly.

From the Cygwin development tools source distribution, configure, build, and install gprof.

Delete all of your .o's in newlib and winsup. Rebuild them all with profiling options:

make -k -w CFLAGS='-pg -O2 -g' CXXFLAGS='-pg -O2 -g'

Note: the dll builds will fail; this is OK. You're not going to use those dlls. Make sure you have a working cygwin.dll available and do not touch or rename it. You'll need it.

OK, now go into winsup and delete mcount.o, gcrt0.o, gmon.o, and profil.o. Rebuild those without -pg. It is possible that mcount.c must be built without -O (this was a problem once, at least) - so just use -g for that one.

Next, you need to build new libraries for newlib and winsup that contain these objects. Here's a script to do it.

You will also need a standalone malloc package. Here's one from djgpp that we modified to work for this context.

Now that you have libcpg.a, libwinpg.a, and malloc.o, you can build your programs like this:

CFLAGS = -g -pg -O2

D = djmalloc.o libwinpg.a libcpg.a libwinpg.a

test.exe : test.c $D
	gcc -pg -g -o test.exe test.c $D -lgdi32 -luser32

gmon.out : test.exe
	./test.exe : gmon.out
	gprof -b test.exe >