Using the compiler for scripts / logging statistics (learning)

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Using the compiler for scripts / logging statistics (learning)


I’m playing with compiler with scripts. For instance:

result := OpalCompiler new
                source: ‘3 + 1';

result2 := OpalCompiler new
                source: 'self + 1';
                receiver: 3;

I would eventually (as an exercice) try to log the time before and after the execution of the script.

Its possible to send #logged: true; to the compiler which basically is able to log doIt through SystemPresenter.

        self compilationContext logged ifFalse: [ ^self ].
        Smalltalk globals
                        at: #SystemAnnouncer
                        ifPresent: [ :sysAnn |
                                sysAnn uniqueInstance evaluated: source contents context: context ].

Right now, it seems the logging mechanism is launched once the evaluation is done.

So my question is would it be possible to log start and ent time execution through the compiler.

        "Compiles the sourceStream into a parse tree, then generates code into
         a method. If aContext is not nil, the text can refer to temporaries in that
         context (the Debugger uses this). If aRequestor is not nil, then it will receive
         a notify:at: message before the attempt to evaluate is aborted. Finally, the
         compiled method is invoked from here via withArgs:executeMethod:, hence
         the system no longer creates Doit method litter on errors."

        | value |
        self noPattern: true.
        self getSourceFromRequestorSelection.
        self class: (context ifNil: [ receiver class ] ifNotNil: [ context method methodClass ]).
=> here a kind of sell startLog.
        "code execution"
        value := receiver withArgs: (context ifNil: [ #() ] ifNotNil: [ {context} ]) executeMethod: self compile.
"actual log call…. Only for doIt ?"
        self logDoIt.
        ^ value

I wonder what would be the way of doing it ? Is it only for doIts ?

Start/endLog could be calling log options #(logDoIt, logWhatever, …) ? Maybe doing ScriptEvaluated to differ from ExpressionEvaluated would be the solution ?
I imagine this has impact on performance too...  

My toy objective is to log statistic of scripts usage. Again this is just experiments, so happy to hear and learn from others. How would people do ?