1 | // Check profile with a single new call and set of loads and stores. Ensures |
2 | // we get the same profile regardless of whether the memory is deallocated |
3 | // before exit. |
4 | |
5 | // RUN: %clangxx_memprof -O0 %s -o %t |
6 | // RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s |
7 | |
8 | // RUN: %clangxx_memprof -DFREE -O0 %s -o %t |
9 | // RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s |
10 | |
11 | // Try again with callbacks instead of inline sequences |
12 | // RUN: %clangxx_memprof -mllvm -memprof-use-callbacks -O0 %s -o %t |
13 | // RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s |
14 | |
15 | // This is actually: |
16 | // Memory allocation stack id = STACKID |
17 | // alloc_count 1, size (ave/min/max) 40.00 / 40 / 40 |
18 | // but we need to look for them in the same CHECK to get the correct STACKID. |
19 | // CHECK: Memory allocation stack id = [[STACKID:[0-9]+]]{{[[:space:]].*}}alloc_count 1, size (ave/min/max) 40.00 / 40 / 40 |
20 | // CHECK-NEXT: access_count (ave/min/max): 20.00 / 20 / 20 |
21 | // CHECK-NEXT: lifetime (ave/min/max): [[AVELIFETIME:[0-9]+]].00 / [[AVELIFETIME]] / [[AVELIFETIME]] |
22 | // CHECK-NEXT: num migrated: {{[0-1]}}, num lifetime overlaps: 0, num same alloc cpu: 0, num same dealloc_cpu: 0 |
23 | // CHECK: Stack for id [[STACKID]]: |
24 | // CHECK-NEXT: #0 {{.*}} in operator new |
25 | // CHECK-NEXT: #1 {{.*}} in main {{.*}}:[[@LINE+6]] |
26 | |
27 | #include <stdio.h> |
28 | #include <stdlib.h> |
29 | |
30 | int main() { |
31 | int *p = new int[10]; |
32 | for (int i = 0; i < 10; i++) |
33 | p[i] = i; |
34 | int j = 0; |
35 | for (int i = 0; i < 10; i++) |
36 | j += p[i]; |
37 | #ifdef FREE |
38 | delete[] p; |
39 | #endif |
40 | |
41 | return 0; |
42 | } |
43 | |