# ofxTimeMeasurements
[![Build Status](https://travis-ci.org/armadillu/ofxTimeMeasurements.svg?branch=master)](https://travis-ci.org/armadillu/ofxTimeMeasurements)
[![Build status](https://ci.appveyor.com/api/projects/status/0cne779u0mdp8mvp/branch/master?svg=true)](https://ci.appveyor.com/project/armadillu/ofxremoteui/branch/master)
Simple OpenFrameworks addon to easily measure execution times across any sections of your code.
![ofxTimeMeasurements anim](https://www.dropbox.com/s/y6nsin52sugpmms/ofxTimeMeasurementsAnim.gif?dl=1)
## 1. FEATURES
* Measure execution time of any parts of your app
* Enable / disable execution of code sections on the fly through the widget
* Collapsable GUI, see only what matters at the time (saves on quit)
* Execution times organized by Thread
* Measure exact times, or averaged time across frames
* Measure cumulative times (TS_START_ACC) for shared code sections
* Highlight frequently used calls, slowly fade unused calls
* update(), and draw() are automatically time sampled
* Measure GL driver execution times; actually querying openGL with glBeginQuery(GL_TIME_ELAPSED_EXT) & co.
* Optionally use [ofxMSATimer](https://github.com/obviousjim/ofxMSATimer) for higher precision (recommended on windows) for < OF_09 (not really needed nowadays).
* Optionally use [ofxHistoryPlot](https://github.com/armadillu/ofxHistoryPlot) to show timings over time
* Optionally use [ofxFontStash](https://github.com/armadillu/ofxFontStash) for rendering, which looks nicer and is much faster to draw than the default ofDrawBitmapFont. (see drawUiWithFontStash())
## 2. QUICK START
That's all you need to get basic measurements of update() and draw();
```
#include "ofxTimeMeasurements.h"
void setup(){
TIME_SAMPLE_SET_FRAMERATE(60.0f); //specify a target framerate
}
```
## 3. HOW TO MEASURE TIMES / PROFILE YOUR CODE
### 3.1 Standard Mode
You can measure times across any code section with TS_START() - TS_STOP()
```
TS_START("measurement1");
//my code here
TS_STOP("measurement1")
```
The ofxTimeMeasurements widget will list a line named "measurement1" showing how long it took for the section to execute.
### 3.2 Accumulation Mode
You can accumulate the time spent across one frame over sections of your code. This can be handy when a methods is called several times over one frame.
```
for(int i = 0; i < 10; i++){
TS_START_ACC("acc measurement");
//do something here
TS_STOP_ACC("acc measurement")
}
```
If we were to use TS_START/STOP on the example above, ofxTimeMeasurements would only report the time spent on the last iteration of the for loop. By using TS_START_ACC / TS_STOP_ACC, it accumulates the time spent on each iteration of the loop, reporting the total time spent.
### 3.3 "No If" Mode (_NIF)
ofxTimeMeasurements wraps your code around an if(){} clause. It does so to be able to disable code on the fly from its GUI. This can be problematic if you declare variables inside a measurement, as they will not be in scope outside the measurement. If that's the case, you use the _NIF extension in your macros, this way your code will not be wrapped around an if(){} clause. The only drawback is that you will not be able to enable/disable that code section from the GUI.
```
TS_START_NIF("nif");
int a = 0;
TS_STOP_NIF("nif");
a = 1; //we can now access the variable declared in the TM scope.
```
You can also use both NIF and ACC, see TS_START_ACC_NIF() and family.
### 3.4 Scope Mode
This mode measures execution times in a particular scope. It creates a temporary minimal object that will start measuring when its constructor is called, and it will stop measuring when its destructor is called.
```
{
TS_SCOPE("myTime");
doSomething();
doSomethingElse();
}
```
The example above will report the time it takes for doSomething() and doSomethingElse() to execute. The advantage here is that only one ofxTimeMeasurements call is needed to measure time.
### 3.5 TS() Mode
TS() is a very convenient ultra-short macro to measure the time a single method takes to execute. This will show up as "myMethod()" on your measurements widget.
```
TS(myMethod());
```
### 3.6 OpenGL Execution Times
This will NOT measure the time it takes the CPU to execute the code between the start() and stop() methods, but the time it takes the GPU to execute all the OpenGL instructions issued between start() and stop().
It does so by sending ```glBeginQuery(GL_TIME_ELAPSED_EXT)``` and ```glEndQuery(GL_TIME_ELAPSED_EXT)``` OpenGL commands, and retrieving the time it actually took to render by querying OpenGL after the rendering has happened. This method was chosen vs the ```GL_TIMESTAMP``` based, bc it seems to work with OpenGL 2.0, vs the ```GL_TIMESTAMP``` one requiring OpenGL 3.3.
![OpenGL Timings](https://farm1.staticflickr.com/576/32429675235_3844e560bf_o_d.png)
OpenGL timings will show in their own separate section named "OpenGL", similar to timings in different threads. They can be disabled the same way as CPU timings, and also averaged and plotted.
```
TSGL_START("FancyShader");
myFancyShader.run();
TSGL_STOP("FancyShader");
```
##### Some Caveats:
* OpenGL timing measurements can't be nested, you can't start a measurement unless you stopped the previous one. It's still ok to measure several things each frame, but not nested.
* It's ok to nest/mix these within standard "CPU" measurements.
* There's also "no if" version of this measurement, see 3.3 to learn more. TSGL_START_NIF() and TSGL_STOP_NIF().
* Because the timings can only be known after the frame has been fully drawn, the timings appear 2-3 frames after measured.
## 4. KEYBOARD COMMANDS / INTERACTIVE MODE
ofxTimeMeasurements responds to a few pre-defined keyboard commands:
* OF_KEY_PAGE_DOWN to toggle all time measuring, and the drawing of the widget
* 'A' to toggle time sample averaging.
* 'T' when widget is visible (enabled) to get into interactive mode.
* When in interactive mode, a "KEYBOARD COMMANDS" list is shown : basically on-screen instructions.
![](https://farm1.staticflickr.com/473/20007668446_d428e77cdf_o_d.png)
Up / Down keys to select, Left / Right keys to expand/collapse the time measurements tree.
## 5. RANDOM NOTES
#### 5.1 OVERHEAD
ofxTimeMeasurements adds some overhead when measuring times; and it adds even more when drawing its widget. You can see how much it adds by pressing the "B" key, it will display two extra timings, the time it takes for the measurements to be taken, and the time it takes for the widget to be drawn. When ofxTimeMeasurements is disabled (by pressing PgDown or by calling TIME_SAMPLE_DISABLE() at setup), it barely adds any overhead (it doesn't measure anything when the widget is not drawn) but it does add a tiny bit as the calls to its methods are still going through. To entirely remove all ofxTimeMeasurements calls without actually removing them from your code, you can define "TIME_MEASUREMENTS_DISABLED" in your project pro-processor macros for it to be entirely bypassed at compile time. This will only work if you use the recommended MACRO based API; if you have code that gets the ofxTimeMeasurements instance ```ofxTimeMeasurements::instance()``` and operates with it, your project will not compile.
#### 5.2 SAMPLE AVERAGING
If times vary too much from frame to frame to be readable on the widget, you can enable sample averaging; if you do so, each new time sample will be blended with the previous one; obtaining a smoother reading. Keep in mind that several samples will be required to get accurate readings when using averaging. You can also completely disable averaging.
TIME_SAMPLE_SET_AVERAGE_RATE(0.01); //every new sample effects 1% of the value shown
TIME_SAMPLE_DISABLE_AVERAGE(); //disable time sample averaging
#### 5.3 COLORS / THREADS
The ofxTimeMeasurements widget can show measurements in different colored sections. The first section will always represent times measured in the main thread. Following section
没有合适的资源?快使用搜索试试~ 我知道了~
OpenFrameworks 插件可轻松测量代码不同部分的执行时间_C++_代码_相关文件_下载
共21个文件
h:6个
cpp:5个
make:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 132 浏览量
2022-07-11
22:36:00
上传
评论
收藏 141KB ZIP 举报
温馨提示
简单的 OpenFrameworks 插件可轻松测量代码任何部分的执行时间。 一、特点 测量应用程序任何部分的执行时间 通过小部件即时启用/禁用代码部分的执行 可折叠的 GUI,仅查看当时重要的内容(退出时保存) 按线程组织的执行时间 测量精确时间,或跨帧的平均时间 测量共享代码段的累积时间 (TS_START_ACC) 突出显示常用来电,慢慢淡化未使用来电 update() 和 draw() 自动进行时间采样 测量 GL 驱动程序执行时间;实际上使用 glBeginQuery(GL_TIME_ELAPSED_EXT) & co 查询 openGL。 可选地使用xMSATimer以获得更高的精度(在 Windows 上推荐)< OF_09(现在并不真正需要)。 可以选择使用xHistoryPlot来显示一段时间内的时间 可选地使用xFontStash进行渲染,它看起来更好,并且比默认的DrawBitmapFont 绘制速度更快。(参见 drawUiWithFontStash()) 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
ofxTimeMeasurements-main.zip (21个子文件)
ofxTimeMeasurements
.travis.yml 5KB
example
config.make 6KB
src
main.cpp 932B
ofApp.h 532B
ofApp.cpp 4KB
addons.make 20B
License.md 1KB
ReadMe.md 12KB
ofxaddons_thumbnail.png 214KB
appveyor.yml 882B
src
MinimalTree.cpp 3KB
GL_Measurement.h 2KB
ofxTimeMeasurementsScoped.cpp 547B
ofxTimeMeasurements.cpp 51KB
ofxTimeMeasurementsScoped.h 375B
MinimalTree.h 1KB
ofxTimeMeasurements.h 14KB
ofxTimeMeasurementsMacros.h 8KB
.gitignore 14B
addon_config.mk 2KB
scripts
ci
install.sh 353B
共 21 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9157
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- libADLMIDI1-1.5.1-bp155.1.7.aarch64.rpm
- 基于python和resnet50的垃圾分类识别项目源码+全部数据.zip
- C语言进阶学习资料,关于预处理,文件处理,结构体,位移运算的学习 大学生期末复习资料,程序设计课程复习资料
- c++少儿编程专业教师使用资料
- box1234567890
- 少儿编程资料,c++少儿编程专业资料
- libADLMIDI1-1.5.1-bp156.2.6.aarch64.rpm
- java源码 仿360buy京东商城源码 京东JavaWeb项目源代码.rar
- libADLMIDI1-1.5.1-1.2.riscv64.rpm
- 基于ASP的BS架构工艺品展示系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功