| 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{.val_dont_use: 0}; |
| 23 | static atomic_uint32_t unique_error_count{.val_dont_use: 0}; |
| 24 | static atomic_uint32_t suppressed_count{.val_dont_use: 0}; |
| 25 | |
| 26 | void __rtsan::IncrementTotalErrorCount() { |
| 27 | atomic_fetch_add(a: &total_error_count, v: 1, mo: memory_order_relaxed); |
| 28 | } |
| 29 | |
| 30 | void __rtsan::IncrementUniqueErrorCount() { |
| 31 | atomic_fetch_add(a: &unique_error_count, v: 1, mo: memory_order_relaxed); |
| 32 | } |
| 33 | |
| 34 | static u32 GetTotalErrorCount() { |
| 35 | return atomic_load(a: &total_error_count, mo: memory_order_relaxed); |
| 36 | } |
| 37 | |
| 38 | static u32 GetUniqueErrorCount() { |
| 39 | return atomic_load(a: &unique_error_count, mo: memory_order_relaxed); |
| 40 | } |
| 41 | |
| 42 | void __rtsan::IncrementSuppressedCount() { |
| 43 | atomic_fetch_add(a: &suppressed_count, v: 1, mo: memory_order_relaxed); |
| 44 | } |
| 45 | |
| 46 | static u32 GetSuppressedCount() { |
| 47 | return atomic_load(a: &suppressed_count, mo: memory_order_relaxed); |
| 48 | } |
| 49 | |
| 50 | void __rtsan::PrintStatisticsSummary() { |
| 51 | ScopedErrorReportLock l; |
| 52 | Printf(format: "RealtimeSanitizer exit stats:\n" ); |
| 53 | Printf(format: " Total error count: %u\n" , GetTotalErrorCount()); |
| 54 | Printf(format: " Unique error count: %u\n" , GetUniqueErrorCount()); |
| 55 | |
| 56 | if (flags().ContainsSuppresionFile()) |
| 57 | Printf(format: " Suppression count: %u\n" , GetSuppressedCount()); |
| 58 | } |
| 59 | |