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>
10int main(int argc, char **argv) {
11 char *x = (char *)malloc(size: 10);
12 memset(s: x, c: 0, n: 10);
13 free(ptr: x);
14 __memprof_profile_dump();
15 x = (char *)malloc(size: 10);
16 memset(s: x, c: 0, n: 10);
17 free(ptr: 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

source code of compiler-rt/test/memprof/TestCases/memprof_profile_dump.cpp