DDLTimeProfiler 1.0.4

DDLTimeProfiler 1.0.4

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release May 2015

Maintained by Georgiy Malyukov.



DDLTimeProfiler is the simple time profiling library based on MTU (Mach Time Units) in Objective-C. You can create a new profiler at any time and log any count of "safe spots" whenever you need until you stop it. You just need to keep a strong reference to created profiler until it stopped.

DDLTimeProfiler uses standard NSLog() function to print your spots synchronously in a main thread to keep your logs actual at any time.

Adding DDLTimeProfiler to your project

Source files

Alternatively you can directly add the DDLTimeProfiler.h and DDLTimeProfiler.m source files to your project.

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. Open your project in Xcode, then drag and drop DDLTimeProfiler.h and DDLTimeProfiler.m onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
  3. Include DDLTimeProfiler wherever you need it with #import "DDLTimeProfiler.h".

Usage

When you want to start profiling some critical code, just start a new profiler by calling static method

DDLTimeProfiler *profiler = [DDLTimeProfiler startWithMessage:@"I'm profiling my special code!"];

// or use shorter version
DDLTimeProfiler *profiler = [DDLTimeProfiler start];

Note that you can use short method version without specifying an input message if you do not need it. Each method in the library has its detailed and short versions.

Now profiling is started. When you need to log a spot, just call this:

[profiler pointWithMessage:@"I've finished some kind of work!"];

If you save your point value (points stored as seconds with high precision transformed from nano seconds) - you can use it for further measurement. For example, in this scenario:

double p1 = [profiler point];
// some critical code block
// ...
double p2 = [profiler point];

NSLog(@"My critical code passed in %.3f", p2 - p1); // just subtract them

When you want to finish your measurement, stop a profiler by calling stop:

[profiler stopWithMessage:@"Some profiling finished!"];

After that you can create a new profiler by calling start as you see above, it's no necessary to keep a strong reference to a stopped profiler anymore.

You can create as many profilers as you need, just be sure that you keep strong references to them.

Thread Safety

DDLTimeProfiler uses standard NSLog() function to print your logs and a system functions to measure time, but you must keep a strong reference to each profiler you have created, so it's not thread safe. You should keep in mind to use your profilers in a same thread in which you've created them.

Samples

You can find sample application in the Samples folder.

License

MIT. See LICENSE for details.