

global probe_id[35]

global sampling_threshold[26]
global sampling_counter[2048]
global sampling_flag[2048]

# Recursion arrays omitted

# Timed Sampling omitted
global stopwatch_on = 0

probe process("cmp").begin {
    # Probe name -> Probe ID
    probe_id["_GLOBAL__sub_I__Z9QuickSortPii"] = 0
    probe_id["_Z10BubbleSortPii"] = 1
    probe_id["_Z10InsertSortPii"] = 2
    probe_id["_Z12BadPartitionPiii"] = 3
    probe_id["_Z12QuickSortBadPii"] = 4
    probe_id["_Z41__static_initialization_and_destruction_0ii"] = 5
    probe_id["_Z4SwapRiS_"] = 6
    probe_id["_Z4swapPiii"] = 7
    probe_id["_Z8HeapSortPii"] = 8
    probe_id["_Z9PartitionPiii"] = 9
    probe_id["_Z9QuickSortPii"] = 10
    probe_id["_Z9repairTopPiii"] = 11
    probe_id["_fini"] = 12
    probe_id["deregister_tm_clones"] = 13
    probe_id["frame_dummy"] = 14
    probe_id["main"] = 15
    probe_id["register_tm_clones"] = 16
    probe_id["array__create"] = 17
    probe_id["array__end"] = 18
    probe_id["cmethod__deconstruct"] = 19
    probe_id["cmethod__entry"] = 20
    probe_id["find__require__begin"] = 21
    probe_id["find__require__entry"] = 22
    probe_id["gc__mark__begin"] = 23
    probe_id["gc__sweep__begin"] = 24
    probe_id["hash__create"] = 25
    probe_id["load__entry"] = 26
    probe_id["method__cache__clear"] = 27
    probe_id["method__entry"] = 28
    probe_id["object__create"] = 29
    probe_id["parse__begin"] = 30
    probe_id["raise"] = 31
    probe_id["require__entry"] = 32
    probe_id["string__create"] = 33
    probe_id["symbol__create"] = 34

    # Probe name -> Probe sampling threshold
    sampling_threshold["_GLOBAL__sub_I__Z9QuickSortPii"] = 20
    sampling_threshold["_Z10BubbleSortPii"] = 20
    sampling_threshold["_Z10InsertSortPii"] = 20
    sampling_threshold["_Z12BadPartitionPiii"] = 20
    sampling_threshold["_Z12QuickSortBadPii"] = 20
    sampling_threshold["_Z41__static_initialization_and_destruction_0ii"] = 20
    sampling_threshold["_Z4SwapRiS_"] = 20
    sampling_threshold["_Z4swapPiii"] = 20
    sampling_threshold["_Z8HeapSortPii"] = 20
    sampling_threshold["_Z9PartitionPiii"] = 20
    sampling_threshold["_Z9QuickSortPii"] = 20
    sampling_threshold["_Z9repairTopPiii"] = 20
    sampling_threshold["_fini"] = 20
    sampling_threshold["deregister_tm_clones"] = 20
    sampling_threshold["frame_dummy"] = 20
    sampling_threshold["main"] = 20
    sampling_threshold["register_tm_clones"] = 20
    sampling_threshold["cmethod__entry"] = 20
    sampling_threshold["find__require__entry"] = 20
    sampling_threshold["gc__mark__begin"] = 20
    sampling_threshold["gc__sweep__begin"] = 20
    sampling_threshold["load__entry"] = 20
    sampling_threshold["method__entry"] = 20
    sampling_threshold["parse__begin"] = 20
    sampling_threshold["require__entry"] = 20
    sampling_threshold["symbol__create"] = 20

    if (!stopwatch_on) {
        stopwatch_on = 1
        start_stopwatch("timestamp")
    }
    printf("7 %d %d %d %d;%s\n", tid(), pid(), ppid(), read_stopwatch_ns("timestamp"), execname())
}

probe process("cmp").end
{
    printf("8 %d %d %d %d;%s\n", tid(), pid(), ppid(), read_stopwatch_ns("timestamp"), execname())
}


probe process("cmp").thread.begin {
    printf("5 %d %d %d;%s\n", tid(), pid(), read_stopwatch_ns("timestamp"), execname())
}
    
probe process("cmp").thread.end {
    printf("6 %d %d %d;%s\n", tid(), pid(), read_stopwatch_ns("timestamp"), execname())
    delete sampling_counter[tid(), *]
    delete sampling_flag[tid(), *]
}

