Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Details_Allocator.cpp
Go to the documentation of this file.
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 
13 namespace Teuchos {
14 namespace Details {
15 
16 void
18 logAllocation (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;
28  }
29 
30  if (verbose) {
31  // Identify this as a Teuchos allocation.
32  out << "Teuchos,alloc," << numEntries << "," << typeName << "," << numBytes << endl;
33  }
34 }
35 
36 void
38 logDeallocation (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 
60 
63 
64 void
66 {
67  curAllocInBytes_ = 0;
68  maxAllocInBytes_ = 0;
69 }
70 
73 
74 } // namespace Details
75 } // namespace Teuchos
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
static size_type maxAllocInBytes_
Max total allocation (&quot;high water mark&quot;) in bytes.
std::size_t size_type
Type of the size of an allocation or deallocation.
static void resetAllocationCounts()
Reset the current and max total allocation numbers to zero.
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 curAllocInBytes_
Current total allocation in bytes.
static size_type maxAllocInBytes()
Max total allocation (&quot;high water mark&quot;) in bytes.
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().
Declaration of Teuchos::Details::Allocator, a tracking and logging implementation of the C++ Standard...
static size_type curAllocInBytes()
Current total allocation in bytes.