Module: sems Branch: master Commit: 18a79339861a8a7217b92d16b3e4021386cd6a84 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=18a79339861a8a7217b92d16b3e4021386cd6a84
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Tue Feb 22 22:55:44 2011 +0100 new: tools: sems-logfile-splitter extracts debug log entries of a single call from (big) logfiles --- core/Makefile | 16 ++++- core/tools/Makefile | 22 ++++++ core/tools/logfile-splitter.cpp | 155 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+), 2 deletions(-) diff --git a/core/Makefile b/core/Makefile index f9e3b9b..6adf1b9 100644 --- a/core/Makefile +++ b/core/Makefile @@ -3,6 +3,7 @@ LIBNAME=sems.so PLUGIN_DIR=plug-in SIP_STACK_DIR=sip +TOOLS_DIR=tools SRCS=$(filter-out $(NAME).cpp, $(wildcard *.cpp)) HDRS=$(SRCS:.cpp=.h) @@ -16,8 +17,8 @@ all: ../Makefile.defs -@$(MAKE) sip_stack && \ $(MAKE) deps && \ $(MAKE) $(NAME) && \ - $(MAKE) modules - + $(MAKE) modules && \ + $(MAKE) tools .PHONY: clean clean: @@ -25,6 +26,7 @@ clean: rm -f lib/*.so compat/getos compat/getarch $(MAKE) -C $(SIP_STACK_DIR) clean $(MAKE) -C $(PLUGIN_DIR) clean + $(MAKE) -C $(TOOLS_DIR) clean .PHONY: sip_stack sip_stack: @@ -38,6 +40,12 @@ modules: -@echo "making core modules" -@cd $(PLUGIN_DIR); $(MAKE) modules +.PHONY: tools +tools: + -@echo "" + -@echo "making tools" + -@cd $(TOOLS_DIR); $(MAKE) all + .PHONY: test test: -@echo "" @@ -75,6 +83,7 @@ install: all mk-install-dirs \ install-cfg \ install-bin \ install-modules \ + install-tools @@ -99,6 +108,9 @@ install-bin: $(DESTDIR)$(bin-prefix)/$(bin-dir) install-modules: $(PLUGIN_DIR) $(DESTDIR)$(modules-prefix)/$(modules-dir) $(MAKE) -C $(PLUGIN_DIR) install +install-tools: $(TOOLS_DIR) + $(MAKE) -C $(TOOLS_DIR) install + install-modules-cfg: $(PLUGIN_DIR) $(MAKE) -C $(PLUGIN_DIR) install-cfg diff --git a/core/tools/Makefile b/core/tools/Makefile new file mode 100644 index 0000000..4c2a39d --- /dev/null +++ b/core/tools/Makefile @@ -0,0 +1,22 @@ +all: make_tools + +COREPATH ?= ../ +include $(COREPATH)/../Makefile.defs + +sems-tools = sems-logfile-callextract + +install: $(sems-tools) install_tools + +make_tools: $(sems-tools) + +install_tools: $(DESTDIR)$(bin-prefix)/$(bin-dir) + -@for r in $(sems-tools) ; do \ + $(INSTALL-TOUCH) $(DESTDIR)$(bin-prefix)/$(bin-dir)/$$r ; \ + $(INSTALL-BIN) $$r $(DESTDIR)$(bin-prefix)/$(bin-dir) ; \ + done + +sems-logfile-callextract: logfile-splitter.o + g++ -o sems-logfile-callextract logfile-splitter.o + +clean: + rm -f logfile-splitter.o sems-logfile-callextract \ No newline at end of file diff --git a/core/tools/logfile-splitter.cpp b/core/tools/logfile-splitter.cpp new file mode 100644 index 0000000..55525b4 --- /dev/null +++ b/core/tools/logfile-splitter.cpp @@ -0,0 +1,155 @@ +// quick hack to separate one call per callid from a logfile + +using namespace std; +#include <string> +#include <vector> +#include <algorithm> +#include <map> +std::vector<string> explode(const string& s, const string& delim, + const bool keep_empty = false); + +#include <iostream> +#include <fstream> + +using namespace std; + +int main(int argc, char *argv[]) +{ + if (argc<3) { + cout << "usage: " << argv[0] << " infile callid" << endl; + exit(1); + } + + ifstream f; + + string fname = argv[1]; + string callid = argv[2]; + f.open(argv[1]); + if (!f.good()) { + cerr << "error opening file " << fname << endl; + exit(1); + } + + string app_thread; + string ltag; + + // threadid log + map<string, string> udprecv_log; + map<string, string> appthread_log; + + while (!f.eof()) { + string s; + getline(f,s); + + vector<string> v = explode(s, " "); + + unsigned log_offset = 5; // offset of thread + if (v.size() < log_offset+1) + continue; + + string t = v[log_offset + 0]; // thread + string delim; + if (v.size() > log_offset + 4) + delim = v[log_offset + 4]; // vv or ^^ + string ptype; + if (v.size() > log_offset + 5) + ptype = v[log_offset + 5]; // M or S + + // cout << "thread " << t << " delim " << delim << " ptype " << ptype << endl; + + if (delim == "vv") { + // block starts + if (ptype == "M") { // message received + + udprecv_log[t] = s+"\n"; // new thread block + } else if (ptype == "S") { // app processing +#define GET_CALL_IDENT \ + string call_ident; \ + if (v.size() > log_offset + 6) \ + call_ident = v[log_offset + 6]; \ + call_ident = call_ident.substr(1, call_ident.length()-2); \ + vector<string> ci_parts = explode(call_ident, "|", true); \ + string ci_cid = ci_parts[0]; \ + string ci_ltag = ci_parts[1]; + + GET_CALL_IDENT; + + if (!ci_cid.empty() && ci_cid != callid) + continue; // other call + + appthread_log[t] = s+"\n"; + } else { + cerr << "unknown ptype " << ptype << " in '" << s << "'" << endl; + continue; + } + } else if (delim == "^^") { + // block ends + if (ptype == "M") { // message received + GET_CALL_IDENT; + + map<string, string>::iterator it=udprecv_log.find(t); + if ((ci_cid == callid) && (it != udprecv_log.end())) { + cout << endl << endl << it->second << s+"\n"; + } + + if (it != udprecv_log.end()) { + udprecv_log.erase(it); + } + } else if (ptype == "S") { // app processing + GET_CALL_IDENT; + + map<string, string>::iterator it=appthread_log.find(t); + if ((ci_cid == callid) && (it != appthread_log.end())) { + cout << endl << endl << it->second << s+"\n"; + } + + if (it != appthread_log.end()) { + appthread_log.erase(it); + } + + } else { + cerr << "unknown ptype " << ptype << " in '" << s << "'" << endl; + continue; + } + + } else { + map<string, string>::iterator it=udprecv_log.find(t); + if (it != udprecv_log.end()) { + it->second+=s+"\n"; + continue; + } + it=appthread_log.find(t); + if (it != appthread_log.end()) { + it->second+=s+"\n"; + continue; + } + } + } +} + + +// Explode string by a separator to a vector +// see http://stackoverflow.com/questions/236129/c-how-to-split-a-string +std::vector<string> explode(const string& s, const string& delim, + const bool keep_empty) { + vector<string> result; + if (delim.empty()) { + result.push_back(s); + return result; + } + string::const_iterator substart = s.begin(), subend; + while (true) { + subend = search(substart, s.end(), delim.begin(), delim.end()); + string temp(substart, subend); + if (keep_empty || !temp.empty()) { + result.push_back(temp); + } + if (subend == s.end()) { + break; + } + substart = subend + delim.size(); + } + return result; +} + + _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
