Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49371 - in sandbox/tools/profile_templates: . src
From: steven_at_[hidden]
Date: 2008-10-17 14:07:25


Author: steven_watanabe
Date: 2008-10-17 14:07:24 EDT (Fri, 17 Oct 2008)
New Revision: 49371
URL: http://svn.boost.org/trac/boost/changeset/49371

Log:
Re-enable gcc support (<4.3)
Text files modified:
   sandbox/tools/profile_templates/src/filter.cpp | 27 ++++++++++++++++++---
   sandbox/tools/profile_templates/src/postprocess.cpp | 50 +++++++++++++++++++++++++++++++++++++++
   sandbox/tools/profile_templates/template-profile.jam | 6 ++--
   3 files changed, 75 insertions(+), 8 deletions(-)

Modified: sandbox/tools/profile_templates/src/filter.cpp
==============================================================================
--- sandbox/tools/profile_templates/src/filter.cpp (original)
+++ sandbox/tools/profile_templates/src/filter.cpp 2008-10-17 14:07:24 EDT (Fri, 17 Oct 2008)
@@ -11,7 +11,14 @@
 #include <cstdio>
 
 const char* search("template_profiler");
-const char* back_trace_search("see reference to");
+
+#if defined(_MSC_VER)
+ const char* back_trace_search("see reference to");
+#elif defined(__GNUC__)
+ const char* back_trace_search("instantiated from");
+#else
+ #error only Microsoft and gcc are supported.
+#endif
 
 void copy_flat_only() {
     std::string buffer;
@@ -64,8 +71,14 @@
                 for(std::size_t i = 0; i < buffer.size(); ++i) {
                     std::putchar(buffer[i]);
                 }
- if(++counter % 100 == 0) {
- std::fprintf(stderr, "On Instantiation %d\n", counter);
+ ++counter;
+#ifdef _MSC_VER
+ int instantiations = counter / 2;
+#else
+ int instantiations = counter;
+#endif
+ if(++instantiations % 100 == 0) {
+ std::fprintf(stderr, "On Instantiation %d\n", instantiations);
                 }
                 buffer.clear();
                 matched = false;
@@ -115,8 +128,14 @@
             pos = 0;
         }
     }
+#elif defined(__GNUC__)
+ // trying to figure out what we should copy is too hard.
+ int ch;
+ while((ch = std::getchar()) != EOF) {
+ std::putchar(ch);
+ }
 #else
- #error gcc is not supported yet.
+ #error Unknown compiler
 #endif
 }
 

Modified: sandbox/tools/profile_templates/src/postprocess.cpp
==============================================================================
--- sandbox/tools/profile_templates/src/postprocess.cpp (original)
+++ sandbox/tools/profile_templates/src/postprocess.cpp 2008-10-17 14:07:24 EDT (Fri, 17 Oct 2008)
@@ -19,6 +19,7 @@
 #include <iterator>
 #include <algorithm>
 #include <iomanip>
+#include <vector>
 
 #ifdef _MSC_VER
 
@@ -29,7 +30,8 @@
 #elif defined(__GNUC__)
 
 boost::regex warning_message("(.*): warning: division by zero in .template_profiler::value / 0.");
-#error gcc is not supported yet
+boost::regex call_graph_line("(.*):(\\d+): instantiated from .*");
+boost::regex split_file_and_line("(.*):(\\d+)");
 
 #else
 
@@ -133,6 +135,8 @@
         }
         const line_id* current_instantiation = 0;
         std::ifstream input(input_file_name);
+#if defined(_MSC_VER)
+ // msvc puts the warning first and follows it with the backtrace.
         while(std::getline(input, line)) {
             boost::smatch match;
             if(boost::regex_match(line, match, warning_message)) {
@@ -162,6 +166,50 @@
                 ++graph[parent].total_with_children;
             }
         }
