From d208fa3c3794e6c36e76e5367b8a99c521788be6 Mon Sep 17 00:00:00 2001 From: drbob Date: Tue, 17 May 2011 18:03:05 +0000 Subject: [PATCH] re-worked printcache to analyse a large batch of cache files. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4209 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/tests/printcache/main_extended.cpp | 153 ++++++++++++++++++ .../src/tests/printcache/printcache.pro | 27 +++- 2 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 libretroshare/src/tests/printcache/main_extended.cpp diff --git a/libretroshare/src/tests/printcache/main_extended.cpp b/libretroshare/src/tests/printcache/main_extended.cpp new file mode 100644 index 000000000..0c77a6348 --- /dev/null +++ b/libretroshare/src/tests/printcache/main_extended.cpp @@ -0,0 +1,153 @@ +/* + * main.cpp + * + * Created on: 11 Apr 2011 + * Author: greyfox + */ + +#include +#include +#include + +#include "argstream.h" +#include "pqi/pqistreamer.h" +#include "pqi/pqibin.h" +#include "serialiser/rsdistribitems.h" +#include "pqi/pqistore.h" + +int storeMsg(std::map > &msgMap, std::string filename, + std::string grpId, std::string msgId); + +pqistore *BuildSerialiser(int type, std::string filename); + +int main(int argc, char **argv) +{ + + std::list fileList; + std::list::iterator fit; + + for(int i = 1; i < argc; i++) + { + fileList.push_back(argv[i]); + } + + std::map > msgMap; + std::map >::iterator mit; + + bool printInput = true; + bool printAll = true; + bool printSummary = true; + int distrib_msgs = 0; + int signed_msgs = 0; + + for(fit = fileList.begin(); fit != fileList.end(); fit++) + { + if (printInput) + { + std::cerr << "Loading File: " << *fit; + std::cerr << std::endl; + } + + /* process this file */ + pqistore *store = BuildSerialiser(0, *fit); + RsItem* item; + RsDistribMsg *distMsg; + RsDistribSignedMsg *signMsg; + + while(NULL != (item = store->GetItem())) + { + if (NULL != (distMsg = dynamic_cast(item))) + { + if (printInput) + { + std::cerr << "Grp = " << distMsg->grpId; + std::cerr << ", parent = " << distMsg->parentId; + std::cerr << ", msgId = " << distMsg->msgId; + std::cerr << std::endl; + } + storeMsg(msgMap, *fit, distMsg->grpId, distMsg->msgId); + ++distrib_msgs ; + } + if (NULL != (signMsg = dynamic_cast(item))) + { + if (printInput) + { + std::cerr << "Grp = " << signMsg->grpId; + std::cerr << ", msgId = " << signMsg->msgId; + std::cerr << ", type = " << signMsg->packet.tlvtype; + std::cerr << ", len = " << signMsg->packet.bin_len; + std::cerr << std::endl; + } + storeMsg(msgMap, *fit, signMsg->grpId, signMsg->msgId); + ++signed_msgs ; + } + } + + delete store; + } + for(mit = msgMap.begin(); mit != msgMap.end(); mit++) + { + bool print = printAll; + if (mit->second.size() > 1) + { + /* duplicates */ + print = true; + } + + if (print) + { + std::cerr << "MsgId: " << mit->first; + std::cerr << " in Files: "; + + std::list::iterator fit; + for(fit = mit->second.begin(); fit != mit->second.end(); fit++) + { + std::cerr << *fit << " "; + } + std::cerr << std::endl; + } + } + if (printSummary) + { + std::cerr << "# RsDistribMsg(s): " << distrib_msgs << std::endl; + std::cerr << "# RsDistribSignedMsg(s): " << signed_msgs << std::endl; + std::cerr << std::endl; + } +} + + +int storeMsg(std::map > &msgMap, std::string filename, + std::string grpId, std::string msgId) +{ + std::map >::iterator mit; + mit = msgMap.find(msgId); + if (mit == msgMap.end()) + { + std::list fileList; + fileList.push_back(filename); + msgMap[msgId] = fileList; + } + else + { + (mit->second).push_back(filename); + } + return 1; +} + + +pqistore *BuildSerialiser(int type, std::string filename) +{ + BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE); + RsSerialiser *rsSerialiser = new RsSerialiser(); + RsSerialType *serialType = new RsDistribSerialiser(); + rsSerialiser->addSerialType(serialType); + + // can use type to add more serialiser types + //RsSerialType *serialType = new RsDistribSerialiser(); + //rsSerialiser->addSerialType(serialType); + + pqistore *store = new pqistore(rsSerialiser, "", bio, BIN_FLAGS_READABLE); + return store; +} + + diff --git a/libretroshare/src/tests/printcache/printcache.pro b/libretroshare/src/tests/printcache/printcache.pro index 4126e251d..04b19511c 100644 --- a/libretroshare/src/tests/printcache/printcache.pro +++ b/libretroshare/src/tests/printcache/printcache.pro @@ -1,9 +1,30 @@ TEMPLATE = app CONFIG = debug -SOURCES = main.cpp +#SOURCES = main.cpp +SOURCES = main_extended.cpp INCLUDEPATH *= ../.. -LIBS = -lstdc++ -lm ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a \ - -lssl -lcrypto -lgpgme -lupnp -lgnome-keyring +linux { + #LIBS = -lstdc++ -lm + LIBS += ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a + LIBS += -lssl -lcrypto -lgpgme -lupnp -lgnome-keyring +} +macx { + # ENABLE THIS OPTION FOR Univeral Binary BUILD. + # CONFIG += ppc x86 + # QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 + # CONFIG -= uitools + + LIBS += ../../lib/libretroshare.a + LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan + LIBS += ../../../../../miniupnpc-1.0/libminiupnpc.a + LIBS += ../../../../libbitdht/src/lib/libbitdht.a + LIBS += -framework CoreFoundation + LIBS += -framework Security + + # LIBS += -framework CoreServices + + +}