1 ; RUN: llvm-profgen --unsymbolized-profile=%S/Inputs/fs-discriminator-probe.raw.prof --binary=%S/Inputs/fs-discriminator-probe.perfbin --output=%t1
2 ; RUN: llvm-profdata show --sample --show-sec-info-only %t1 | FileCheck %s --check-prefix=CHECK-SECTION
3 ; RUN: llvm-profdata merge --sample %t1 -o %t2 --text
4 ; RUN: FileCheck %s --input-file %t2 --check-prefix=CHECK
6 ; CHECK-SECTION: ProfileSummarySection - Offset: [[#]], Size: [[#]], Flags: {fs-discriminator}
8 ; CHECK: partition_pivot_first:29661:2739
10 ; CHECK-NEXT: 2.1: 2739
11 ; CHECK-NEXT: 2.11265: 0
14 ; CHECK-NEXT: 5.1: 508
15 ; CHECK-NEXT: 6.2: 508
16 ; CHECK-NEXT: 7.3: 2780
19 ; CHECK-NEXT: 10: 6457
20 ; CHECK-NEXT: 11: swap:508
21 ; CHECK-NEXT: 1.7680: 508
22 ; CHECK-NEXT: !CFGChecksum: 4294967295
23 ; CHECK-NEXT: 12: swap:6457
24 ; CHECK-NEXT: 1.7168: 6457
25 ; CHECK-NEXT: !CFGChecksum: 4294967295
26 ; CHECK-NEXT: !CFGChecksum: 563159988274199
27 ; CHECK-NEXT: main:16724:1478
29 ; CHECK-NEXT: 2.1: 1478
30 ; CHECK-NEXT: 2.3585: 0
33 ; CHECK-NEXT: 5.1537: 0
41 ; CHECK-NEXT: 14: 3105
42 ; CHECK-NEXT: 15: 1567
45 ; CHECK-NEXT: 18: 3105
46 ; CHECK-NEXT: !CFGChecksum: 1126178599120658
47 ; CHECK-NEXT: partition_pivot_last:10497:0
50 ; CHECK-NEXT: 2.6145: 1095
51 ; CHECK-NEXT: 2.7681: 241
52 ; CHECK-NEXT: 2.8193: 0
55 ; CHECK-NEXT: 4.3072: 1098
56 ; CHECK-NEXT: 4.12800: 0
58 ; CHECK-NEXT: 5.5632: 0
59 ; CHECK-NEXT: 5.6144: 1053
60 ; CHECK-NEXT: 6.1: 1095
61 ; CHECK-NEXT: 6.12801: 0
62 ; CHECK-NEXT: 6.13825: 241
63 ; CHECK-NEXT: 7.2: 1095
64 ; CHECK-NEXT: 7.7170: 241
65 ; CHECK-NEXT: 7.7682: 0
67 ; CHECK-NEXT: 9: swap:1053
68 ; CHECK-NEXT: 1.1024: 1053
69 ; CHECK-NEXT: 1.4608: 0
70 ; CHECK-NEXT: 1.15360: 0
71 ; CHECK-NEXT: !CFGChecksum: 4294967295
72 ; CHECK-NEXT: 10: swap:1095
73 ; CHECK-NEXT: 1.14848: 1095
74 ; CHECK-NEXT: !CFGChecksum: 4294967295
75 ; CHECK-NEXT: !CFGChecksum: 563108639284859
76 ; CHECK-NEXT: quick_sort:4881:2519
78 ; CHECK-NEXT: 1.15360: 503
83 ; CHECK-NEXT: !CFGChecksum: 844480566202114
88 ; clang -O3 -g -mllvm --enable-fs-discriminator -fdebug-info-for-profiling -fpseudo-probe-for-profiling qsort.c -o a.out
92 void swap(int *a, int *b) {
98 int partition_pivot_last(int* array, int low, int high) {
99 int pivot = array[high];
101 for (int j = low; j < high; j++)
102 if (array[j] < pivot)
103 swap(&array[++i], &array[j]);
104 swap(&array[i + 1], &array[high]);
108 int partition_pivot_first(int* array, int low, int high) {
109 int pivot = array[low];
111 for (int j = low + 1; j <= high; j++)
112 if (array[j] < pivot) { if (j != i) swap(&array[i], &array[j]); i++;}
113 swap(&array[i - 1], &array[low]);
117 void quick_sort(int* array, int low, int high, int (*partition_func)(int *, int, int)) {
119 int pi = (*partition_func)(array, low, high);
120 quick_sort(array, low, pi - 1, partition_func);
121 quick_sort(array, pi + 1, high, partition_func);
126 const int size = 200;
128 int *array = malloc(size * sizeof(int));
129 for(int i = 0; i < 100 * 1000; i++) {
130 for(int j = 0; j < size; j++)
131 array[j] = j % 10 ? rand() % size: j;
132 int (*fptr)(int *, int, int) = i % 3 ? partition_pivot_last : partition_pivot_first;
133 quick_sort(array, 0, size - 1, fptr);
134 sum += array[i % size];
136 printf("sum=%d\n", sum);