00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "XrdMon/XrdMonHeader.hh"
00014 #include "XrdMon/XrdMonException.hh"
00015 #include "XrdMon/XrdMonDecArgParser.hh"
00016 #include <fstream>
00017 #include <iomanip>
00018 #include "XrdSys/XrdSysHeaders.hh"
00019 #include <sstream>
00020 using std::cout;
00021 using std::endl;
00022 using std::fstream;
00023 using std::ios;
00024 using std::setfill;
00025 using std::setw;
00026 using std::stringstream;
00027
00028 void
00029 dumpOnePacket(kXR_int64 uniqueId, fstream& _file)
00030 {
00031
00032 stringstream ss(stringstream::out);
00033 ss << "/tmp/ap.dump." << setw(6) << setfill('0') << uniqueId;
00034 string filePath = ss.str();
00035 fstream ofs(filePath.c_str(), ios::out|ios::binary);
00036
00037
00038 char hBuffer[HDRLEN];
00039 _file.read(hBuffer, HDRLEN);
00040 ofs.write(hBuffer, HDRLEN);
00041
00042
00043 XrdMonHeader header;
00044 header.decode(hBuffer);
00045 cout << "Dumping packet " << uniqueId << " to " << filePath.c_str() << ", "
00046 << "inputfile tellg: " << setw(10) << (kXR_int64) _file.tellg()-HDRLEN
00047 << ", header: " << header << endl;
00048
00049
00050 char packet[MAXPACKETSIZE];
00051 _file.read(packet, header.packetLen()-HDRLEN);
00052 ofs.write(packet, header.packetLen()-HDRLEN);
00053
00054
00055 ofs.close();
00056 }
00057
00058 int main(int argc, char* argv[])
00059 {
00060 try {
00061 XrdMonDecArgParser::parseArguments(argc, argv);
00062 const char* fName = XrdMonDecArgParser::_fPath.c_str();
00063
00064 fstream _file;
00065 _file.open(fName, ios::in|ios::binary);
00066 _file.seekg(0, ios::end);
00067 kXR_int64 fSize = _file.tellg();
00068 _file.seekg(XrdMonDecArgParser::_offset2Dump, ios::beg);
00069
00070 if (XrdMonDecArgParser::_offset2Dump != 0 ) {
00071 dumpOnePacket(XrdMonDecArgParser::_offset2Dump, _file);
00072 } else {
00073 kXR_int64 packetNo = 0;
00074 while ( fSize > _file.tellg() ) {
00075 dumpOnePacket(++packetNo, _file);
00076 }
00077 }
00078 } catch (XrdMonException& e) {
00079 e.printIt();
00080 return 1;
00081 }
00082
00083 return 0;
00084 }