oomph::MemoryUsage Namespace Reference

Functions

void empty_my_memory_usage_file ()
 
void empty_total_memory_usage_file ()
 
void doc_total_memory_usage (const std::string &prefix_string)
 
void empty_memory_usage_files ()
 
void doc_memory_usage (const std::string &prefix_string)
 
void empty_top_file ()
 
void run_continous_top (const std::string &comment)
 
void stop_continous_top (const std::string &comment)
 
void insert_comment_to_continous_top (const std::string &comment)
 Insert comment into running continuous top output. More...
 

Variables

bool Suppress_mpi_synchronisation = true
 
std::string My_memory_usage_system_string = "ps aux"
 
bool Bypass_all_memory_usage_monitoring = false
 
std::string My_memory_usage_filename = "my_memory_usage.dat"
 
std::string Total_memory_usage_system_string
 
std::string Total_memory_usage_filename = "memory_usage.dat"
 
std::string Top_system_string = "while true; do top -b -n 2 ; done "
 
std::string Top_output_filename = "top_output.dat"
 

Detailed Description

///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// Namespace with helper functions to assess total memory usage on the fly using system() – details are very machine specific! This just provides the overall machinery with default settings for our own (linux machines). Uses the system command to spawn a command that computes the total memory usage on the machine where this is called. [Disclaimer: works on my machine(s) – no guarantees for any other platform; linux or not. MH]

///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// Namespace with helper functions to assess total memory usage on the fly using system() – details are very machine specific! This just provides the overall machinery with default settings for our own (linux machines). Uses the system command to spawn a command that computes the total memory usage on the machine where this is called. [Disclaimer: works on my machine(s) – no guarantees for any other platform; Linux or not. MH]

Function Documentation

◆ doc_memory_usage()

void oomph::MemoryUsage::doc_memory_usage ( const std::string &  prefix_string)

Doc total and local memory usage, prepended by string (which allows identification from where the function is called, say). NOTE: Local memory usage only works if we have unistd.h header

Doc total and local memory usage, prepended by string (which allows identification from where the function is called, say)

1536  {
1537  // bail out straight away?
1539 
1540 #ifdef OOMPH_HAS_UNISTDH
1541  doc_my_memory_usage(prefix_string);
1542 #endif
1543 
1544  doc_total_memory_usage(prefix_string);
1545  }
bool Bypass_all_memory_usage_monitoring
Definition: oomph_utilities.cc:1390
void doc_total_memory_usage(const std::string &prefix_string)
Definition: oomph_utilities.cc:1489

References Bypass_all_memory_usage_monitoring, and doc_total_memory_usage().

◆ doc_total_memory_usage()

void oomph::MemoryUsage::doc_total_memory_usage ( const std::string &  prefix_string)

Doc total memory usage, prepended by string (which allows identification from where the function is called, say) that records memory usage in file whose name is specified by Total_memory_usage_filename. Data is appended to that file; wipe it with empty_memory_usage_file().

Doc total memory usage, prepended by string (which allows identification from where the function is called, say) that records mem usage in file whose name is specified by Total_memory_usage_filename. Data is appended to that file; wipe it with empty_memory_usage_file().