+#elif defined(__GNUC__)
+ // gcc puts the backtrace first, and then the warning.
+ // so we have to buffer the backtrace until we reach the
+ // warning.
+ std::vector<std::string> pending_lines;
+ while(std::getline(input, line)) {
+ boost::smatch match;
+ if(boost::regex_match(line, match, warning_message)) {
+ std::string file_and_line(match[1].str());
+ boost::regex_match(file_and_line, match, split_file_and_line);
+ std::string file = match[1];
+ int line = boost::lexical_cast<int>(match[2].str());
+ current_instantiation = &*lines.find(line_id(file, line));
+ ++graph[current_instantiation].total_with_children;
+ ++graph[current_instantiation].count;
+ BOOST_FOREACH(const std::string& line, pending_lines) {
+ boost::regex_match(line, match, call_graph_line);
+ std::string file = match[1];
+ int line = boost::lexical_cast<int>(match[2].str());
+ std::set<line_id>::const_iterator pos = lines.lower_bound(line_id(file, line));
+ if(pos != lines.end()) {
+ if(*pos != line_id(file, line) && pos != lines.begin() && boost::prior(pos)->first == file) {
+ --pos;
+ }
+ } else if(pos != lines.begin()) {
+ --pos;
+ } else {
+ break;
+ }
+ const line_id* parent = &*pos;
+ ++graph[current_instantiation].parents[parent];
+ ++graph[parent].children[current_instantiation];
+ ++graph[parent].total_with_children;
+ }
+ pending_lines.clear();
+ } else if(boost::regex_match(line, match, call_graph_line)) {
+ pending_lines.push_back(line);
+ } else {
+ pending_lines.clear();
+ }
+ }
+#else
+ #error Unsupported compiler
+#endif
         typedef std::pair<const line_id*, node_info> call_graph_node_t;
         std::vector<call_graph_node_t> call_graph;
         std::copy(graph.begin(), graph.end(), std::back_inserter(call_graph));

Modified: sandbox/tools/profile_templates/template-profile.jam
==============================================================================
--- sandbox/tools/profile_templates/template-profile.jam (original)
+++ sandbox/tools/profile_templates/template-profile.jam 2008-10-17 14:07:24 EDT (Fri, 17 Oct 2008)
@@ -48,7 +48,7 @@
     }
 
     actions compile.c++.template-profile {
- "$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-$(TEMPLATE_DEPTH) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -D PROFILE_TEMPLATES -I"$(INCLUDES)" -c "$(>:W)" 2>&1 "$(FILTER)" | $(FILTER-OPTIONS) >"$(<)"
+ "$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-$(TEMPLATE_DEPTH) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -D PROFILE_TEMPLATES -I"$(INCLUDES)" -c "$(>:W)" 2>&1 | "$(FILTER)" $(FILTER-OPTIONS) >"$(<)"
     }
 
 }
@@ -59,11 +59,11 @@
     template-profile.init-toolset msvc ;
 
     actions compile.c++.preprocess {
- $(.CC) @"@($(<[1]:W).rsp:E="$(>[1]:W)" -E $(lang-opt) -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(OPTIONS) $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES:W)")" | $(INSTRUMENT-ACTION) >"$(<[1]:W)"
+ $(.CC) @"@($(<[1]:W).rsp:E="$(>[1]:W)" -E $(lang-opt) -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(OPTIONS) $(.nl)-D$(DEFINES) $(.nl)"-I$(INCLUDES:W)")" | $(INSTRUMENT-ACTION) >"$(<[1]:W)"
     }
 
     actions compile.c++.template-profile {
- $(.CC) @"@($(<[1]:W).rsp:E="$(>[1]:W)" -c $(lang-opt) -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(OPTIONS) -W4 $(nl)-D$(DEFINES) -D PROFILE_TEMPLATES $(nl)"-I$(INCLUDES:W)")" 2>&1 | "$(FILTER)" $(FILTER-OPTIONS) >"$(<)"
+ $(.CC) @"@($(<[1]:W).rsp:E="$(>[1]:W)" -c $(lang-opt) -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(OPTIONS) -W4 $(.nl)-D$(DEFINES) -D PROFILE_TEMPLATES $(.nl)"-I$(INCLUDES:W)")" 2>&1 | "$(FILTER)" $(FILTER-OPTIONS) >"$(<)"
     }
 
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk