Blame view
tools/sctk-2.4.10/src/asclite/test/asctools.cpp
2.64 KB
8dcb6dfcb first commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
/* * ASCLITE * Author: Jerome Ajot, Jon Fiscus, Nicolas Radde, Chris Laprun * * This software was developed at the National Institute of Standards and Technology by * employees of the Federal Government in the course of their official duties. Pursuant * to title 17 Section 105 of the United States Code this software is not subject to * copyright protection and is in the public domain. ASCLITE is an experimental system. * NIST assumes no responsibility whatsoever for its use by other parties, and makes no * guarantees, expressed or implied, about its quality, reliability, or any other * characteristic. We would appreciate acknowledgement if the software is used. * * THIS SOFTWARE IS PROVIDED "AS IS." With regard to this software, NIST MAKES NO EXPRESS * OR IMPLIED WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING MERCHANTABILITY, * OR FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef WIN32 //#include <windows.h> #endif #include "asctools.h" #ifdef __APPLE__ #include <mach/mach.h> #endif /** Get the current time in ms */ double timerStart() { timeval tv; gettimeofday(&tv, NULL); return((double)(tv.tv_sec*1000000+tv.tv_usec)/1000); } /** Return the difference between 2 times ms */ double timerEnd(double start) { timeval tv; gettimeofday(&tv, NULL); return(((double)(tv.tv_sec*1000000+tv.tv_usec)/1000) - start); } /** Print on the screen the memory usage */ int MemoryUsage() { #ifdef WIN32 //return (int) getMemoryUsed(); //MEMORY_BASIC_INFORMATION mbi; //DWORD dwMemUsed = 0; //PVOID pvAddress = 0; //memset(&mbi, 0, sizeof(MEMORY_BASIC_INFORMATION)); //while(VirtualQuery(pvAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == sizeof(MEMORY_BASIC_INFORMATION)) //{ // if(mbi.State == MEM_COMMIT && mbi.Type == MEM_PRIVATE) // dwMemUsed += mbi.RegionSize; // pvAddress = ((BYTE*)mbi.BaseAddress) + mbi.RegionSize; //} //return (int) dwMemUsed; return 0; #else #ifdef __APPLE__ kern_return_t err; mach_msg_type_number_t count; task_basic_info_data_t taskinfo; count = TASK_BASIC_INFO_COUNT; err = task_info( mach_task_self(), TASK_BASIC_INFO, (task_info_t)&taskinfo, &count ); if (err != KERN_SUCCESS) return 0; return (int) taskinfo.resident_size / 1024; #else //*NUX char buffer[256]; ifstream statusfile("/proc/self/status"); if (!statusfile.is_open()) { cout << "Error opening file" << endl; return 0; } while (!statusfile.eof()) { statusfile.getline(buffer,100); if((buffer[4] == 'z') && (buffer[0] == 'V') ) { char* pch; pch = strtok(buffer," "); pch = strtok(NULL, " "); return std::atoi(pch); } } return 0; #endif //__APPLE__ #endif //WIN32 } |