

# ID array omitted

global sampling_threshold[19]
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 is not used in verbose mode

    # Probe name -> Probe sampling threshold
    sampling_threshold["_.stapsdt.base"] = 20
    sampling_threshold["_Z10BubbleSortPii"] = 20
    sampling_threshold["_Z10InsertSortPii"] = 20
    sampling_threshold["_Z12BadPartitionPiii"] = 20
    sampling_threshold["_Z12QuickSortBadPii"] = 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["__libc_csu_fini"] = 20
    sampling_threshold["__libc_csu_init"] = 20
    sampling_threshold["_fini"] = 20
    sampling_threshold["_init"] = 20
    sampling_threshold["_start"] = 20
    sampling_threshold["data_start"] = 20
    sampling_threshold["main"] = 20
    sampling_threshold["BEFORE_CYCLE"] = 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("INSIDE_CYCLE")?
{
    pname = ppfunc()
    tid = tid()
    printf("2 %d %d;%s\n", tid, read_stopwatch_ns("timestamp"), pname)
}

probe process("cmp").function("_.stapsdt.base").call?,
      process("cmp").function("_Z10BubbleSortPii").call?,
      process("cmp").function("_Z10InsertSortPii").call?,
      process("cmp").function("_Z12BadPartitionPiii").call?,
      process("cmp").function("_Z12QuickSortBadPii").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("__libc_csu_fini").call?,
      process("cmp").function("__libc_csu_init").call?,
      process("cmp").function("_fini").call?,
      process("cmp").function("_init").call?,
      process("cmp").function("_start").call?,
      process("cmp").function("data_start").call?,
      process("cmp").function("main").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;%s\n", tid, read_stopwatch_ns("timestamp"), pname)
    }
    sampling_counter[tid, pname] ++

}

probe process("cmp").function("_.stapsdt.base").return?,
      process("cmp").function("_Z10BubbleSortPii").return?,
      process("cmp").function("_Z10InsertSortPii").return?,
      process("cmp").function("_Z12BadPartitionPiii").return?,
      process("cmp").function("_Z12QuickSortBadPii").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("__libc_csu_fini").return?,
      process("cmp").function("__libc_csu_init").return?,
      process("cmp").function("_fini").return?,
      process("cmp").function("_init").return?,
      process("cmp").function("_start").return?,
      process("cmp").function("data_start").return?,
      process("cmp").function("main").return?
{
    pname = ppfunc()
    tid = tid()
    
    if (sampling_flag[tid, pname] > 0) {
        printf("1 %d %d;%s\n", tid, read_stopwatch_ns("timestamp"), pname)
        sampling_flag[tid, pname] --
    }

}

probe process("cmp").mark("BEFORE_CYCLE")?
{
    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;%s\n", tid, read_stopwatch_ns("timestamp"), pname)
    }
    sampling_counter[tid, pname] ++

}

probe process("cmp").mark("BEFORE_CYCLE_end")?
{
    pname = ppfunc()
    tid = tid()
    
    if (sampling_flag[tid, pname] > 0) {
        printf("4 %d %d;%s\n", tid, read_stopwatch_ns("timestamp"), pname)
        sampling_flag[tid, pname] --
    }

}
