xref: /llvm-project/compiler-rt/test/memprof/TestCases/memprof_profile_dump.cpp (revision a4b92d61580d9a1ef9f4946ffe8d0bb6949596a8)
1 // RUN: %clangxx_memprof %s -o %t
2 
3 // RUN: %env_memprof_opts=print_text=true:log_path=stdout %run %t | FileCheck --check-prefix=CHECK-TEXT %s
4 // RUN: %env_memprof_opts=log_path=stdout %run %t > %t.memprofraw
5 // RUN: od -c -N 8 %t.memprofraw | FileCheck --check-prefix=CHECK-RAW %s
6 
7 #include <sanitizer/memprof_interface.h>
8 #include <stdlib.h>
9 #include <string.h>
main(int argc,char ** argv)10 int main(int argc, char **argv) {
11   char *x = (char *)malloc(10);
12   memset(x, 0, 10);
13   free(x);
14   __memprof_profile_dump();
15   x = (char *)malloc(10);
16   memset(x, 0, 10);
17   free(x);
18   return 0;
19 }
20 // We should get 2 rounds of profile info, one from the explicit dump request,
21 // and one at exit.
22 //
23 // CHECK-TEXT: Recorded MIBs (incl. live on exit):
24 // CHECK-TEXT: Memory allocation stack id
25 // CHECK-TEXT: Stack for id
26 //
27 // CHECK-TEXT: Recorded MIBs (incl. live on exit):
28 // CHECK-TEXT: Memory allocation stack id
29 // CHECK-TEXT: Stack for id
30 //
31 // For the raw profile just check the header magic. The following check assumes that memprof
32 // runs on little endian architectures.
33 // CHECK-RAW: 0000000 201   r   f   o   r   p   m 377
34