File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,15 @@ SANITIZER_INTERFACE_ATTRIBUTE void __memprof_version_mismatch_check_v1();
3535SANITIZER_INTERFACE_ATTRIBUTE
3636void __memprof_record_access (void const volatile *addr);
3737
38+ SANITIZER_INTERFACE_ATTRIBUTE
39+ void __memprof_record_access_hist (void const volatile *addr);
40+
3841SANITIZER_INTERFACE_ATTRIBUTE
3942void __memprof_record_access_range (void const volatile *addr, uptr size);
4043
44+ SANITIZER_INTERFACE_ATTRIBUTE
45+ void __memprof_record_access_range_hist (void const volatile *addr, uptr size);
46+
4147SANITIZER_INTERFACE_ATTRIBUTE void __memprof_print_accumulated_stats ();
4248
4349SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
@@ -51,6 +57,10 @@ extern uptr __memprof_shadow_memory_dynamic_address;
5157
5258SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
5359 __memprof_profile_filename[1 ];
60+
61+ SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern bool
62+ __memprof_histogram;
63+
5464SANITIZER_INTERFACE_ATTRIBUTE int __memprof_profile_dump ();
5565SANITIZER_INTERFACE_ATTRIBUTE void __memprof_profile_reset ();
5666
Original file line number Diff line number Diff line change 1+ // Test the histogram support in memprof using the text format output.
2+ // Shadow memory counters per object are limited to 8b. In memory counters
3+ // aggregating counts across multiple objects are 64b.
4+
5+ // RUN: %clangxx_memprof -O0 -mllvm -memprof-histogram -mllvm -memprof-use-callbacks=true %s -o %t
6+ // RUN: %env_memprof_opts=print_text=1:histogram=1:log_path=stdout %run %t 2>&1 > /tmp/test.log
7+ // RUN: cat /tmp/test.log | FileCheck %s
8+
9+ #include < stdio.h>
10+ #include < stdlib.h>
11+
12+ int main () {
13+ // Allocate memory that will create a histogram
14+ char *buffer = (char *)malloc (1024 );
15+ if (!buffer)
16+ return 1 ;
17+
18+ for (int i = 0 ; i < 10 ; ++i) {
19+ // Access every 8th byte (since shadow granularity is 8b.
20+ buffer[i * 8 ] = ' A' ;
21+ }
22+
23+ for (int j = 0 ; j < 200 ; ++j) {
24+ buffer[8 ] = ' B' ; // Count = previous count + 200
25+ }
26+
27+ for (int j = 0 ; j < 400 ; ++j) {
28+ buffer[16 ] = ' B' ; // Count is saturated at 255
29+ }
30+
31+ // Free the memory to trigger MIB creation with histogram
32+ free (buffer);
33+
34+ printf (" Test completed successfully\n " );
35+ return 0 ;
36+ }
37+
38+ // CHECK: AccessCountHistogram[128]: 1 201 255 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
39+ // CHECK: Test completed successfully
You can’t perform that action at this time.
0 commit comments