Interface ProfilerService


  • public interface ProfilerService
    Service to support basic profiling. Allows nested profiling calls and well distinguish in results between self time and total time (per entry). The service is thread safe, in the way that profiling can happen asynchronously, across multiple threads. It does not support nested profiling across multiple threads, i.e. nesting is local. The service supports starting and not stopping profiling entries, so it is not required to add a stopProfiling(int) call to every branch of the profiled function. Results can be viewed via the web/admin/profile page, or by retrieving the results manually.

    • Prior to starting a profiling sequence, use reset(). This will initiate a new profiling sequence and clear the old one, if any. This should be done per thread. Threads in which ServletRequest are handled are likely already cleared by WebManager
    • To start profiling some code, use startProfiling(String).
    • To stop profiling some code, use stopProfiling(int). Invoking this method will stop profiling a single entry, being the one identified by the int id.
      • A profiling entry must be stopped in the same function as it was started.
      • A profiling entry does not have to be stopped. An entry that is not stopped will be discarded, along with its children. Cancelled entries will never appear in the results list, and not affect any other entries, safe for their children.
    • By default, the profiling results are not stored and thus cannot be retrieved. To store the results for some duration, use @{link #storeResults(long)}.
    • Results can be retrieved using getResults(), but not that retrieving results will discard all current results afterwards.
    • Profiler calls are ignored unless part of a profiling sequence. Starting a sequence can be done using reset(). This also clears all opened entries of the previous sequence of that thread (if any).
    • Method Detail

      • startProfiling

        int startProfiling​(String name)
        Starts profiling. A profiling entry with the specified name will be added and started for the current thread. If a starting profiling entry is never stopped, it will be discarded. The entry is placed in the default category. Note that calls are ignored if the service is not reset() for current thread.
        Parameters:
        name - The name of the entry, e.g. "SQL query <query>"
        Returns:
        The id for this profiling entry
        See Also:
        startProfilingCategory(String), startProfiling(String, String)
      • startProfilingCategory

        int startProfilingCategory​(String category)
        Starts profiling. A profiling entry in the specified category will be added and started for the current thread. If a starting profiling entry is never stopped, it will be discarded. The entry will not be saved and is thus not retrievable; the results will be propagated to the statistics service only. Note that calls are ignored if the service is not reset() for current thread.
        Parameters:
        category - The category of the entry, e.g. "XSLT transformation"
        Returns:
        The id for this profiling entry
        See Also:
        startProfiling(String), startProfiling(String, String)
      • startProfiling

        int startProfiling​(String category,
                           String name)
        Starts profiling. A profiling entry with the specified name will be added and started for the current thread. If a starting profiling entry is never stopped, it will be discarded. Note that calls are ignored if the service is not reset() for current thread.
        Parameters:
        category - The category of the entry, e.g. "XSLT transformation"
        name - The name of the entry, e.g. "SQL query <query>"
        Returns:
        The id for this profiling entry
        See Also:
        startProfiling(String), startProfilingCategory(String)
      • stopProfiling

        void stopProfiling​(int entryId)
        Stops the specified profiling entry on the current thread and also stops all entries that have been started after the specified one has been. Attempts to stop the last profiling entry whilst there is no profiling entry active, will generate a warning.
        Parameters:
        entryId - The id of the profiling entry to stop
      • reset

        void reset()
        Clears all started profiling entries for the current thread (the results are not saved), and starts a new profiling process. Only profile calls after having called this method are recorded.
      • getResults

        List<ProfilerEntry> getResults()
        Returns the 100 last root nodes of all profiling entries.
        Returns:
        The root entries, in reverse order