#include <MyProcessManager.hh>
Public Member Functions | |
MyProcessManager () | |
virtual | ~MyProcessManager () |
int | OpenFile () |
void | CloseFile () |
int | GetMemorySize () |
Static Public Member Functions | |
static MyProcessManager * | GetMyProcessManager () |
Private Attributes | |
int | MemoryConsumption |
std::ifstream * | fin_card |
std::stringstream | buff |
bool | fileOpened |
Static Private Attributes | |
static MyProcessManager * | fMyProcessManager = 0 |
Definition at line 7 of file MyProcessManager.hh.
MyProcessManager::MyProcessManager | ( | ) |
Definition at line 11 of file MyProcessManager.cc.
References fileOpened, fin_card, fMyProcessManager, and MemoryConsumption.
00012 { 00013 if (fMyProcessManager){ 00014 G4Exception("MyProcessManager::MyProcessManager()","Run0031", 00015 FatalException, "MyProcessManager constructed twice."); 00016 } 00017 fileOpened = false; 00018 fin_card = 0; 00019 MemoryConsumption = 0; 00020 }
MyProcessManager::~MyProcessManager | ( | ) | [virtual] |
Definition at line 22 of file MyProcessManager.cc.
References buff, and CloseFile().
void MyProcessManager::CloseFile | ( | ) |
Definition at line 53 of file MyProcessManager.cc.
References fileOpened, and fin_card.
Referenced by OpenFile(), and ~MyProcessManager().
00053 { 00054 if (fileOpened&&fin_card){ 00055 fin_card->close(); 00056 } 00057 fileOpened = false; 00058 fin_card = 0; 00059 }
int MyProcessManager::GetMemorySize | ( | ) |
Definition at line 61 of file MyProcessManager.cc.
References buff, fileOpened, fin_card, and OpenFile().
Referenced by MyAnalysisSvc::EndOfEventAction().
00061 { 00062 if (!fileOpened){ 00063 OpenFile(); 00064 } 00065 if (fin_card&&fileOpened){ 00066 std::string s_card; 00067 std::string temp; 00068 double size = -2; 00069 while(getline(*fin_card,s_card)){ 00070 buff.str(""); 00071 buff.clear(); 00072 buff<<s_card; 00073 buff>>temp; 00074 // std::cout<<"In MyProcessManager::GetMemorySize: Found Line \""<<s_card<<"\""<<std::endl; 00075 if (temp=="VmSize:"){ 00076 buff>>size>>temp; 00077 if (temp == "kB" || temp == "KB" || temp == "kb"){ 00078 size /= 1024; 00079 } 00080 else if (temp == "mB" || temp == "MB" || temp == "mb"){ 00081 } 00082 else if (temp == "gB" || temp == "GB" || temp == "gb"){ 00083 size *= 1024; 00084 } 00085 else if (temp == "Byte" || temp == "B" || temp == "b"){ 00086 size /= 1024*1024; 00087 } 00088 fin_card->clear(); 00089 fin_card->seekg(0,std::ios::beg); 00090 break; 00091 } 00092 } 00093 return size; 00094 } 00095 else{ 00096 return -1; 00097 } 00098 }
MyProcessManager * MyProcessManager::GetMyProcessManager | ( | ) | [static] |
Definition at line 28 of file MyProcessManager.cc.
References fMyProcessManager.
Referenced by MyAnalysisSvc::MyAnalysisSvc().
00028 { 00029 if ( !fMyProcessManager ){ 00030 fMyProcessManager = new MyProcessManager; 00031 } 00032 return fMyProcessManager; 00033 }
int MyProcessManager::OpenFile | ( | ) |
Definition at line 35 of file MyProcessManager.cc.
References buff, CloseFile(), fileOpened, and fin_card.
Referenced by GetMemorySize().
00035 { 00036 CloseFile(); 00037 pid_t id = getpid(); 00038 buff.str(""); 00039 buff.clear(); 00040 buff<<"/proc/"<<id<<"/status"; 00041 fin_card = new std::ifstream (buff.str().c_str()); 00042 std::cout<<"In MyProcessManager::OpenFile: Opened file \""<<buff.str()<<"\""<<std::endl; 00043 if ( !fin_card ){ 00044 fileOpened = false; 00045 return 1; 00046 } 00047 else{ 00048 fileOpened = true; 00049 return 0; 00050 } 00051 }
std::stringstream MyProcessManager::buff [private] |
Definition at line 23 of file MyProcessManager.hh.
Referenced by GetMemorySize(), OpenFile(), and ~MyProcessManager().
bool MyProcessManager::fileOpened [private] |
Definition at line 24 of file MyProcessManager.hh.
Referenced by CloseFile(), GetMemorySize(), MyProcessManager(), and OpenFile().
std::ifstream* MyProcessManager::fin_card [private] |
Definition at line 22 of file MyProcessManager.hh.
Referenced by CloseFile(), GetMemorySize(), MyProcessManager(), and OpenFile().
MyProcessManager * MyProcessManager::fMyProcessManager = 0 [static, private] |
Definition at line 20 of file MyProcessManager.hh.
Referenced by GetMyProcessManager(), and MyProcessManager().
int MyProcessManager::MemoryConsumption [private] |
Definition at line 21 of file MyProcessManager.hh.
Referenced by MyProcessManager().