profiler

Profiler for all targets.
https://bitbucket.org/yar3333/haxe-profiler

To install, run:

haxelib install profiler 1.0.6 

See using Haxelib in Haxelib documentation for more information.

README.md

profiler haxe library

This library help you to profile the code.

Using example:

@:build(Profiler.buildAll())
class Test
{
	public function new() {}
	
	public function pubF()
	{
		Sys.sleep(1);
		privF();
		Sys.sleep(2);
	}
	
	function privF() Sys.sleep(0.5);
}

class Main
{
	static function main()
	{
		var test = new Test();
		
		test.pubF();
		test.pubF();
		
		Sys.println(Profiler.getCallStackResultsAsText());
	}
}

Result:

0000 | Test.new
3503 | Test.pubF
0500 |     Test.privF
3501 | Test.pubF
0500 |     Test.privF

Numbers like 3501 means 3,501 seconds.

Manual collect data

Profiler has two alternative: direct call begin/end or measure with a callback function.

Direct call begin/end

Profiler.begin("myCodeA");
// code to measure duration
Profiler.end();

Measure with a callback function

Profiler.measure("myCodeA", function()
{
    // code to measure duration
});

var result = Profiler.measureResult("myCodeB", function()
{
    // code to measure duration
    return "abc"; // result
});

Collect data by macro

Use @:build(Profiler.buildAll()) to profile all methods of class. Use @:noprofile to exclude methods.

Use @:build(Profiler.buildMarked()) to profile only methods with a @:profile meta.

@:build(Profiler.buildMarked())
class MyClassToProfile
{
    @:profile public function f() {  trace("f() called"); }
}

Getting collected data

// trace summary
Profiler.traceResults();

// get all calls as linear array
var results = Profiler.getCallStackResults();

// get all calls as tree
var callTree = Profiler.getCallStack();
// it is very useful to generate human-readable json from this
trace(Json.stringify({ name:"myApp", stack:callTree }));
Contributors
yar3333
Version
1.0.6
Published
2 years ago
License
LGPL

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github