Skip to content

Adaptive Instrumentation

Jaroslav Bachorik edited this page Jun 3, 2019 · 1 revision

Adaptive Instrumentation

BTrace supports adaptive instrumentation using a concept of instrumentation levels. Each probe can be marked (via annotation) with the minimum level for that particular probe to take effect. This way lightweight probes can run always, having the level set to 0, while some heavy weight probes can be restricted to level 100 and above.

The instrumentation level is adjustable in runtime and it can even be done from within a probe handler - allowing for certain trigger points to increase/decrease the instrumentation level.

Specifying Instrumentation Level

Desired instrumentation level of a particular probe is defined via @Level annotation. This annotation takes textual value in following format: [=,>,<,<=,>=] - the equality and comparison signs having their usual meaning.

// following probe will be active only if the instrumentation level is at least 100
@Level("100") // @Level(">=100")
// @Level("<100") @Level(">100") @Level("<=100") @Level("=100")
@OnMethod(...)
public void handler() {
   ...
}

Adjusting Instrumentation Level

Instrumentation level is adjusted by calling BTraceUtils.setInstrumentationLevel(level). BTraceUtils.getInstrumentationLevel() can be used to query the current instrumentation level.

Performance Benefits

Inactive probe handlers will incur only the overhead of int comparison and branch jump - which is negligible compared to the cost of full probe handling. Take this with a grain of salt but the ballpark is microseconds for active probe vs. nanosecond(s) for inactive one.