Skip to content

Instantly share code, notes, and snippets.

@wighawag
Created February 11, 2016 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wighawag/2d0824b61cb5712a4def to your computer and use it in GitHub Desktop.
Save wighawag/2d0824b61cb5712a4def to your computer and use it in GitHub Desktop.
Haxe telemetry in a unit test
#if HXCPP_TELEMETRY
public function testAllocation(){
var instanceUnderTest = new Testing();
//start telemetry
var threadNum = untyped __global__.__hxcpp_hxt_start_telemetry(true, true);
instanceUnderTest.methodThatShoulDoNoAllocation();
//force gc to ensure allocation are tracked?
cpp.vm.Gc.run(true);
//stash the data
untyped __global__.__hxcpp_hxt_stash_telemetry();
//gather the data and return the number of allocation
var numAllocations = getNumAllocations(threadNum);
Assert.equals(0, numAllocations);
}
@:functionCode('
TelemetryFrame* frame = __hxcpp_hxt_dump_telemetry(thread_num);
if (frame->allocation_data!=0){
return frame->allocation_data->size();
}
return -1;
')
public static function getNumAllocations(thread_num : Int) : Int{
return 10;
}
#end
@jcward
Copy link

jcward commented Feb 11, 2016

Try something like:

@:functionCode('
    TelemetryFrame* frame = __hxcpp_hxt_dump_telemetry(thread_num);
    if (frame->allocation_data!=0){
        int size = frame->allocation_data->size();
        int i = 0;
        int count = 0;
        while (i<size) {
            if (frame->allocation_data->at(i)==0) { // allocation
                i+=5;
                count++;
            }
            else if (frame->allocation_data->at(i)==1) { i+=2; } // deallocation
            else if (frame->allocation_data->at(i)==2) { i+=4; } // reallocation
        }
        return count;
    }
    return -1;
')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment