Permalink
Browse files

Removing OStringStream from PerfLog.

Issue #22.
  • Loading branch information...
1 parent a2039b0 commit 0f0a6a28ba94cafb54a9828d8b30e107f532e4fd @jwpeterson jwpeterson committed Dec 20, 2012
Showing with 171 additions and 88 deletions.
  1. +171 −88 src/utils/perf_log.C
View
@@ -28,7 +28,6 @@
#include <vector>
// Local includes
-#include "libmesh/o_string_stream.h"
#include "libmesh/perf_log.h"
#include "libmesh/timestamp.h"
@@ -38,7 +37,7 @@ namespace {
void output_character_line(const unsigned int n,
const char c,
- OStringStream& out)
+ std::ostringstream& out)
{
for (unsigned int i=0; i<n; ++i)
out << c;
@@ -110,7 +109,7 @@ void PerfLog::clear()
std::string PerfLog::get_info_header() const
{
- OStringStream out;
+ std::ostringstream out;
if (log_events)
{
@@ -136,20 +135,20 @@ std::string PerfLog::get_info_header() const
out << "\n";
// Construct string stream objects for each of the outputs
- OStringStream pid_stream;
- OStringStream nprocs_stream;
- OStringStream time_stream;
- OStringStream os_stream;
- OStringStream host_stream;
- OStringStream osrel_stream;
- OStringStream osver_stream;
- OStringStream machine_stream;
- OStringStream user_stream;
- OStringStream config_stream;
+ std::ostringstream
+ pid_stream,
+ nprocs_stream,
+ time_stream,
+ os_stream,
+ host_stream,
+ osrel_stream,
+ osver_stream,
+ machine_stream,
+ user_stream;
// Put pointers to these streams in a vector
- std::vector<OStringStream*> v;
+ std::vector<std::ostringstream*> v;
v.push_back(&pid_stream);
v.push_back(&nprocs_stream);
v.push_back(&time_stream);
@@ -211,25 +210,30 @@ std::string PerfLog::get_info_header() const
for (unsigned int i=0; i<v.size(); ++i)
{
if (v[i]->str().size() > 0)
- {
- out << v[i]->str();
- OSSStringright(out, max_length+4 - v[i]->str().size(), "|\n");
- }
+ out << v[i]->str()
+ << std::setw(max_length + 4 - v[i]->str().size())
+ << std::right
+ << "|\n";
}
// Print out configuration header plus first parsed string. The
// magic number 18 below accounts for the length of the word
// 'Configuration'.
- out << "| Configuration: " << parsed_libmesh_configure_info[0];
- OSSStringright(out, max_length+4 - parsed_libmesh_configure_info[0].size() - 18, "|\n");
+ out << "| Configuration: "
+ << parsed_libmesh_configure_info[0]
+ << std::setw(max_length + 4 - parsed_libmesh_configure_info[0].size() - 18)
+ << std::right
+ << "|\n";
// Loop over the parsed_libmesh_configure_info and add end formatting. The magic
// number 3 below accounts for the leading 'pipe' character and indentation
for (unsigned i=1; i<parsed_libmesh_configure_info.size(); ++i)
{
- out << "| ";
- out << parsed_libmesh_configure_info[i];
- OSSStringright(out, max_length+4 - parsed_libmesh_configure_info[i].size() - 3, "|\n");
+ out << "| "
+ << parsed_libmesh_configure_info[i]
+ << std::setw(max_length + 4 - parsed_libmesh_configure_info[i].size() - 3)
+ << std::right
+ << "|\n";
}
@@ -246,7 +250,7 @@ std::string PerfLog::get_info_header() const
std::string PerfLog::get_perf_info() const
{
- OStringStream out;
+ std::ostringstream out;
if (log_events && !log.empty())
{
@@ -296,7 +300,7 @@ std::string PerfLog::get_perf_info() const
{
// Construct temporary message string
- OStringStream temp;
+ std::ostringstream temp;
temp << "| " << label_name << " Performance: Alive time=" << elapsed_time
<< ", Active time=" << total_time;
@@ -311,9 +315,9 @@ std::string PerfLog::get_perf_info() const
// happen often, hopefully. Add two additional characters for a
// space and a "|" character at the end.
if (temp_size < total_col_width+2)
- {
- OSSStringright(out, total_col_width-temp_size+2, "|");
- }
+ out << std::setw(total_col_width - temp_size + 2)
+ << std::right
+ << "|";
out << '\n';
}
@@ -325,26 +329,56 @@ std::string PerfLog::get_perf_info() const
// Write out the header for the events listing
- out << "| ";
- OSSStringleft(out,event_col_width,"Event");
- OSSStringleft(out,ncalls_col_width,"nCalls");
- OSSStringleft(out,tot_time_col_width,"Total Time");
- OSSStringleft(out,avg_time_col_width,"Avg Time");
- OSSStringleft(out,tot_time_incl_sub_col_width,"Total Time");
- OSSStringleft(out,avg_time_incl_sub_col_width,"Avg Time");
- OSSStringleft(out,pct_active_col_width+pct_active_incl_sub_col_width,"% of Active Time");
- out << "|\n";
- out << "| ";
- OSSStringleft(out,event_col_width,"");
- OSSStringleft(out,ncalls_col_width,"");
- OSSStringleft(out,tot_time_col_width,"w/o Sub");
- OSSStringleft(out,avg_time_col_width,"w/o Sub");
- OSSStringleft(out,tot_time_incl_sub_col_width,"With Sub");
- OSSStringleft(out,avg_time_incl_sub_col_width,"With Sub");
- OSSStringleft(out,pct_active_col_width,"w/o S");
- OSSStringleft(out,pct_active_incl_sub_col_width,"With S");
+ out << "| "
+ << std::setw(event_col_width)
+ << std::left
+ << "Event"
+ << std::setw(ncalls_col_width)
+ << std::left
+ << "nCalls"
+ << std::setw(tot_time_col_width)
+ << std::left
+ << "Total Time"
+ << std::setw(avg_time_col_width)
+ << std::left
+ << "Avg Time"
+ << std::setw(tot_time_incl_sub_col_width)
+ << std::left
+ << "Total Time"
+ << std::setw(avg_time_incl_sub_col_width)
+ << std::left
+ << "Avg Time"
+ << std::setw(pct_active_col_width+pct_active_incl_sub_col_width)
+ << std::left
+ << "% of Active Time"
+ << "|\n"
+ << "| "
+ << std::setw(event_col_width)
+ << std::left
+ << ""
+ << std::setw(ncalls_col_width)
+ << std::left
+ << ""
+ << std::setw(tot_time_col_width)
+ << std::left
+ << "w/o Sub"
+ << std::setw(avg_time_col_width)
+ << std::left
+ << "w/o Sub"
+ << std::setw(tot_time_incl_sub_col_width)
+ << std::left
+ << "With Sub"
+ << std::setw(avg_time_incl_sub_col_width)
+ << std::left
+ << "With Sub"
+ << std::setw(pct_active_col_width)
+ << std::left
+ << "w/o S"
+ << std::setw(pct_active_incl_sub_col_width)
+ << std::left
+ << "With S"
+ << "|\n|";
- out << "|\n|";
output_character_line(total_col_width, '-', out);
out << "|\n|";
output_character_line(total_col_width, ' ', out);
@@ -377,10 +411,11 @@ std::string PerfLog::get_perf_info() const
// Print the event name
if (pos->first.first == "")
- {
- out << "| ";
- OSSStringleft(out,event_col_width,pos->first.second);
- }
+ out << "| "
+ << std::setw(event_col_width)
+ << std::left
+ << pos->first.second;
+
else
{
if (last_header != pos->first.first)
@@ -394,83 +429,131 @@ std::string PerfLog::get_perf_info() const
// print header name (account for additional space before
// the header)
- out << "| ";
- OSSStringleft(out, total_col_width-1, pos->first.first);
- out << "|\n";
+ out << "| "
+ << std::setw(total_col_width-1)
+ << std::left
+ << pos->first.first
+ << "|\n";
}
- out << "| ";
- OSSStringleft(out, event_col_width-2, pos->first.second);
+ out << "| "
+ << std::setw(event_col_width-2)
+ << std::left
+ << pos->first.second;
}
// Print the number of calls to the event.
- OSSInt(out,ncalls_col_width,perf_count);
+ out << std::setw(ncalls_col_width)
+ << perf_count;
+
+ // Save the original stream flags
+ std::ios_base::fmtflags out_flags = out.flags();
// Print the total time spent in the event
- out.setf(std::ios::fixed);
- OSSRealleft(out,tot_time_col_width,4,perf_time);
+ out << std::fixed
+ << std::setprecision(4)
+ << std::setw(tot_time_col_width)
+ << std::left
+ << perf_time;
+
// Print the average time per function call
- OSSRealleft(out,avg_time_col_width,6,perf_avg_time);
+ out << std::fixed
+ << std::setprecision(6)
+ << std::setw(avg_time_col_width)
+ << std::left
+ << perf_avg_time;
// Print the total time spent in the event incl. sub-events
- OSSRealleft(out,tot_time_incl_sub_col_width,4,perf_time_incl_sub);
+ out << std::fixed
+ << std::setprecision(4)
+ << std::setw(tot_time_incl_sub_col_width)
+ << std::left
+ << perf_time_incl_sub;
// Print the average time per function call incl. sub-events
- OSSRealleft(out,avg_time_incl_sub_col_width,6,perf_avg_time_incl_sub);
+ out << std::fixed
+ << std::setprecision(6)
+ << std::setw(avg_time_incl_sub_col_width)
+ << std::left
+ << perf_avg_time_incl_sub;
// Print the percentage of the time spent in the event
- OSSRealleft(out,pct_active_col_width,2,perf_percent);
+ out << std::fixed
+ << std::setprecision(2)
+ << std::setw(pct_active_col_width)
+ << std::left
+ << perf_percent;
// Print the percentage of the time spent in the event incl. sub-events
- OSSRealleft(out,pct_active_incl_sub_col_width,2,perf_percent_incl_sub);
+ out << std::fixed
+ << std::setprecision(2)
+ << std::setw(pct_active_incl_sub_col_width)
+ << std::left
+ << perf_percent_incl_sub;
- out << "|";
- out << '\n';
+ // Reset the stream flags
+ out.flags(out_flags);
+
+ out << "|\n";
}
}
out << ' ';
output_character_line(total_col_width, '-', out);
- out << '\n';
- out << "| ";
- OSSStringleft(out,event_col_width,"Totals:");
+ out << "\n| "
+ << std::setw(event_col_width)
+ << std::left
+ << "Totals:";
// Print the total number of logged function calls
// For routines which are called many times, summed_function_calls may
// exceed 7 digits. If this happens use, scientific notation.
if (summed_function_calls < 9999999)
- {
- OSSInt(out,ncalls_col_width,summed_function_calls);
- }
+ out << std::setw(ncalls_col_width)
+ << summed_function_calls;
else
{
- out.setf(std::ios::scientific);
- OSSRealleft(out, ncalls_col_width, 3, static_cast<Real>(summed_function_calls));
- out.unsetf(std::ios::scientific);
+ // Save the original stream flags
+ std::ios_base::fmtflags out_flags = out.flags();
+
+ out << std::scientific
+ << std::setprecision(3)
+ << std::setw(ncalls_col_width)
+ << std::left
+ << static_cast<Real>(summed_function_calls);
+
+ // Reset the stream flags
+ out.flags(out_flags);
}
- // Print the total time spent in logged function calls
- out.setf(std::ios::fixed);
- OSSRealleft(out,tot_time_col_width,4,summed_total_time);
+ // Print the total time spent in logged function calls. Don't bother saving/restoring
+ // the flags here since we are almost done with this stream anyway...
+ out << std::fixed
+ << std::setprecision(4)
+ << std::setw(tot_time_col_width)
+ << std::left
+ << summed_total_time;
// Null, the average time doesn't make sense as a total
- out.width(avg_time_col_width);
- out << "";
+ out << std::setw(avg_time_col_width) << "";
// Same for times that include sub-events
- out.width(tot_time_incl_sub_col_width);
- out << "";
- out.width(avg_time_incl_sub_col_width);
- out << "";
+ out << std::setw(tot_time_incl_sub_col_width)
+ << ""
+ << std::setw(avg_time_incl_sub_col_width)
+ << "";
// Print the total percentage
- OSSRealleft(out,pct_active_col_width,2,summed_percentage);
+ out << std::fixed
+ << std::setprecision(2)
+ << std::setw(pct_active_col_width)
+ << std::left
+ << summed_percentage;
- out.width(pct_active_incl_sub_col_width);
- out << "";
+ out << std::setw(pct_active_incl_sub_col_width) << "";
out << "|\n ";
output_character_line(total_col_width, '-', out);
@@ -484,7 +567,7 @@ std::string PerfLog::get_perf_info() const
std::string PerfLog::get_log() const
{
- OStringStream out;
+ std::ostringstream out;
if (log_events)
{

0 comments on commit 0f0a6a2

Please sign in to comment.