[Xorp-hackers] [PATCH] xorp: rib: test: Enable profiling with callgrind

igorm at etf.rs igorm at etf.rs
Tue Jun 12 00:31:13 PDT 2012


From: Igor Maravic <igorm at etf.rs>

Code should be pretified, maybe we can include some if defs,
checks if valgrind exists, reading of number of cycles
from argumetns...

Only for test purposes. To test it, just enter the accurate location of commands
in this line:
ifstream file("/home/igor/Work/xorp.ct/xorp/obj/x86_64-unknown-linux-gnu/rib/tests/commands");
---
 xorp/rib/tests/SConscript         |    5 +++
 xorp/rib/tests/test_rib_direct.cc |   64 ++++++++++++++++++++++++-------------
 xorp/rib/tests/test_rib_xrls.cc   |    5 +++
 3 files changed, 52 insertions(+), 22 deletions(-)

diff --git a/xorp/rib/tests/SConscript b/xorp/rib/tests/SConscript
index d2af49d..989c896 100644
--- a/xorp/rib/tests/SConscript
+++ b/xorp/rib/tests/SConscript
@@ -22,6 +22,11 @@ Import("env")
 
 env = env.Clone()
 
+#enable profiling with callgrind
+if not env['disable_werror']:
+	env['CFLAGS'].remove('-Werror')
+	env['CXXFLAGS'].remove('-Werror')
+
 env.AppendUnique(CPPPATH = [
 	'#',
 	'$BUILDDIR',
diff --git a/xorp/rib/tests/test_rib_direct.cc b/xorp/rib/tests/test_rib_direct.cc
index 5554b2d..0cfa403 100644
--- a/xorp/rib/tests/test_rib_direct.cc
+++ b/xorp/rib/tests/test_rib_direct.cc
@@ -35,6 +35,8 @@
 #include "rib.hh"
 #include "dummy_register_server.hh"
 
+#include <valgrind/callgrind.h>
+
 
 bool verbose = false;
 
@@ -71,8 +73,9 @@ RibParser::RibParser(RIB<IPv4>& rib)
 }
 
 static void
-parser_main()
+parser_main(int loops)
 {
+
     EventLoop eventloop;
 
     // Finder Server
@@ -81,36 +84,46 @@ parser_main()
 
     // Rib Server component
     XrlStdRouter xrl_std_router_rib(eventloop, "rib", fs.addr(), fs.port());
-
+    CALLGRIND_START_INSTRUMENTATION;
     //
     // The RIB manager
     //
     RibManager rib_manager(eventloop, xrl_std_router_rib, "fea");
     rib_manager.enable();
 
-    RIB<IPv4> rib(UNICAST, rib_manager, eventloop);
-    DummyRegisterServer register_server;
-
-    rib.initialize(register_server);
-
-    wait_until_xrl_router_is_ready(eventloop, xrl_std_router_rib);
-
-    RibParser parser(rib);
-
-    string cmd;
-    int line = 0;
-    while (feof(stdin) == 0) {
-	getline(cin, cmd);
-	if (feof(stdin) != 0)
-	    break;
-	line++;
-	printf("%d: %s\n", line, cmd.c_str());
-	parser.parse(cmd);
+    for (int i = 0; i < loops; i++) {
+	RIB<IPv4> rib(UNICAST, rib_manager, eventloop);
+	DummyRegisterServer register_server;
+
+	rib.initialize(register_server);
+
+	wait_until_xrl_router_is_ready(eventloop, xrl_std_router_rib);
+
+	RibParser parser(rib);
+	cout << "Pass number " << i << endl;
+	ifstream file("/home/igor/Work/xorp.ct/xorp/obj/x86_64-unknown-linux-gnu/rib/tests/commands");
+	if (!file) {
+	    cerr << "Error opening file " << endl;
+
+	    return;
+	}
+	string cmd;
+	int line = 0;
+	while (!file.eof()) {
+	    getline(file, cmd);
+	    if (file.eof())
+		break;
+	    line++;
+	    //cout << line << ": " << cmd << endl;
+	    parser.parse(cmd);
+	}
     }
+    CALLGRIND_STOP_INSTRUMENTATION;
+    CALLGRIND_DUMP_STATS;
 }
 
 int
-main (int /* argc */, char* argv[])
+main (int argc, char* argv[])
 {
     //
     // Initialize and start xlog
@@ -122,9 +135,16 @@ main (int /* argc */, char* argv[])
     xlog_add_default_output();
     xlog_start();
 
+    int loops = 1;
+    if (argc > 1) {
+	loops = atoi(argv[1]);
+    }
+    if (loops <= 0)
+	loops = 1;
+
     XorpUnexpectedHandler x(xorp_unexpected_handler);
     try {
-	parser_main();
+	parser_main(loops);
     } catch (...) {
 	xorp_catch_standard_exceptions();
     }
diff --git a/xorp/rib/tests/test_rib_xrls.cc b/xorp/rib/tests/test_rib_xrls.cc
index 4bae5f1..174bf81 100644
--- a/xorp/rib/tests/test_rib_xrls.cc
+++ b/xorp/rib/tests/test_rib_xrls.cc
@@ -36,6 +36,8 @@
 #include "dummy_register_server.hh"
 #include "xrl_target.hh"
 
+#include <valgrind/callgrind.h>
+
 
 bool verbose = false;
 
@@ -70,6 +72,7 @@ public:
 static void
 parser_main()
 {
+    CALLGRIND_START_INSTRUMENTATION;
     EventLoop eventloop;
 
     // Finder Server
@@ -114,6 +117,8 @@ parser_main()
 	    eventloop.run();
 	XLOG_ASSERT(cv == SUCCESS);
     }
+    CALLGRIND_STOP_INSTRUMENTATION;
+    CALLGRIND_DUMP_STATS;
 }
 
 int
-- 
1.7.5.4



More information about the Xorp-hackers mailing list