Package org.apache.lucene.sandbox.search
Class QueryProfilerTree
- java.lang.Object
-
- org.apache.lucene.sandbox.search.QueryProfilerTree
-
class QueryProfilerTree extends java.lang.ObjectThis class tracks the dependency tree for queries (scoring and rewriting) and generatesQueryProfilerBreakdownfor each node in the tree.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<QueryProfilerBreakdown>breakdownsprivate intcurrentTokenprivate java.util.ArrayList<Query>queriesA list of the original queries, keyed by index positionprivate longrewriteScratchprivate longrewriteTimeRewrite timeprivate java.util.ArrayList<java.lang.Integer>rootsA list of top-level "roots".private java.util.Deque<java.lang.Integer>stackA temporary stack used to record where we are in the dependency tree.private java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>treeMaps the Query to it's list of children.
-
Constructor Summary
Constructors Constructor Description QueryProfilerTree()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private QueryProfilerBreakdownaddDependencyNode(Query query, int token)Helper method to add a new node to the dependency tree.private QueryProfilerBreakdowncreateProfileBreakdown()private QueryProfilerResultdoGetTree(int token)Recursive helper to finalize a node in the dependency treeprivate java.lang.StringgetDescriptionFromQuery(Query query)QueryProfilerBreakdowngetProfileBreakdown(Query query)Returns aQueryProfilerBreakdownfor a scoring query.longgetRewriteTime()java.util.List<QueryProfilerResult>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 java.lang.StringgetTypeFromQuery(Query query)voidpollLast()Removes the last (e.g.voidstartRewriteTime()Begin timing a query for a specific Timing contextlongstopAndAddRewriteTime()Halt the timing process and add the elapsed rewriting time.private voidupdateParent(int childToken)Internal helper to add a child to the current parent node
-
-
-
Field Detail
-
breakdowns
private final java.util.ArrayList<QueryProfilerBreakdown> breakdowns
-
tree
private final java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> tree
Maps the Query to it's list of children. This is basically the dependency tree
-
queries
private final java.util.ArrayList<Query> queries
A list of the original queries, keyed by index position
-
roots
private final java.util.ArrayList<java.lang.Integer> roots
A list of top-level "roots". Each root can have its own tree of profiles
-
stack
private final java.util.Deque<java.lang.Integer> stack
A temporary stack used to record where we are in the dependency tree.
-
currentToken
private int currentToken
-
rewriteTime
private long rewriteTime
Rewrite time
-
rewriteScratch
private long rewriteScratch
-
-
Method Detail
-
getProfileBreakdown
public QueryProfilerBreakdown getProfileBreakdown(Query query)
Returns aQueryProfilerBreakdownfor 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
private QueryProfilerBreakdown addDependencyNode(Query query, int token)
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
QueryProfilerBreakdownto track the timings of this query.- Parameters:
query- The query to profiletoken- The assigned token for this query- Returns:
- A
QueryProfilerBreakdownto profile this query
-
createProfileBreakdown
private QueryProfilerBreakdown createProfileBreakdown()
-
pollLast
public void pollLast()
Removes the last (e.g. most recent) value on the stack
-
getTree
public java.util.List<QueryProfilerResult> 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
private QueryProfilerResult doGetTree(int token)
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
private java.lang.String getTypeFromQuery(Query query)
-
getDescriptionFromQuery
private java.lang.String getDescriptionFromQuery(Query query)
-
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()
-
-