1 // Printing memory profiling only works in the configuration where we can 2 // detect leaks. 3 // REQUIRES: leak-detection 4 // 5 // RUN: %clangxx_asan %s -o %t 6 // RUN: %run %t 100 10 2>&1 | FileCheck %s --check-prefix=CHECK-100-10 7 // RUN: %run %t 100 1 2>&1 | FileCheck %s --check-prefix=CHECK-100-1 8 // RUN: %run %t 50 10 2>&1 | FileCheck %s --check-prefix=CHECK-50-10 9 #include <sanitizer/common_interface_defs.h> 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 char *sink[1000]; 15 16 int main(int argc, char **argv) { 17 if (argc < 3) 18 return 1; 19 20 int idx = 0; 21 for (int i = 0; i < 17; i++) 22 sink[idx++] = new char[131000]; 23 for (int i = 0; i < 28; i++) 24 sink[idx++] = new char[24000]; 25 26 __sanitizer_print_memory_profile(atoi(argv[1]), atoi(argv[2])); 27 } 28 29 // CHECK-100-10: Live Heap Allocations: {{.*}}; showing top 100% (at most 10 unique contexts) 30 // CHECK-100-10: 2227000 byte(s) ({{.*}}%) in 17 allocation(s) 31 // CHECK-100-10: 672000 byte(s) ({{.*}}%) in 28 allocation(s) 32 33 // CHECK-100-1: Live Heap Allocations: {{.*}}; showing top 100% (at most 1 unique contexts) 34 // CHECK-100-1: 2227000 byte(s) ({{.*}}%) in 17 allocation(s) 35 // CHECK-100-1-NOT: allocation 36 37 // CHECK-50-10: Live Heap Allocations: {{.*}}; showing top 50% (at most 10 unique contexts) 38 // CHECK-50-10: 2227000 byte(s) ({{.*}}%) in 17 allocation(s) 39 // CHECK-50-10-NOT: allocation 40