- java.lang.Object
-
- de.codecamp.tracer.Trace
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidend(Instant endTime)Sets the trace as ended and records theend time.voidend(Instant endTime, Throwable exitThrowable)Sets this trace and all still active sub-traces as ended and records theend time.TracegetActiveTrace(boolean includeRoot)Map<String,Object>getData()<T> TgetData(Class<T> key)ObjectgetData(String key)<T> TgetData(String key, Class<T> type)DurationgetDuration()Returns the duration of this trace.InstantgetEndTime()Returns the end time of this trace.Optional<Throwable>getExitThrowable()Returns the throwable that exited the trace.StringgetLabel()Returns the label of this trace.TracegetLastSubTrace()TracegetParentTrace()Returns the parent trace or null.InstantgetStartTime()Returns the start time of this trace.List<Trace>getSubTraces()Returns the list of sub-traces.booleanhasEnded()Returns whether the trace has already ended.booleanisContextRoot()Returns whether this trace is the root of aTraceContextImpl.booleanisGap()Returns whether this trace represents a gap.booleanisWarn()static TracenewContextRoot(Trace parentTrace, Instant startTime, String label, Object[] labelFormatArgs)static TracenewExplicit(Trace parentTrace, Instant startTime, String label, Object[] labelFormatArgs)static TracenewGap(Trace parentTrace, Instant startTime, Instant endTime)<T> voidsetData(Class<T> key, T data)voidsetData(String key, Object data)voidsetData(Map<String,Object> data)voidsetWarn(boolean warn)StringtoString()
-
-
-
Method Detail
-
newExplicit
public static Trace newExplicit(Trace parentTrace, Instant startTime, String label, Object[] labelFormatArgs)
-
newContextRoot
public static Trace newContextRoot(Trace parentTrace, Instant startTime, String label, Object[] labelFormatArgs)
-
getLabel
public String getLabel()
Returns the label of this trace.- Returns:
- the label of this trace
-
getStartTime
public Instant getStartTime()
Returns the start time of this trace.- Returns:
- the start time of this trace
-
getEndTime
public Instant getEndTime()
Returns the end time of this trace.- Returns:
- the end time of this trace
- Throws:
IllegalStateException- if the trace has not yet finished
-
hasEnded
public boolean hasEnded()
Returns whether the trace has already ended.- Returns:
- whether the trace has already ended
-
end
public void end(Instant endTime)
Sets the trace as ended and records theend time.- Parameters:
endTime- the end time for the trace
-
end
public void end(Instant endTime, Throwable exitThrowable)
Sets this trace and all still active sub-traces as ended and records theend time.- Parameters:
endTime- the end time for the traceexitThrowable- the throwable that exited the trace
-
getDuration
public Duration getDuration()
Returns the duration of this trace.- Returns:
- the duration of this trace
- Throws:
IllegalStateException- if the trace has not yet finished
-
getParentTrace
public Trace getParentTrace()
Returns the parent trace or null.- Returns:
- the parent trace or null
-
isContextRoot
public boolean isContextRoot()
Returns whether this trace is the root of aTraceContextImpl.- Returns:
- whether this trace is the root of a
TraceContextImpl
-
isGap
public boolean isGap()
Returns whether this trace represents a gap. Gaps are periods of time between explicit traces. This can help locate costly segments of code that aren't explicitly traced (yet).- Returns:
- whether this trace represents a gap
-
getSubTraces
public List<Trace> getSubTraces()
Returns the list of sub-traces.- Returns:
- the list of sub-traces
-
getLastSubTrace
public Trace getLastSubTrace()
-
getActiveTrace
public Trace getActiveTrace(boolean includeRoot)
-
getExitThrowable
public Optional<Throwable> getExitThrowable()
Returns the throwable that exited the trace.- Returns:
- the throwable that exited the trace
-
isWarn
public boolean isWarn()
-
setWarn
public void setWarn(boolean warn)
-
getData
public <T> T getData(Class<T> key)
-
setData
public <T> void setData(Class<T> key, T data)
-
-