Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:45

0001 #include <array>
0002 #include <iostream>
0003 #include <memory>
0004 
0005 #include "HLTrigger/Timer/interface/memory_usage.h"
0006 
0007 void print_thread_header() {
0008   std::cout << "+allocated / -deallocated / < peak memory for the current thread:" << std::endl;
0009 }
0010 
0011 void print_thread_stat() {
0012   std::cout << "\t+" << (memory_usage::allocated() / 1024) << " kB / "  // allocated memory, in kB
0013             << "-" << (memory_usage::deallocated() / 1024) << " kB / "  // deallocated memory, in kB
0014             << "< " << (memory_usage::peak() / 1024) << " kB"           // peak used memory, in kB
0015             << std::endl;
0016 }
0017 
0018 int main(void) {
0019   constexpr int size = 10;
0020   std::array<std::unique_ptr<std::byte[]>, size> buffers;
0021 
0022   print_thread_header();
0023   print_thread_stat();
0024 
0025   for (auto& buffer : buffers) {
0026     buffer = std::make_unique<std::byte[]>(16 * 1024);
0027     print_thread_stat();
0028   }
0029 
0030   for (auto& buffer : buffers) {
0031     buffer.reset();
0032     print_thread_stat();
0033   }
0034 
0035   std::cout << std::endl;
0036   memory_usage::reset_peak();
0037   print_thread_header();
0038   print_thread_stat();
0039 
0040   for (auto& buffer : buffers) {
0041     buffer = std::make_unique<std::byte[]>(16 * 1024);
0042     print_thread_stat();
0043     buffer.reset();
0044     print_thread_stat();
0045   }
0046 
0047   return 0;
0048 }