Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Details_Allocator.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
11#include <sstream>
12
13namespace Teuchos {
14namespace Details {
15
16void
18logAllocation (std::ostream& out,
19 const size_type numEntries,
20 const size_type numBytes,
21 const char typeName[],
22 const bool verbose)
23{
24 using std::endl;
25 curAllocInBytes_ += numBytes;
26 if (curAllocInBytes_ > maxAllocInBytes_) {
27 maxAllocInBytes_ = curAllocInBytes_;
28 }
29
30 if (verbose) {
31 // Identify this as a Teuchos allocation.
32 out << "Teuchos,alloc," << numEntries << "," << typeName << "," << numBytes << endl;
33 }
34}
35
36void
38logDeallocation (std::ostream& out,
39 const size_type numEntries,
40 const size_type numBytes,
41 const char typeName[],
42 const bool verbose)
43{
44 using std::endl;
45 curAllocInBytes_ -= numBytes;
46
47 if (verbose) {
48 // First field identifies this as a Teuchos allocation. Use the
49 // same number of characters for "deall"(ocation) as
50 // "alloc"(ation) above, so that the columns line up nicely for
51 // human reading. Print deallocations as negative allocations.
52 // This makes it easy for a sed or awk script to compute totals.
53 out << "Teuchos,deall,-" << numEntries << "," << typeName
54 << ",-" << numBytes << endl;
55 }
56}
57
59AllocationLogger::curAllocInBytes () { return curAllocInBytes_; }
60
62AllocationLogger::maxAllocInBytes () { return maxAllocInBytes_; }
63
64void
66{
67 curAllocInBytes_ = 0;
68 maxAllocInBytes_ = 0;
69}
70
71AllocationLogger::size_type AllocationLogger::curAllocInBytes_ = 0;
72AllocationLogger::size_type AllocationLogger::maxAllocInBytes_ = 0;
73
74} // namespace Details
75} // namespace Teuchos
Declaration of Teuchos::Details::Allocator, a tracking and logging implementation of the C++ Standard...
static void resetAllocationCounts()
Reset the current and max total allocation numbers to zero.
static size_type curAllocInBytes()
Current total allocation in bytes.
static void logAllocation(std::ostream &out, const size_type numEntries, const size_type numBytes, const char typeName[], const bool verbose)
Log an allocation.
static size_type maxAllocInBytes()
Max total allocation ("high water mark") in bytes.
std::size_t size_type
Type of the size of an allocation or deallocation.
static void logDeallocation(std::ostream &out, const size_type numEntries, const size_type numBytes, const char typeName[], const bool verbose)
Log a deallocation, that was previously logged using logAllocation().
Smart reference counting pointer class for automatic garbage collection.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Namespace of implementation details.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...