Discussion:
[FreeMarker-user] Execution time of called method from custom shared variable classes
Jan Haderka
2013-07-12 11:18:47 UTC
Permalink
Hi,

I need to find out execution time of some class called from the template. It's the class with bunch of static methods and I would ideally need to know cumulative time spent in all those calls (as opposed to rendering itself). The examples of usages would be from

${classX.callA(some param)}

to

[#if classX.doTest() ]

etc.

The class above is made available via shared variables.

I understand that I need to modify the code was wondering if anyone could suggest what would be the best class to extend to add such monitoring and to collect the time.
Is there a singe point through which all calls to shared variable methods go?
Is TemplateMethodModel.exec() the right place where to measure such thing or do I need to extend more (or something else then model) depending on where the call happens?

Thanks in advance,
--
Jan
Daniel Dekany
2013-07-13 08:10:12 UTC
Permalink
You could extend BeansWrapper and override invokeMethod and measure
super.invokeMethod. However, there are two problems with it:

- You will also measure the overhead of Method.invoke and the time
needed for wrapping the return value into TemplateModel.

- It's not a public method, so you can only override it if your new class
will be in freemarker.ext.beans package. This means that you will
have no backward-compatibility guarantees.
--
Thanks,
Daniel Dekany
Post by Jan Haderka
Hi,
I need to find out execution time of some class called from the
template. It's the class with bunch of static methods and I would
ideally need to know cumulative time spent in all those calls (as
opposed to rendering itself). The examples of usages would be from
${classX.callA(some param)}
to
[#if classX.doTest() ]
etc.
The class above is made available via shared variables.
I understand that I need to modify the code was wondering if anyone
could suggest what would be the best class to extend to add such
monitoring and to collect the time.
Is there a singe point through which all calls to shared variable methods go?
Is TemplateMethodModel.exec() the right place where to measure such
thing or do I need to extend more (or something else then model)
depending on where the call happens?
Thanks in advance,
--
Jan
Loading...