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