java.lang.Object
org.apache.lucene.sandbox.search.QueryProfilerTree
This class tracks the dependency tree for queries (scoring and rewriting) and generates
QueryProfilerBreakdown
for each node in the tree.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ArrayList<QueryProfilerBreakdown>
private int
A list of the original queries, keyed by index positionprivate long
private long
Rewrite timeA list of top-level "roots".A temporary stack used to record where we are in the dependency tree.Maps the Query to it's list of children. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate QueryProfilerBreakdown
addDependencyNode
(Query query, int token) Helper method to add a new node to the dependency tree.private QueryProfilerBreakdown
private QueryProfilerResult
doGetTree
(int token) Recursive helper to finalize a node in the dependency treeprivate String
getDescriptionFromQuery
(Query query) getProfileBreakdown
(Query query) Returns aQueryProfilerBreakdown
for a scoring query.long
getTree()
After the query has been run and profiled, we need to merge the flat timing map with the dependency graph to build a data structure that mirrors the original query treeprivate String
getTypeFromQuery
(Query query) void
pollLast()
Removes the last (e.g.void
Begin timing a query for a specific Timing contextlong
Halt the timing process and add the elapsed rewriting time.private void
updateParent
(int childToken) Internal helper to add a child to the current parent node
-
Field Details
-
breakdowns
-
tree
Maps the Query to it's list of children. This is basically the dependency tree -
queries
A list of the original queries, keyed by index position -
roots
A list of top-level "roots". Each root can have its own tree of profiles -
stack
A temporary stack used to record where we are in the dependency tree. -
currentToken
private int currentToken -
rewriteTime
private long rewriteTimeRewrite time -
rewriteScratch
private long rewriteScratch
-
-
Constructor Details
-
QueryProfilerTree
public QueryProfilerTree()
-
-
Method Details
-
getProfileBreakdown
Returns aQueryProfilerBreakdown
for a scoring query. Scoring queries (e.g. those that are past the rewrite phase and are now being wrapped by createWeight() ) follow a recursive progression. We can track the dependency tree by a simple stackThe only hiccup is that the first scoring query will be identical to the last rewritten query, so we need to take special care to fix that
- Parameters:
query
- The scoring query we wish to profile- Returns:
- A ProfileBreakdown for this query
-
addDependencyNode
Helper method to add a new node to the dependency tree.Initializes a new list in the dependency tree, saves the query and generates a new
QueryProfilerBreakdown
to track the timings of this query.- Parameters:
query
- The query to profiletoken
- The assigned token for this query- Returns:
- A
QueryProfilerBreakdown
to profile this query
-
createProfileBreakdown
-
pollLast
public void pollLast()Removes the last (e.g. most recent) value on the stack -
getTree
After the query has been run and profiled, we need to merge the flat timing map with the dependency graph to build a data structure that mirrors the original query tree- Returns:
- a hierarchical representation of the profiled query tree
-
doGetTree
Recursive helper to finalize a node in the dependency tree- Parameters:
token
- The node we are currently finalizing- Returns:
- A hierarchical representation of the tree inclusive of children at this level
-
getTypeFromQuery
-
getDescriptionFromQuery
-
updateParent
private void updateParent(int childToken) Internal helper to add a child to the current parent node- Parameters:
childToken
- The child to add to the current parent
-
startRewriteTime
public void startRewriteTime()Begin timing a query for a specific Timing context -
stopAndAddRewriteTime
public long stopAndAddRewriteTime()Halt the timing process and add the elapsed rewriting time. startRewriteTime() must be called for a particular context prior to calling stopAndAddRewriteTime(), otherwise the elapsed time will be negative and nonsensical- Returns:
- The elapsed time
-
getRewriteTime
public long getRewriteTime()
-