[ 
https://issues.apache.org/jira/browse/SLING-4849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15374787#comment-15374787
 ] 

Ian Boston commented on SLING-4849:
-----------------------------------

Currently you can dump all the methods encountered and then select the ones you 
want to instrument.

To perform a wildcard config (eg org.apache.oak.core.* ) would require the 
getConfig [1] method evaluates the first path element using regexes rather than 
simply looking up maps in a key. I don't think that would be hard, all it would 
need to do is iterate through the keys, check to see if they were a pattern, 
and then see if the pattern matched the first path element. This method is 
called when weaving is performed, so if it's slow it will impact the 
classloader performance on all classes loaded, but should not impact the 
runtime performance. For this reason I did not implement, since I felt the 
overhead would not be acceptable in production. 

I think instrumenting everything might introduce significant overhead which is 
why, on reflection, I went for the dump approach to allow whoever is 
instrumenting a quick way of seeing what classes are being loaded, and given 
them the config template to instrument what they wanted.

1 
https://github.com/ieb/sling/blob/SLING-4849/bundles/extensions/metrics/src/main/java/org/apache/sling/metrics/impl/dropwizard/DropwizardMetricsConfig.java#L175

> Create Metrics instumentation bundle using ASM.
> -----------------------------------------------
>
>                 Key: SLING-4849
>                 URL: https://issues.apache.org/jira/browse/SLING-4849
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>            Reporter: Ian Boston
>            Assignee: Ian Boston
>         Attachments: Screen Shot 2015-07-02 at 12.24.01.png, Screen Shot 
> 2015-07-02 at 12.24.18.png, Screen Shot 2015-07-02 at 12.24.27.png
>
>
> Aim: To enable metrics for any method call in a Sling JVM without requiring 
> any code changes to existing bundles.
> Method: OSGi 4.3 has a WeavingHook which is allows a byte code generator to 
> get in between the classloader and classloading. Using ASM it should be 
> possible to write code that enhances the byte code of any class to wrap 
> method calls in calls to the Dropwizard Metrics library. This should work 
> without any changes to the startup. The only requirement is the bundle is 
> loaded before the classloader loads the classes that need to be instrumented. 
> Quick tests indicate the method works and adds no more than 10 byte code 
> instructions to a method. It may be possible to reduce that further. 
> Instrumentation will be controlled by configuration, so classes that are not 
> instrumented are not modified at all when loading.
> The metrics once available can be pushed into Graphite, Kibana or some other 
> collection service. Dumped to a file periodically or exposed in JMX as 
> counters.
> Will work in a branch on github initially.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to