probe process("cmp").mark("array__create")?,
      process("cmp").mark("array__end")?,
      process("cmp").mark("cmethod__deconstruct")?,
      process("cmp").mark("find__require__begin")?,
      process("cmp").mark("hash__create")?,
      process("cmp").mark("method__cache__clear")?,
      process("cmp").mark("object__create")?,
      process("cmp").mark("raise")?,
      process("cmp").mark("string__create")?
{
    pname = ppfunc()
    tid = tid()
    printf("2 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
}

probe process("cmp").function("_GLOBAL__sub_I__Z9QuickSortPii").call?,
      process("cmp").function("_Z10BubbleSortPii").call?,
      process("cmp").function("_Z10InsertSortPii").call?,
      process("cmp").function("_Z12BadPartitionPiii").call?,
      process("cmp").function("_Z12QuickSortBadPii").call?,
      process("cmp").function("_Z41__static_initialization_and_destruction_0ii").call?,
      process("cmp").function("_Z4SwapRiS_").call?,
      process("cmp").function("_Z4swapPiii").call?,
      process("cmp").function("_Z8HeapSortPii").call?,
      process("cmp").function("_Z9PartitionPiii").call?,
      process("cmp").function("_Z9QuickSortPii").call?,
      process("cmp").function("_Z9repairTopPiii").call?,
      process("cmp").function("_fini").call?,
      process("cmp").function("deregister_tm_clones").call?,
      process("cmp").function("frame_dummy").call?,
      process("cmp").function("main").call?,
      process("cmp").function("register_tm_clones").call?
{
    pname = ppfunc()
    tid = tid()
    
    counter = sampling_counter[tid, pname]
    if (counter == 0 || counter == sampling_threshold[pname]) {
        sampling_counter[tid, pname] = 0
        sampling_flag[tid, pname] ++
        printf("0 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
    }
    sampling_counter[tid, pname] ++

}

probe process("cmp").function("_GLOBAL__sub_I__Z9QuickSortPii").return?,
      process("cmp").function("_Z10BubbleSortPii").return?,
      process("cmp").function("_Z10InsertSortPii").return?,
      process("cmp").function("_Z12BadPartitionPiii").return?,
      process("cmp").function("_Z12QuickSortBadPii").return?,
      process("cmp").function("_Z41__static_initialization_and_destruction_0ii").return?,
      process("cmp").function("_Z4SwapRiS_").return?,
      process("cmp").function("_Z4swapPiii").return?,
      process("cmp").function("_Z8HeapSortPii").return?,
      process("cmp").function("_Z9PartitionPiii").return?,
      process("cmp").function("_Z9QuickSortPii").return?,
      process("cmp").function("_Z9repairTopPiii").return?,
      process("cmp").function("_fini").return?,
      process("cmp").function("deregister_tm_clones").return?,
      process("cmp").function("frame_dummy").return?,
      process("cmp").function("main").return?,
      process("cmp").function("register_tm_clones").return?
{
    pname = ppfunc()
    tid = tid()
    
    if (sampling_flag[tid, pname] > 0) {
        printf("1 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
        sampling_flag[tid, pname] --
    }

}

probe process("cmp").mark("cmethod__entry")?,
      process("cmp").mark("find__require__entry")?,
      process("cmp").mark("gc__mark__begin")?,
      process("cmp").mark("gc__sweep__begin")?,
      process("cmp").mark("load__entry")?,
      process("cmp").mark("method__entry")?,
      process("cmp").mark("parse__begin")?,
      process("cmp").mark("require__entry")?,
      process("cmp").mark("symbol__create")?
{
    pname = ppfunc()
    tid = tid()
    
    counter = sampling_counter[tid, pname]
    if (counter == 0 || counter == sampling_threshold[pname]) {
        sampling_counter[tid, pname] = 0
        sampling_flag[tid, pname] ++
        printf("3 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
    }
    sampling_counter[tid, pname] ++

}

probe process("cmp").mark("cmethod__return")?,
      process("cmp").mark("find__require__return")?,
      process("cmp").mark("gc__mark__end")?,
      process("cmp").mark("gc__sweep__end")?,
      process("cmp").mark("load__return")?,
      process("cmp").mark("method__return")?,
      process("cmp").mark("parse__end")?,
      process("cmp").mark("require__return")?,
      process("cmp").mark("symbol__deconstruct")?
{
    pname = ppfunc()
    tid = tid()
    
    if (sampling_flag[tid, pname] > 0) {
        printf("4 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
        sampling_flag[tid, pname] --
    }

}
