I think a better template to use is the following:
// Original version
int getValue() {
return super.getValue() * 5;
}
// Instrumented version
int getValue() {
try {
Timer.startTimer("Test.getValue()");
return super.getValue() * 5;
} finally {
Timer.stopTimer("Test.getValue()");
}
}
This also handles correctly cases where there are multiple return
statements, and you get timing information even if there's an
exception. The implementation is fairly simple:
(beginning-of-defun)
(insert "try {\n Timer.startTime(" (get-function-name) ");\n")
(end-of-defun)
(insert "} finally {\n Timer.stopTimer(" (get-function-name) ");\n}\n")
This isn't quite right. At least on my emacs, the defun functions put you
on the wrong side of the braces. get-function-name is probably also not
the right function name, but there is some function that does that. (The
name shows up in my modeline, so probably semantic/senator knows it.)
Troy
At 09:02 PM 1/24/02 +0100, Paul Ebermann wrote:
>""Altmann, Michael"" skribis:
>
> > I have been using xemacs and jde for quite a while, but I am not much of an
> > elisp programmer. Could someone help me (or point me to the appropriate
> > online resource) write the following elisp function? I have a java class
> > called Timer that I use to time various chunks of code. It has methods
> > startTimer and stopTimer that should surround any code I want to time. I
> > would like an elisp function to insert calls to Timer for the current java
> > method. For example, given a java program that looks like
> >
>[...]
> >
> > I would like code inserted like
> >
>[...]
> > void bar() {
> > Timer.startTimer("Test.bar");
> > int x=3;
> > Timer.stopTimer("Test.bar");
> > }
> > }
>
>(Sorry for missing tabs, my newsreader ignores or deletes them.)
>
>What should be done here?
>---
>int getValue() {
> return super.getValue()*5;
>}
>---
>The simple Version
>---
>int getValue() {
> Timer.startTimer("Test.getValue()");
> Timer.stopTimer("Test.getValue()");
> return super.getValue() * 5;
>}
>---
>is not really helpful (it does not time
>anything time-consuming).
>You may need something like
>---
>int getValue() {
> Timer.startTimer("Test.getValue()");
> int temp = super.getValue() * 5;
> Timer.stopTimer("Test.getValue()");
> return temp;
>}
>---
>So your function has to choose a name for a
>temporary variable, and using the right type ...
>
>
>Sorry, this does not really help, but only
>shows a possible problem.
>
>Paul
Troy Daniels
[EMAIL PROTECTED]
781-273-3388 x218