Class QueryProfilerTree

java.lang.Object
org.apache.lucene.sandbox.search.QueryProfilerTree

class QueryProfilerTree extends Object
This class tracks the dependency tree for queries (scoring and rewriting) and generates QueryProfilerBreakdown for each node in the tree.
  • Field Details

    • breakdowns

      private final ArrayList<QueryProfilerBreakdown> breakdowns
    • tree

      private final ArrayList<ArrayList<Integer>> tree
      Maps the Query to it's list of children. This is basically the dependency tree
    • queries

      private final ArrayList<Query> queries
      A list of the original queries, keyed by index position
    • roots

      private final ArrayList<Integer> roots
      A list of top-level "roots". Each root can have its own tree of profiles
    • stack

      private final Deque<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
  • Constructor Details

    • QueryProfilerTree

      public QueryProfilerTree()
  • Method Details

    • getProfileBreakdown

      public QueryProfilerBreakdown getProfileBreakdown(Query query)
      Returns a QueryProfilerBreakdown 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 stack

      The 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 QueryProfilerBreakdown to track the timings of this query.

      Parameters:
      query - The query to profile
      token - The assigned token for this query
      Returns:
      A QueryProfilerBreakdown to profile this query
    • createProfileBreakdown

      private QueryProfilerBreakdown createProfileBreakdown()
    • pollLast

      public void pollLast()
      Removes the last (e.g. most recent) value on the stack
    • getTree

      public 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 String getTypeFromQuery(Query query)
    • getDescriptionFromQuery

      private 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()