diff --git a/BaseLib/MemWatch.cpp b/BaseLib/MemWatch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d2e6e294fc966f0e16e514281ad7f23099e641e --- /dev/null +++ b/BaseLib/MemWatch.cpp @@ -0,0 +1,69 @@ +/* + * MemWatch.cpp + * + * Created on: May 7, 2012 + * Author: TF + */ + +#include "MemWatch.h" + +#ifndef WIN32 + +namespace BaseLib { + +MemWatch::MemWatch () +{ + updateMemUsage (); +} + +unsigned MemWatch::updateMemUsage () +{ + std::string fname ("/proc/"); + std::stringstream str_pid; + str_pid << (unsigned) getpid(); + fname += str_pid.str(); + fname += "/statm"; + unsigned pages; + + std::ifstream in (fname.c_str(), std::ios::in); + if (in == NULL) { + perror( "open" ); + return 1; + } + + in >> pages; + _vmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + in >> pages; + _rmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + in >> pages; + _smem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + in >> pages; + _cmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + in.close (); + return 0; +} + +unsigned long MemWatch::getVirtMemUsage () +{ + updateMemUsage (); + return _vmem_size; +} + +unsigned long MemWatch::getResMemUsage () { + updateMemUsage (); + return _rmem_size; +} + +unsigned long MemWatch::getShrMemUsage () { + updateMemUsage (); + return _smem_size; +} + +unsigned long MemWatch::getCodeMemUsage () { + updateMemUsage (); + return _cmem_size; +} + +} // end namespace BaseLib + +#endif // WIN diff --git a/BaseLib/MemWatch.h b/BaseLib/MemWatch.h new file mode 100644 index 0000000000000000000000000000000000000000..2afa771ba80aeb18f1d90af4fd6bbaed78715286 --- /dev/null +++ b/BaseLib/MemWatch.h @@ -0,0 +1,42 @@ +/* + * MemWatch.h + * + * Created on: May 7, 2012 + * Author: TF + */ + +#ifndef MEMWATCH_H_ +#define MEMWATCH_H_ + +#ifndef WIN32 + +#include <sys/types.h> +#include <unistd.h> +#include <iostream> +#include <fstream> +#include <string> +#include <sstream> + +namespace BaseLib { + +class MemWatch { +public: + MemWatch (); + unsigned long getVirtMemUsage (); + unsigned long getResMemUsage (); + unsigned long getShrMemUsage (); + unsigned long getCodeMemUsage (); + +private: + unsigned updateMemUsage (); + unsigned long _vmem_size; + unsigned long _rmem_size; + unsigned long _smem_size; + unsigned long _cmem_size; +}; + +} + +#endif // not Windows + +#endif /* MEMWATCH_H_ */ diff --git a/SimpleTests/MeshTests/CMakeLists.txt b/SimpleTests/MeshTests/CMakeLists.txt index 2a224164947132cbb5a297daec8593a9e6dcb03b..a094ce6623451ef8f47777733d7217389089bc68 100644 --- a/SimpleTests/MeshTests/CMakeLists.txt +++ b/SimpleTests/MeshTests/CMakeLists.txt @@ -4,6 +4,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/BaseLib/ ${CMAKE_SOURCE_DIR}/BaseLib/logog/include ${CMAKE_SOURCE_DIR}/FileIO/ + ${CMAKE_SOURCE_DIR}/GeoLib/ ${CMAKE_SOURCE_DIR}/MathLib/ ${CMAKE_SOURCE_DIR}/MeshLib/ ) diff --git a/SimpleTests/MeshTests/MeshRead.cpp b/SimpleTests/MeshTests/MeshRead.cpp index 6cfd71c00d0abf4b61218612390320feecabb7ac..7729ef64498925284e1f79a8c75aa8f65d74aff1 100644 --- a/SimpleTests/MeshTests/MeshRead.cpp +++ b/SimpleTests/MeshTests/MeshRead.cpp @@ -5,15 +5,40 @@ * Author: KR */ +// BaseLib +#include "MemWatch.h" +#include "RunTime.h" + +// MeshLib +#include "Node.h" +#include "Elements/Element.h" #include "Mesh.h" #include "MeshIO.h" int main(int argc, char *argv[]) { - std::string file_name("c:/Project/Data/Ammer/Ammer-Homogen100m-Final.msh"); + std::string file_name("/mnt/visdata/tom/data/TestMeshes/Mesh-dx1.00-Layered20.msh"); + + std::cout << "sizeof(double): " << sizeof (double) << std::endl; + std::cout << "sizeof(GeoLib::Point): " << sizeof (GEOLIB::Point) << std::endl; + std::cout << "sizeof(GeoLib::PointWithID): " << sizeof (GEOLIB::PointWithID) << std::endl; + std::cout << "sizeof(Node): " << sizeof (MeshLib::Node) << std::endl; + std::cout << "sizeof(Element): " << sizeof (MeshLib::Element) << std::endl; + FileIO::MeshIO mesh_io; +#ifndef WIN32 + BaseLib::MemWatch mem_watch; + unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + BaseLib::RunTime run_time; + run_time.start(); +#endif MeshLib::Mesh* mesh = mesh_io.loadMeshFromFile(file_name); - +#ifndef WIN32 + unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); + std::cout << "mem for mesh: " << (mem_with_mesh - mem_without_mesh)/(1024*1024) << " MB" << std::endl; + run_time.stop(); + std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl; +#endif delete mesh; }