Back to index

nordugrid-arc-nox  1.1.0~rc6
test_sysinfo.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <list>
00004 #include <vector>
00005 #include <arc/StringConv.h>
00006 #include "sysinfo.h"
00007 
00008 int main(int argc, char **argv)
00009 {
00010 #if 0
00011     Paul::SysInfo si;
00012 
00013     std::cout << "OSName: " << si.getOSName() << std::endl;
00014     std::cout << "OSFamily: " << si.getOSFamily() << std::endl;
00015     std::cout << "OSVersion: " << si.getOSVersion() << std::endl;
00016     std::cout << "Platform: " << si.getPlatform() << std::endl;
00017     std::cout << "Pys CPU: " << si.getPhysicalCPUs() << std::endl;
00018     std::cout << "Log CPU: " << si.getLogicalCPUs() << std::endl;
00019     std::cout << "Main Memory (MB): " << si.getMainMemorySize() << std::endl;
00020     std::cout << "Virtual Memory (MB): " << si.getVirtualMemorySize() << std::endl;
00021     std::cout << "Available Disk space (MB): " << si.diskAvailable(".") << std::endl;
00022     std::cout << "Total Disk space (MB): " << si.diskTotal(".") << std::endl;
00023     std::cout << "Free Disk space (MB): " << si.diskFree(".") << std::endl;
00024 #endif
00025     
00026     std::ifstream fin(argv[1]);
00027     int line_n = 20;
00028     int ln = 0;
00029     int seek_size = 1024;
00030     std::list<std::string> lines;
00031     fin.seekg(0, std::ios::end);
00032     int block_end = fin.tellg(); 
00033     fin.seekg(-seek_size, std::ios::end);
00034     int pos = fin.tellg();
00035     int block_start = pos;
00036     std::cout << "bs: " << block_start << std::endl;
00037     std::cout << "p: " << pos << std::endl;
00038     std::cout << "be: " << block_end << std::endl;
00039     std::vector<std::string> tokens;
00040     char buffer[1024];
00041     for(;;) { 
00042         memset(buffer, 0, sizeof(buffer));
00043         fin.read(buffer, sizeof(buffer));
00044         buffer[sizeof(buffer)-1] = '\0';
00045         std::string l = buffer;
00046         tokens.clear();
00047         Arc::tokenize(l, tokens, "\n");
00048         for (int i = tokens.size() -1 ; i >= 0; i--) {
00049 std::cout << "**" << tokens[i] << "(" << i << "/" << tokens.size() << ")" << std::endl;
00050             lines.push_back(tokens[i]);
00051             ln++;
00052         }
00053         if (ln >= line_n) {
00054             break;
00055         }
00056         pos = fin.tellg();
00057 std::cout << pos << std::endl;
00058         if ((fin.eof() && ln < line_n) || pos >= block_end) {
00059             if (block_start == 0) {
00060                 break;
00061             }
00062             block_end = block_start;
00063             int s = block_start - seek_size;
00064             if (s < 0) {
00065                 s = 0;
00066             }
00067             fin.seekg(s, std::ios::beg);
00068             block_start = fin.tellg();
00069         }
00070     std::cout << "bs: " << block_start << std::endl;
00071     std::cout << "p: " << pos << std::endl;
00072     std::cout << "be: " << block_end << std::endl;
00073     }
00074 std::cout << "------" << std::endl;
00075     std::list<std::string>::iterator it;
00076     for (it = lines.begin(); it != lines.end(); it++) {
00077         std::cout << *it << std::endl;
00078     }
00079     return 0;
00080 }