CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
//===-- stats.h -------------------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SCUDO_STATS_H_
|
|
#define SCUDO_STATS_H_
|
|
|
|
#include "atomic_helpers.h"
|
|
#include "list.h"
|
|
#include "mutex.h"
|
|
#include "thread_annotations.h"
|
|
|
|
#include <string.h>
|
|
|
|
namespace scudo {
|
|
|
|
// Memory allocator statistics
|
|
enum StatType { StatAllocated, StatFree, StatMapped, StatCount };
|
|
|
|
typedef uptr StatCounters[StatCount];
|
|
|
|
// Per-thread stats, live in per-thread cache. We use atomics so that the
|
|
// numbers themselves are consistent. But we don't use atomic_{add|sub} or a
|
|
// lock, because those are expensive operations , and we only care for the stats
|
|
// to be "somewhat" correct: eg. if we call GlobalStats::get while a thread is
|
|
// LocalStats::add'ing, this is OK, we will still get a meaningful number.
|
|
class LocalStats {
|
|
public:
|
|
void init() {
|
|
for (uptr I = 0; I < StatCount; I++)
|
|
DCHECK_EQ(get(static_cast<StatType>(I)), 0U);
|
|
}
|
|
|
|
void add(StatType I, uptr V) {
|
|
V += atomic_load_relaxed(&StatsArray[I]);
|
|
atomic_store_relaxed(&StatsArray[I], V);
|
|
}
|
|
|
|
void sub(StatType I, uptr V) {
|
|
V = atomic_load_relaxed(&StatsArray[I]) - V;
|
|
atomic_store_relaxed(&StatsArray[I], V);
|
|
}
|
|
|
|
void set(StatType I, uptr V) { atomic_store_relaxed(&StatsArray[I], V); }
|
|
|
|
uptr get(StatType I) const { return atomic_load_relaxed(&StatsArray[I]); }
|
|
|
|
LocalStats *Next = nullptr;
|
|
LocalStats *Prev = nullptr;
|
|
|
|
private:
|
|
atomic_uptr StatsArray[StatCount] = {};
|
|
};
|
|
|
|
// Global stats, used for aggregation and querying.
|
|
class GlobalStats : public LocalStats {
|
|
public:
|
|
void init() { LocalStats::init(); }
|
|
|
|
void link(LocalStats *S) EXCLUDES(Mutex) {
|
|
ScopedLock L(Mutex);
|
|
StatsList.push_back(S);
|
|
}
|
|
|
|
void unlink(LocalStats *S) EXCLUDES(Mutex) {
|
|
ScopedLock L(Mutex);
|
|
StatsList.remove(S);
|
|
for (uptr I = 0; I < StatCount; I++)
|
|
add(static_cast<StatType>(I), S->get(static_cast<StatType>(I)));
|
|
}
|
|
|
|
void get(uptr *S) const EXCLUDES(Mutex) {
|
|
ScopedLock L(Mutex);
|
|
for (uptr I = 0; I < StatCount; I++)
|
|
S[I] = LocalStats::get(static_cast<StatType>(I));
|
|
for (const auto &Stats : StatsList) {
|
|
for (uptr I = 0; I < StatCount; I++)
|
|
S[I] += Stats.get(static_cast<StatType>(I));
|
|
}
|
|
// All stats must be non-negative.
|
|
for (uptr I = 0; I < StatCount; I++)
|
|
S[I] = static_cast<sptr>(S[I]) >= 0 ? S[I] : 0;
|
|
}
|
|
|
|
void lock() ACQUIRE(Mutex) { Mutex.lock(); }
|
|
void unlock() RELEASE(Mutex) { Mutex.unlock(); }
|
|
|
|
void disable() ACQUIRE(Mutex) { lock(); }
|
|
void enable() RELEASE(Mutex) { unlock(); }
|
|
|
|
private:
|
|
mutable HybridMutex Mutex;
|
|
DoublyLinkedList<LocalStats> StatsList GUARDED_BY(Mutex);
|
|
};
|
|
|
|
} // namespace scudo
|
|
|
|
#endif // SCUDO_STATS_H_
|