Testers for lang/ruby18 with Profile-Guided Optimization

Mario Sergio Fujikawa Ferreira lioux at FreeBSD.org
Sat Feb 28 07:37:25 PST 2009


	I did some work on the lang/ruby18 to enable Profile-Guided
Optimization (PGO) build support.

	What I did? (Steps 1-4 handled by pgo port target).

------- RECIPE
	1) Compile everything with CFLAGS/LDFLAGS containing

	2) Run lots of test cases to generate profiling information
	   (make check);

	3) Remove all binaries leaving only the profiling information behind;

	4) Replace all instances of '-fprofile-generate' with

	5) Re-compile everything using the profiling information.

	If I did it correctly, you should not notice any differences
on port usage aside from PGO option and a huge build compilation
time. Please, verify if you can that I did all steps of the "RECIPE"

	I am not a ruby expert so I would like input on this one:

	1) Does it perform better than ruby18 compiled without PGO?
	   Hard number benchmarks welcome. Check

	2) Also, could others run specification conformance
	   verification checks on the resulting ruby interpreter?
	   So that we have multiple cross verification. Perhaps,
	   with rubyspec?

	I hope you find this useful and that it performs as expected.
I want to go after lang/ruby19. Perhaps, even python and perl5.

	The modified port file can be found at


but the patch is so small that I have it as an attachment.


Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
feature, n: a documented bug | bug, n: an undocumented feature
-------------- next part --------------
--- Makefile.orig	2009-02-12 15:54:27.000000000 -0200
+++ Makefile	2009-02-28 09:04:05.000000000 -0300
@@ -38,6 +38,7 @@
 		ONIGURUMA "Build with oniguruma regular expressions lib" off \
 		GCPATCH "Build with GC performance statistics collector" off \
 		IPV6 "Enable IPv6 support" on \
+		PGO "Enable Profile-Guided Optimization" off \
 		RDOC "Build and install Rdoc indexes" off \
 		DEBUG "Compile-in debug info" off
@@ -57,6 +58,10 @@
 CFLAGS+=	${PTHREAD_CFLAGS}	# Keep this, else ruby will fail to load
 LDFLAGS+=	${PTHREAD_LIBS}		# libraries dependent op libpthread.
+.if defined(WITH_PGO)
 .if defined(WITH_PTHREADS)
@@ -98,8 +103,14 @@
 CONFIGURE_ARGS+=	--enable-ipv6
+.if defined(WITH_PGO)
+CONFIGURE_ENV=	CFLAGS="${CFLAGS} -fprofile-generate" \
+		LDFLAGS="-fprofile-generate" \
 MLINKS=		${RUBY_NAME}.1 ruby.1
@@ -170,6 +181,13 @@
 	cd ${WRKSRC}/ && ${PATCH} -p0 < ${PATCHDIR}/extrapatch-oniguruma-reggnu.c
+.if defined(WITH_PGO)
+.if target(pre-build)
+.error Makefile error since pre-build target has already been defined
+pre-build: pgo
 # Hack to allow modules to be installed into separate PREFIX and/or under user
@@ -321,4 +339,47 @@
 	(cd ${WRKSRC}/rubyspec && git clone git://github.com/rubyspec/mspec.git)
 	(cd ${WRKSRC}/rubyspec/rubyspec && env PATH=${WRKSRC}/rubyspec/mspec/bin:${PATH} mspec -t ${PREFIX}/bin/ruby${RUBY_SUFFIX})
+.if defined(WITH_PGO)
+pgo: pgo-pre-build pgo-build pgo-run pgo-post-run pgo-clean
+	@${FIND} ${BUILD_WRKSRC} -type f -name Makefile -exec \
+			-e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)-fprofile-generate,\1,' \
+			-e 's,^(CFLAGS[[:space:]]*=.*)-fprofile-use,\1,' \
+			-e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)$$,\1 -fprofile-generate,' \
+			{} \;
+# XXX
+# Can I use do-build directly instead of copying its contents?
+# I mean, if I do
+# pgo-build: do-build
+# Will do-build still be called when bsd.port.mk gets to the build target?
+# Or, will it have "already" been executed by the pgo-build target?
+pgo-run: test
+# Check everything to generate profiling information.
+# We will ignore any errors if test target works
+	@-(cd ${BUILD_WRKSRC}; ${MAKE} check)
+	@${FIND} ${BUILD_WRKSRC} -type f -name Makefile -exec \
+			-e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)-fprofile-generate,\1,' \
+			-e 's,^(CFLAGS[[:space:]]*=.*)-fprofile-use,\1,' \
+			-e 's,^(CFLAGS[[:space:]]*=.*)$$,\1 -fprofile-use,' \
+			{} \;
+		-e 's,-fprofile-generate,-fprofile-use,g' \
+		${CONFIGURE_WRKSRC}/config.status
+	@(cd ${BUILD_WRKSRC}; ${MAKE} clean)
+.endif # if defined(WITH_PGO)
 .include <bsd.port.post.mk>

More information about the freebsd-ports mailing list