我想测量我项目中各种功能的性能。这将在多个线程上运行,所以现在我有这样的东西
long start = System.currentTimeMillis();
first();
StatsTracker.putTime("first", System.currentTimeMillis() - start);
...
start = System.currentTimeMillis();
second();
StatsTracker.putTime("second", System.currentTimeMillis() - start);
其中 StatsTracker 是一个静态类,它只是跟踪性能图。
我是编写自定义注释的新手,我在网上看到的一些教程让它有点混乱。我最终想要的是这样的
@StartTime("first")
first();
@EndTime("first")
...
@StartTime("second")
second();
@EndTime("second")
然后对于开始/结束时间注释,我希望这两个注释记录当前系统时间,然后将该运行时间放入地图中(以记录平均性能)。
编辑:在函数定义之前有这样的东西可能更自然:
@TrackTime("first")
public void first() { ... }
任何帮助表示赞赏。谢谢!