1490  {
1491  // bail out straight away?
1493 
1494  // Write prefix
1495  std::ofstream the_file;
1496  the_file.open(Total_memory_usage_filename.c_str(), std::ios::app);
1497  the_file << prefix_string << " ";
1498  the_file.close();
1499 
1500  // Sync all processors if in parallel
1501 #ifdef OOMPH_HAS_MPI
1502  if ((MPI_Helpers::mpi_has_been_initialised()) &&
1504  {
1505  MPI_Barrier(MPI_Helpers::communicator_pt()->mpi_comm());
1506  }
1507 #endif
1508 
1509  // Process memory usage command and write to file
1510  std::stringstream tmp;
1513  int success = system(tmp.str().c_str());
1514 
1515  // Dummy command to shut up compiler warnings
1516  success += 1;
1517  }
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
bool Suppress_mpi_synchronisation
Definition: oomph_utilities.cc:1378
std::string Total_memory_usage_system_string
Definition: oomph_utilities.cc:1459
std::string Total_memory_usage_filename
Definition: oomph_utilities.cc:1468

References Bypass_all_memory_usage_monitoring, oomph::MPI_Helpers::communicator_pt(), oomph::MPI_Helpers::mpi_has_been_initialised(), Suppress_mpi_synchronisation, tmp, Total_memory_usage_filename, and Total_memory_usage_system_string.

Referenced by doc_memory_usage().

◆ empty_memory_usage_files()

void oomph::MemoryUsage::empty_memory_usage_files ( )

Function to empty file that records total and local memory usage in appropriate files

1523  {
1524  // bail out straight away?
1526 
1529  empty_top_file();
1530  }
void empty_top_file()
Definition: oomph_utilities.cc:1564
void empty_total_memory_usage_file()
Definition: oomph_utilities.cc:1472
void empty_my_memory_usage_file()
Definition: oomph_utilities.cc:1402

References Bypass_all_memory_usage_monitoring, empty_my_memory_usage_file(), empty_top_file(), and empty_total_memory_usage_file().

◆ empty_my_memory_usage_file()

void oomph::MemoryUsage::empty_my_memory_usage_file ( )

Function to empty file that records my memory usage in file whose name is specified by My_memory_usage_filename.

1403  {
1404  // bail out straight away?
1406 
1407  // Open without appending and write header
1408  std::ofstream the_file;
1409  the_file.open(My_memory_usage_filename.c_str());
1410  the_file << "# My memory usage: \n";
1411  the_file.close();
1412  }
std::string My_memory_usage_filename
Definition: oomph_utilities.cc:1398

References Bypass_all_memory_usage_monitoring, and My_memory_usage_filename.

Referenced by empty_memory_usage_files().

◆ empty_top_file()

void oomph::MemoryUsage::empty_top_file ( )

Function to empty file that records continuous output from top in file whose name is specified by Top_output_filename

1565  {
1566  // bail out straight away?
1568 
1569  // Open without appending and write header
1570  std::ofstream the_file;
1571  the_file.open(Top_output_filename.c_str());
1572  the_file << "# Continuous output from top obtained with: \n";
1573  the_file << "# " << Top_system_string << "\n";
1574  the_file.close();
1575  }
std::string Top_output_filename
Definition: oomph_utilities.cc:1560
std::string Top_system_string
Definition: oomph_utilities.cc:1552

References Bypass_all_memory_usage_monitoring, Top_output_filename, and Top_system_string.

Referenced by empty_memory_usage_files().

◆ empty_total_memory_usage_file()

void oomph::MemoryUsage::empty_total_memory_usage_file ( )

Function to empty file that records total memory usage in file whose name is specified by Total_memory_usage_filename.

1473  {
1474  // bail out straight away?
1476 
1477  // Open without appending and write header
1478  std::ofstream the_file;
1479  the_file.open(Total_memory_usage_filename.c_str());
1480  the_file << "# Total memory usage: \n";
1481  the_file.close();
1482  }

References Bypass_all_memory_usage_monitoring, and Total_memory_usage_filename.

Referenced by empty_memory_usage_files().

◆ insert_comment_to_continous_top()

void oomph::MemoryUsage::insert_comment_to_continous_top ( const std::string &  comment)

Insert comment into running continuous top output.

1681  {
1682  // bail out straight away?
1684 
1685  std::stringstream tmp;
1686  tmp << " echo \"OOMPH-LIB EVENT: " << comment << "\" >> "
1688  int success = system(tmp.str().c_str());
1689 
1690  // Dummy command to shut up compiler warnings
1691  success += 1;
1692  }

References Bypass_all_memory_usage_monitoring, tmp, and Top_output_filename.

Referenced by run_continous_top(), and stop_continous_top().

◆ run_continous_top()

void oomph::MemoryUsage::run_continous_top ( const std::string &  comment)

Start running top continuously and output (append) into file specified by Top_output_filename. Wipe that file with empty_top_file() if you wish. Note that this is again quite Linux specific and unlikely to work on other operating systems. Insert optional comment into output file before starting.

Start running top continuously and output (append) into file specified by Top_output_filename. Wipe that file with empty_top_file() first if you wish. Note that this is again quite Linux specific and unlikely to work on other operating systems. Insert optional comment into output file before starting.

1584  {
1585  // bail out straight away?
1587 
1588  // Sync all processors if in parallel
1589  std::string modifier = "";
1590 
1591 #ifdef OOMPH_HAS_MPI
1592  if (MPI_Helpers::mpi_has_been_initialised())
1593  {
1595  {
1596  MPI_Barrier(MPI_Helpers::communicator_pt()->mpi_comm());
1597  }
1598  std::stringstream tmp;
1599  tmp << "_proc" << MPI_Helpers::communicator_pt()->my_rank();
1600  modifier = tmp.str();
1601  }
1602 #endif
1603 
1604  // Process memory usage command and write to file
1605  std::stringstream tmp;
1606 
1607  // String stream seems unhappy about direct insertions of these
1608  std::string backslash = "\\";
1609  std::string dollar = "$";
1610 
1611  // Create files that spawn and kill continuous top
1612  tmp << "echo \"#/bin/bash\" > run_continuous_top" << modifier << ".bash; "
1613  << "echo \" echo " << backslash << "\" kill " << backslash << dollar
1614  << backslash << dollar << " " << backslash
1615  << "\" > kill_continuous_top" << modifier
1616  << ".bash; chmod a+x kill_continuous_top" << modifier << ".bash; "
1617  << Top_system_string << " \" >> run_continuous_top" << modifier
1618  << ".bash; chmod a+x run_continuous_top" << modifier << ".bash ";
1619  int success = system(tmp.str().c_str());
1620 
1621  // Add comment to annotate?
1622  if (comment != "")
1623  {
1625  }
1626 
1627  // Start spawning
1628  std::stringstream tmp2;
1629  tmp2 << "./run_continuous_top" << modifier << ".bash >> "
1630  << Top_output_filename << " & ";
1631  success = system(tmp2.str().c_str());
1632 
1633  // Dummy command to shut up compiler warnings
1634  success += 1;
1635  }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
void insert_comment_to_continous_top(const std::string &comment)
Insert comment into running continuous top output.
Definition: oomph_utilities.cc:1680

References Bypass_all_memory_usage_monitoring, oomph::MPI_Helpers::communicator_pt(), insert_comment_to_continous_top(), oomph::MPI_Helpers::mpi_has_been_initialised(), oomph::OomphCommunicator::my_rank(), oomph::Global_string_for_annotation::string(), Suppress_mpi_synchronisation, tmp, Top_output_filename, and Top_system_string.

◆ stop_continous_top()

void oomph::MemoryUsage::stop_continous_top ( const std::string &  comment)

Stop running top continuously. Note that this is again quite Linux specific and unlikely to work on other operating systems. Insert optional comment into output file before stopping.

1642  {
1643  // bail out straight away?
1645 
1646  // Sync all processors if in parallel
1647  std::string modifier = "";
1648 
1649 #ifdef OOMPH_HAS_MPI
1650  if (MPI_Helpers::mpi_has_been_initialised())
1651  {
1653  {
1654  MPI_Barrier(MPI_Helpers::communicator_pt()->mpi_comm());
1655  }
1656  std::stringstream tmp;
1657  tmp << "_proc" << MPI_Helpers::communicator_pt()->my_rank();
1658  modifier = tmp.str();
1659  }
1660 #endif
1661 
1662  // Add comment to annotate?
1663  if (comment != "")
1664  {
1666  }
1667 
1668  // Kill
1669  std::stringstream tmp2;
1670  tmp2 << "./kill_continuous_top" << modifier << ".bash >> "
1671  << Top_output_filename << " & ";
1672  int success = system(tmp2.str().c_str());
1673 
1674  // Dummy command to shut up compiler warnings
1675  success += 1;
1676  }

References Bypass_all_memory_usage_monitoring, oomph::MPI_Helpers::communicator_pt(), insert_comment_to_continous_top(), oomph::MPI_Helpers::mpi_has_been_initialised(), oomph::OomphCommunicator::my_rank(), oomph::Global_string_for_annotation::string(), Suppress_mpi_synchronisation, tmp, and Top_output_filename.

Variable Documentation

◆ Bypass_all_memory_usage_monitoring

bool oomph::MemoryUsage::Bypass_all_memory_usage_monitoring = false

Bool allowing quick bypassing of ALL operations related to memory usage monitoring – this allows the code to remain "instrumented" without incurring the heavy penalties associated with the system calls and i/o. Default setting: false.

Referenced by doc_memory_usage(), doc_total_memory_usage(), empty_memory_usage_files(), empty_my_memory_usage_file(), empty_top_file(), empty_total_memory_usage_file(), insert_comment_to_continous_top(), main(), run_continous_top(), and stop_continous_top().

◆ My_memory_usage_filename

std::string oomph::MemoryUsage::My_memory_usage_filename = "my_memory_usage.dat"

String containing name of file in which we document my memory usage – you may want to change this to allow different processors to write to separate files (especially in mpi context). Note that file is appended to so it ought to be emptied (either manually or by calling helper function empty_memory_usage_file()

Referenced by empty_my_memory_usage_file().

◆ My_memory_usage_system_string

std::string oomph::MemoryUsage::My_memory_usage_system_string = "ps aux"

String containing system command that obtains memory usage of all processes. Default assignment for linux. [Disclaimer: works on my machine(s) – no guarantees for any other platform; linux or not. MH]

String containing system command that obtains memory usage of all processes. Default assignment for Linux. [Disclaimer: works on my machine(s) – no guarantees for any other platform; Linux or not. MH]

◆ Suppress_mpi_synchronisation

bool oomph::MemoryUsage::Suppress_mpi_synchronisation = true

Boolean to suppress synchronisation of doc memory usage on processors (via mpi barriers). True (i.e. sync is suppressed) by default because not all processors may reach the relevant doc memory usage statements causing the code to hang).

Boolean to suppress synchronisation of doc memory usage on processors (via mpi barriers). True (i.e. sync is is suppressed by default because not all processors may execute the reach the relevant doc memory usage statements causing the code to hang).

Referenced by doc_total_memory_usage(), run_continous_top(), and stop_continous_top().

◆ Top_output_filename

std::string oomph::MemoryUsage::Top_output_filename = "top_output.dat"

String containing name of file in which we document "continuous" output from "top" (or equivalent)– you may want to change this to allow different processors to write to separate files (especially in mpi context). Note that file is appended to so it ought to be emptied (either manually or by calling helper function empty_top_file()

Referenced by empty_top_file(), insert_comment_to_continous_top(), run_continous_top(), and stop_continous_top().

◆ Top_system_string

std::string oomph::MemoryUsage::Top_system_string = "while true; do top -b -n 2 ; done "

String containing system command that runs "top" (or equivalent) "indefinitely" and writes to file specified in Top_output_filename. Default assignment for linux. [Disclaimer: works on my machine(s) – no guarantees for any other platform; linux or not. MH]

String containing system command that runs "top" (or equivalent) "indefinitely" and writes to file specified in Top_output_filename. Default assignment for Linux. [Disclaimer: works on my machine(s) – no guarantees for any other platform; Linux or not. MH]

Referenced by empty_top_file(), and run_continous_top().

◆ Total_memory_usage_filename

std::string oomph::MemoryUsage::Total_memory_usage_filename = "memory_usage.dat"

String containing name of file in which we document total memory usage – you may want to change this to allow different processors to write to separate files (especially in mpi context). Note that file is appended to so it ought to be emptied (either manually or by calling helper function empty_memory_usage_file()

Referenced by doc_total_memory_usage(), and empty_total_memory_usage_file().

◆ Total_memory_usage_system_string

std::string oomph::MemoryUsage::Total_memory_usage_system_string
Initial value:
=
"ps aux | awk 'BEGIN{sum=0}{sum+=$4}END{print sum}'"

String containing system command that obtains total memory usage. Default assignment for linux. [Disclaimer: works on my machine(s) – no guarantees for any other platform; linux or not. MH]

String containing system command that obtains total memory usage. Default assignment for Linux. [Disclaimer: works on my machine(s) – no guarantees for any other platform; Linux or not. MH]

Referenced by doc_total_memory_usage().