1*e8d8bef9SDimitry Andric //===-- memprof_stats.h ----------------------------------------*- C++ -*-===//
2*e8d8bef9SDimitry Andric //
3*e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e8d8bef9SDimitry Andric //
7*e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8*e8d8bef9SDimitry Andric //
9*e8d8bef9SDimitry Andric // This file is a part of MemProfiler, a memory profiler.
10*e8d8bef9SDimitry Andric //
11*e8d8bef9SDimitry Andric // MemProf-private header for statistics.
12*e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
13*e8d8bef9SDimitry Andric #ifndef MEMPROF_STATS_H
14*e8d8bef9SDimitry Andric #define MEMPROF_STATS_H
15*e8d8bef9SDimitry Andric 
16*e8d8bef9SDimitry Andric #include "memprof_allocator.h"
17*e8d8bef9SDimitry Andric #include "memprof_internal.h"
18*e8d8bef9SDimitry Andric 
19*e8d8bef9SDimitry Andric namespace __memprof {
20*e8d8bef9SDimitry Andric 
21*e8d8bef9SDimitry Andric // MemprofStats struct is NOT thread-safe.
22*e8d8bef9SDimitry Andric // Each MemprofThread has its own MemprofStats, which are sometimes flushed
23*e8d8bef9SDimitry Andric // to the accumulated MemprofStats.
24*e8d8bef9SDimitry Andric struct MemprofStats {
25*e8d8bef9SDimitry Andric   // MemprofStats must be a struct consisting of uptr fields only.
26*e8d8bef9SDimitry Andric   // When merging two MemprofStats structs, we treat them as arrays of uptr.
27*e8d8bef9SDimitry Andric   uptr mallocs;
28*e8d8bef9SDimitry Andric   uptr malloced;
29*e8d8bef9SDimitry Andric   uptr malloced_overhead;
30*e8d8bef9SDimitry Andric   uptr frees;
31*e8d8bef9SDimitry Andric   uptr freed;
32*e8d8bef9SDimitry Andric   uptr real_frees;
33*e8d8bef9SDimitry Andric   uptr really_freed;
34*e8d8bef9SDimitry Andric   uptr reallocs;
35*e8d8bef9SDimitry Andric   uptr realloced;
36*e8d8bef9SDimitry Andric   uptr mmaps;
37*e8d8bef9SDimitry Andric   uptr mmaped;
38*e8d8bef9SDimitry Andric   uptr munmaps;
39*e8d8bef9SDimitry Andric   uptr munmaped;
40*e8d8bef9SDimitry Andric   uptr malloc_large;
41*e8d8bef9SDimitry Andric   uptr malloced_by_size[kNumberOfSizeClasses];
42*e8d8bef9SDimitry Andric 
43*e8d8bef9SDimitry Andric   // Ctor for global MemprofStats (accumulated stats for dead threads).
MemprofStatsMemprofStats44*e8d8bef9SDimitry Andric   explicit MemprofStats(LinkerInitialized) {}
45*e8d8bef9SDimitry Andric   // Creates empty stats.
46*e8d8bef9SDimitry Andric   MemprofStats();
47*e8d8bef9SDimitry Andric 
48*e8d8bef9SDimitry Andric   void Print(); // Prints formatted stats to stderr.
49*e8d8bef9SDimitry Andric   void Clear();
50*e8d8bef9SDimitry Andric   void MergeFrom(const MemprofStats *stats);
51*e8d8bef9SDimitry Andric };
52*e8d8bef9SDimitry Andric 
53*e8d8bef9SDimitry Andric // Returns stats for GetCurrentThread(), or stats for fake "unknown thread"
54*e8d8bef9SDimitry Andric // if GetCurrentThread() returns 0.
55*e8d8bef9SDimitry Andric MemprofStats &GetCurrentThreadStats();
56*e8d8bef9SDimitry Andric // Flushes a given stats into accumulated stats of dead threads.
57*e8d8bef9SDimitry Andric void FlushToDeadThreadStats(MemprofStats *stats);
58*e8d8bef9SDimitry Andric 
59*e8d8bef9SDimitry Andric } // namespace __memprof
60*e8d8bef9SDimitry Andric 
61*e8d8bef9SDimitry Andric #endif // MEMPROF_STATS_H
62