I know how to measure time (eg. prefer System.nanoTime) and I'm measuring execution time of methods in 'test'-builds of my applications here and there.
But sometimes bad performance can happen in a production app. It would be nice to know if the reason for it is an HTTP-call to another Host, or a mapping-code for DB-entities, JSON/XML mappers or other parts of the logic.
So I want to include that time measuring also in the production code, waiting there for being enabled/disabled.
I'm thinking of a naive approach like creating a TimeMeasure-interface that is subclassed twice, one implementation with actual time measuring and the other with empty method bodies to avoid too much overhead in productive use.
Does that approach sounds valid or is there a better technique to keep a low overhead for code in your method that is only used in very rare cases. Is there any timemeasuring library that is already aware of such a feature?