Class DatabaseActivity
It exists so that instrumentation which only sees the Vaadin side of a data load — the data provider events, which say a component asked for 150 items and got 150 back — can also report what that load cost underneath. Those two numbers are the same whether the page came out of one indexed query or out of sixty thousand, and the difference between those two is the whole finding.
The tally is monotonic and never reset. A caller measures a window by taking
current() at its start and since(Work) at its end, so
windows can nest without one clearing another's baseline.
Threading. The counters are thread-confined, which is what makes them cheap — a plain increment, no contention. It also means a window only counts the queries issued on the thread that opened it: a data provider that hands its fetch to another thread would see none of them. That case is reported as unknown rather than as zero, since the two are indistinguishable here and a confident "no database work" would be the more damaging of the two answers.
The counters cost two longs on each thread that touches JDBC and are
never removed, which is deliberate: they belong to pooled request threads
that outlive any single query, and a remove() on a window boundary
would throw away the baseline of an enclosing window.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe JDBC work counted in one window: how many queries ran and how many result-set rows they read. -
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseActivity.Workcurrent()Opens a measurement window.static voidDeclares that JDBC queries are being counted.static booleanstatic voidCounts one executed query on the current thread.static voidrowsRead(long rows) Counts rows read from one result set on the current thread.static DatabaseActivity.Worksince(DatabaseActivity.Work start) Closes a measurement window opened bycurrent().
-
Method Details
-
instrumented
public static void instrumented()Declares that JDBC queries are being counted. Called by whichever instrumentation wraps the application's data sources. -
isInstrumented
public static boolean isInstrumented()- Returns:
- whether JDBC queries are being counted at all
-
queryExecuted
public static void queryExecuted()Counts one executed query on the current thread. -
rowsRead
public static void rowsRead(long rows) Counts rows read from one result set on the current thread.- Parameters:
rows- the number of rows read, ignored when negative
-
current
Opens a measurement window.- Returns:
- the current thread's running tally, to be handed back to
since(Work), orDatabaseActivity.Work.UNKNOWNwhen nothing is being counted
-
since
Closes a measurement window opened bycurrent().- Parameters:
start- the tally taken when the window opened, may benull- Returns:
- the work done on this thread since then, or
DatabaseActivity.Work.UNKNOWNwhen there is nothing to report — no instrumentation, no baseline, or no query counted, the last of which also covers a window whose queries ran on another thread
-