Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - How can I calculate execution time spent on any action?

Tags:

grails

I'm trying to measure time spent on every action of my application, since I'm rebuilding a legacy system.

Right now I'm doing this at Controller level:

def actionStart() {
    session.startTime = new Date().getTime()
}
def actionEnd() {
    def endTime = new Date().getTime()
    timeHandler(endTime, session.startTime)
}
def timeHandler(end, start){
    return end - start
}

Important: I want to move it to a Filter and automatically execute it at the start and ending of every action.

What should be the best approach? Thanks in advance.

PS.: What's the difference between getting System.currentTimeMillis() and instanciating an object? Performance?

like image 457
André Buzzo Avatar asked Nov 20 '25 17:11

André Buzzo


1 Answers

At the start of the action do Like this :

long now = System.currentTimeMillis();

at the end of the Action , do Like this :

System.out.println( (System.currentTimeMillis() - now) + " ms");

and put your action between this two line

Disclaimer:

I answered this question according to java (before the tags was edited), so please clarify your tags.

like image 102
Alya'a Gamal Avatar answered Nov 24 '25 23:11

Alya'a Gamal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!