

global probe_id[20]
# Sampling arrays omitted
# Recursion arrays omitted

# Timed Sampling omitted
global stopwatch_on = 0

probe process("cmp").begin {
    # Probe name -> Probe ID
    probe_id["_.stapsdt.base"] = 0
    probe_id["_Z10BubbleSortPii"] = 1
    probe_id["_Z10InsertSortPii"] = 2
    probe_id["_Z12BadPartitionPiii"] = 3
    probe_id["_Z12QuickSortBadPii"] = 4
    probe_id["_Z4SwapRiS_"] = 5
    probe_id["_Z4swapPiii"] = 6
    probe_id["_Z8HeapSortPii"] = 7
    probe_id["_Z9PartitionPiii"] = 8
    probe_id["_Z9QuickSortPii"] = 9
    probe_id["_Z9repairTopPiii"] = 10
    probe_id["__libc_csu_fini"] = 11
    probe_id["__libc_csu_init"] = 12
    probe_id["_fini"] = 13
    probe_id["_init"] = 14
    probe_id["_start"] = 15
    probe_id["data_start"] = 16
    probe_id["main"] = 17
    probe_id["BEFORE_CYCLE"] = 18
    probe_id["INSIDE_CYCLE"] = 19

    # Probe name -> Probe sampling threshold

    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())
    # Sampling cleanup omitted
}

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()
    printf("0 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[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()
    printf("1 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
}

probe process("cmp").mark("BEFORE_CYCLE")?
{
    pname = ppfunc()
    tid = tid()
    printf("3 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
}

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

probe process("cmp").mark("INSIDE_CYCLE")?
{
    pname = ppfunc()
    tid = tid()
    printf("2 %d %d;%d\n", tid, read_stopwatch_ns("timestamp"), probe_id[pname])
}
