1 //===--- rtsan_stats.cpp - Realtime Sanitizer -------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Part of the RealtimeSanitizer runtime library 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "rtsan/rtsan_stats.h" 14 #include "rtsan/rtsan_flags.h" 15 16 #include "sanitizer_common/sanitizer_atomic.h" 17 #include "sanitizer_common/sanitizer_common.h" 18 19 using namespace __sanitizer; 20 using namespace __rtsan; 21 22 static atomic_uint32_t total_error_count{0}; 23 static atomic_uint32_t unique_error_count{0}; 24 static atomic_uint32_t suppressed_count{0}; 25 26 void __rtsan::IncrementTotalErrorCount() { 27 atomic_fetch_add(&total_error_count, 1, memory_order_relaxed); 28 } 29 30 void __rtsan::IncrementUniqueErrorCount() { 31 atomic_fetch_add(&unique_error_count, 1, memory_order_relaxed); 32 } 33 34 static u32 GetTotalErrorCount() { 35 return atomic_load(&total_error_count, memory_order_relaxed); 36 } 37 38 static u32 GetUniqueErrorCount() { 39 return atomic_load(&unique_error_count, memory_order_relaxed); 40 } 41 42 void __rtsan::IncrementSuppressedCount() { 43 atomic_fetch_add(&suppressed_count, 1, memory_order_relaxed); 44 } 45 46 static u32 GetSuppressedCount() { 47 return atomic_load(&suppressed_count, memory_order_relaxed); 48 } 49 50 void __rtsan::PrintStatisticsSummary() { 51 ScopedErrorReportLock l; 52 Printf("RealtimeSanitizer exit stats:\n"); 53 Printf(" Total error count: %u\n", GetTotalErrorCount()); 54 Printf(" Unique error count: %u\n", GetUniqueErrorCount()); 55 56 if (flags().ContainsSuppresionFile()) 57 Printf(" Suppression count: %u\n", GetSuppressedCount()); 58 } 59