groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Johnson <>
Subject question about Groovy syntax
Date Thu, 02 Jul 2015 15:51:22 GMT
I'm using a package called gprof that profiles Groovy code, and it has been
very useful.

You are supposed to be able to write

profile {your code goes here}.prettyPrint()

and it will print out a profile of your code on the console.   But that
doesn't work for me.  I read the code and found what I thought was the
definition of "profile" in ProfileStaticExtension

Its definition is

public class ProfileStaticExtension {

    static Report profile(Object selfType, Callable profiled) {

        return new Profiler().run(profiled);


    static Report profile(Object selfType, Map options, Callable profiled) {

        return new Profiler().run(options, profiled);



So, I tried writing

ProfileStaticExtension.profile(null, {your code goes here}).prettyPrint()

and that worked!   Do you have any idea why the syntax that they advertised
doesn't work?  It certainly is a nicer syntax than what I am using.  I'm
using it in Eclipse and I thought maybe I had the class path set up
incorrectly, but it looks good to me.

new Profiler.profile({your code here}).prettyPrint() works, too.

View raw message