Use string instead of stringstream
Most of the monitor was already using string for formatted printing.
This commit is contained in:
		@ -12,15 +12,14 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "mariadbmon.hh"
 | 
			
		||||
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <queue>
 | 
			
		||||
#include <maxscale/modutil.h>
 | 
			
		||||
#include <maxscale/mysql_utils.h>
 | 
			
		||||
#include <maxscale/utils.hh>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using std::string;
 | 
			
		||||
using maxscale::string_printf;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,10 +14,12 @@
 | 
			
		||||
#include "gtid.hh"
 | 
			
		||||
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
#include <maxbase/assert.h>
 | 
			
		||||
#include <maxscale/utils.hh>
 | 
			
		||||
 | 
			
		||||
using std::string;
 | 
			
		||||
using maxscale::string_printf;
 | 
			
		||||
 | 
			
		||||
GtidList GtidList::from_string(const string& gtid_string)
 | 
			
		||||
{
 | 
			
		||||
@ -226,12 +228,12 @@ bool Gtid::eq(const Gtid& rhs) const
 | 
			
		||||
 | 
			
		||||
string Gtid::to_string() const
 | 
			
		||||
{
 | 
			
		||||
    std::stringstream ss;
 | 
			
		||||
    string rval;
 | 
			
		||||
    if (m_server_id != SERVER_ID_UNKNOWN)
 | 
			
		||||
    {
 | 
			
		||||
        ss << m_domain << "-" << m_server_id << "-" << m_sequence;
 | 
			
		||||
        rval += string_printf("%" PRIu32 "-%" PRIi64 "-%" PRIu64, m_domain, m_server_id, m_sequence);
 | 
			
		||||
    }
 | 
			
		||||
    return ss.str();
 | 
			
		||||
    return rval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Gtid GtidList::get_gtid(uint32_t domain) const
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,6 @@
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
#include <iomanip>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <maxscale/mysql_utils.h>
 | 
			
		||||
#include <maxscale/utils.hh>
 | 
			
		||||
@ -627,29 +626,34 @@ const char* MariaDBServer::name() const
 | 
			
		||||
 | 
			
		||||
string MariaDBServer::diagnostics() const
 | 
			
		||||
{
 | 
			
		||||
    std::stringstream ss;
 | 
			
		||||
    ss << "Server:                 " << name() << "\n";
 | 
			
		||||
    ss << "Server ID:              " << m_server_id << "\n";
 | 
			
		||||
    ss << "Read only:              " << (m_read_only ? "Yes" : "No") << "\n";
 | 
			
		||||
    ss << (m_slave_status.empty() ? "No slave connections \n" : "Slave connections: \n");
 | 
			
		||||
    // Format strings.
 | 
			
		||||
    const char fmt_string[] = "%-23s %s\n";
 | 
			
		||||
    const char fmt_int[] = "%-23s %i\n";
 | 
			
		||||
    const char fmt_int64[] = "%-23s %" PRIi64 "\n";
 | 
			
		||||
 | 
			
		||||
    for (const SlaveStatus& sstatus : m_slave_status)
 | 
			
		||||
    {
 | 
			
		||||
        ss << sstatus.to_string() << "\n";
 | 
			
		||||
    }
 | 
			
		||||
    string rval;
 | 
			
		||||
    rval += string_printf(fmt_string, "Server:", name());
 | 
			
		||||
    rval += string_printf(fmt_int64, "Server ID:", m_server_id);
 | 
			
		||||
    rval += string_printf(fmt_string, "Read only:", (m_read_only ? "Yes" : "No"));
 | 
			
		||||
    if (!m_gtid_current_pos.empty())
 | 
			
		||||
    {
 | 
			
		||||
        ss << "Gtid current position:  " << m_gtid_current_pos.to_string() << "\n";
 | 
			
		||||
        rval += string_printf(fmt_string, "Gtid current position:", m_gtid_current_pos.to_string().c_str());
 | 
			
		||||
    }
 | 
			
		||||
    if (!m_gtid_binlog_pos.empty())
 | 
			
		||||
    {
 | 
			
		||||
        ss << "Gtid binlog position:   " << m_gtid_binlog_pos.to_string() << "\n";
 | 
			
		||||
        rval += string_printf(fmt_string, "Gtid binlog position:", m_gtid_binlog_pos.to_string().c_str());
 | 
			
		||||
    }
 | 
			
		||||
    if (m_node.cycle != NodeData::CYCLE_NONE)
 | 
			
		||||
    {
 | 
			
		||||
        ss << "Master group:           " << m_node.cycle << "\n";
 | 
			
		||||
        rval += string_printf(fmt_int, "Master group:", m_node.cycle);
 | 
			
		||||
    }
 | 
			
		||||
    return ss.str();
 | 
			
		||||
 | 
			
		||||
    rval += (m_slave_status.empty() ? "No slave connections\n" : "Slave connections:\n");
 | 
			
		||||
    for (const SlaveStatus& sstatus : m_slave_status)
 | 
			
		||||
    {
 | 
			
		||||
        rval += sstatus.to_string() + "\n";
 | 
			
		||||
    }
 | 
			
		||||
    return rval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
json_t* MariaDBServer::to_json() const
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user