Class StatActionInOut
java.lang.Object
com.iohao.net.framework.core.flow.internal.StatActionInOut
- All Implemented Interfaces:
ActionMethodInOut
PluginInOut - StatActionInOut - Action Call Statistics Plugin
StatActionInOut is an action call statistics plugin that can be used to collect relevant data for each action call, such as the execution count, total time cost, average time cost, maximum time cost, number of exceptions triggered, and other related statistics. Developers can use this data to analyze the hotspot methods and time-consuming methods in the project, thus achieving precise optimization.
// StatAction statistics record print preview
"StatAction{cmd[1-0], Executed [1] times, Total Time Cost [8], Average Time Cost [8], Maximum Time Cost [8], Exceptions [0] times}"
for example
BarSkeletonBuilder builder = ...;
// Action Call Statistics Plugin, add the plugin to the business framework
var statActionInOut = new StatActionInOut();
builder.addInOut(statActionInOut);
// Set the listener for processing after the StatAction statistics record is updated
statActionInOut.setListener((statAction, time, flowContext) -> {
// Simply print the statistics record value StatAction
System.out.println(statAction);
});
// Statistics region (manager of statistical values)
StatActionInOut.StatActionRegion region = statActionInOut.getRegion();
// Iterate over all statistics data
region.forEach((cmdInfo, statAction) -> {
// Simply print the statistics record value StatAction
System.out.println(statAction);
// Developers can periodically save this data to logs or a DB for subsequent analysis
});
- Author:
- 渔民小镇
- See Also:
- date:
- 2023-11-17
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classPer-action statistics record holding execution count, total/average/max time cost, error count, and time range distribution.static interfacePluginInOut - StatActionInOut - Action Call Statistics Plugin - StatAction Update Listenerfinal classRegion that managesStatActionInOut.StatActioninstances, one perCmdInfo.static final recordPluginInOut - StatActionInOut - Action Call Statistics Plugin - Time Range Record -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfuckIn(FlowContext flowContext) Record the start time before action method execution (no-op; timing usesFlowContext.getNanoTime()).voidfuckOut(FlowContext flowContext) Collect statistics after action method execution, updating the correspondingStatActionInOut.StatAction.Statistics region (manages StatAction)voidListener for statistics value update
-
Constructor Details
-
StatActionInOut
public StatActionInOut()
-
-
Method Details
-
fuckIn
Record the start time before action method execution (no-op; timing usesFlowContext.getNanoTime()).- Specified by:
fuckInin interfaceActionMethodInOut- Parameters:
flowContext- the current request flow context
-
fuckOut
Collect statistics after action method execution, updating the correspondingStatActionInOut.StatAction.- Specified by:
fuckOutin interfaceActionMethodInOut- Parameters:
flowContext- the current request flow context
-
getRegion
Statistics region (manages StatAction) -
setListener
Listener for statistics value update
-