[llvm-bugs] [Bug 41190] New: The file format of sample profile is inconsistent with AutoFDO

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 21 18:36:12 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41190

            Bug ID: 41190
           Summary: The file format of sample profile  is inconsistent
                    with AutoFDO
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: cszide at 163.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 21645
  --> https://bugs.llvm.org/attachment.cgi?id=21645&action=edit
the source file

As described in documents, the file format of sample profile in llvm is as
follows.

// Sample profiles are written as ASCII text. The file is divided into
// sections, which correspond to each of the functions executed at runtime.
// Each section has the following format
//
//     function1:total_samples:total_head_samples
//      offset1[.discriminator]: number_of_samples [fn1:num fn2:num ... ]
//      offset2[.discriminator]: number_of_samples [fn3:num fn4:num ... ]
//      ...
//      offsetN[.discriminator]: number_of_samples [fn5:num fn6:num ... ]
//      offsetA[.discriminator]: fnA:num_of_total_samples
//       offsetA1[.discriminator]: number_of_samples [fn7:num fn8:num ... ]
//       ...
//

Source line offset represents the line number in the function where the sample
was collected. The line number is always relative to the line where symbol of
the function is defined. So, if the function has its header at line 280, the
offset 13 is at line 293 in the file.

However, when I use AutoFDO to generate the sample profile of a program, I find
the file format is inconsistent with llvm. For example, the following is the
text format of sample profile of a function generated by AutoFDO.

Bubble:307889687:0
 145: 0
 147: 0
 148: 0
 150: 826
 152: 814
 153: 3396010
 155: 3386796
 156: 1921076
 157: 1921072
 158: 1921072
 160: 3396018
 163: 826
 165: 0
 166: 0
 168: 0

The source code of this function is as follows. The number before each line is
the line number in the source file.
145 void Bubble(int run) {
146  int i, j;
147  bInitarr();
148  top = sortelements;
149
150  while (top > 1) {
151
152    i = 1;
153    while (i < top) {
154
155      if (sortlist[i] > sortlist[i + 1]) {
156        j = sortlist[i];
157        sortlist[i] = sortlist[i + 1];
158        sortlist[i + 1] = j;
159      }
160      i = i + 1;
161    }
162
163    top = top - 1;
164  }
165  if ((sortlist[1] != littlest) || (sortlist[sortelements] != biggest))
166    printf("Error3 in Bubble.\n");
167  // printf("%d\n", sortlist[run + 1]);
168 }

Obviously, in AutoFDO, the source line offset is the line number in the source
file. Thus, when I use '-sample-profile' pass (or -fprofile-sample-use of
clang) to annotate the profile information in IR file, the result is not
correct.

The following are my steps.
$clang -gline-tables-only Bubblesort.c -o bubb
$perf record -b ./bubb
$create_llvm_prof --binary=./bubb --out=bubb.prof
$clang -gline-tables-only -fprofile-sample-use=bubb.prof -emit-llvm -c
Bubblesort.c -o bubb.bc
or
$clang -gline-tables-only -emit-llvm -c Bubblesort.c -o bubb1.bc
#opt -sample-profile -sample-profile-file=bubb.prof bubb1.bc -o bubb.bc

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190322/a981e2cb/attachment-0001.html>


More information about the llvm-bugs mailing list