1 // RUN: %clang_pgogen -O2 -mllvm -pgo-function-entry-coverage -o %t %s
2 // RUN: %run %t %t.profraw 1 1
3 // RUN: llvm-profdata show --all-functions --counts %t.profraw | FileCheck %s
5 // FIXME: llvm-profdata exits with "Malformed instrumentation profile data"
6 // XFAIL: target={{.*windows.*}}
8 #include "profile_test.h"
13 int __llvm_profile_runtime
= 0;
14 uint64_t __llvm_profile_get_size_for_buffer(void);
15 int __llvm_profile_write_buffer(char *);
16 void __llvm_profile_reset_counters(void);
17 int __llvm_profile_merge_from_buffer(const char *, uint64_t);
19 __attribute__((noinline
)) int dumpBuffer(const char *FileN
, const char *Buffer
,
21 FILE *File
= fopen(FileN
, "w");
24 if (fwrite(Buffer
, 1, Size
, File
) != Size
)
30 __attribute__((noinline
)) void foo(char c
) {
37 /* This function is not profiled */
38 __attribute__((noinline
)) void bar(int M
) { g
+= M
; }
40 int main(int argc
, const char *argv
[]) {
45 const uint64_t MaxSize
= 10000;
46 static ALIGNED(sizeof(uint64_t)) char Buffer
[MaxSize
];
48 uint64_t Size
= __llvm_profile_get_size_for_buffer();
52 /* Start profiling. */
53 __llvm_profile_reset_counters();
55 /* End profiling by freezing counters. */
56 if (__llvm_profile_write_buffer(Buffer
))
59 /* Its profile will be discarded. */
60 for (i
= 0; i
< 10; i
++)
63 /* Start profiling again and merge in previously
64 saved counters in buffer. */
65 __llvm_profile_reset_counters();
66 __llvm_profile_merge_from_buffer(Buffer
, Size
);
69 if (__llvm_profile_write_buffer(Buffer
))
72 /* Its profile will be discarded. */
75 /* Now it is time to dump the profile to file. */
76 return dumpBuffer(argv
[1], Buffer
, Size
);
79 // CHECK-LABEL: dumpBuffer:
81 // CHECK-NEXT: Block counts: [0]
85 // CHECK-NEXT: Block counts: [1]
89 // CHECK-NEXT: Block counts: [0]
93 // CHECK-NEXT: Block counts: [0]