Commit cf0e63e3 authored by Pavel Vainerman's avatar Pavel Vainerman

(VMonitor): добавил вспомогательные функции pretty_str(...) чтобы

можно было вызывать "снаружи". (uniset2-vmonit): добавил команду -d |--dump - распечатать состояние и выйти
parent b9666421
...@@ -14,7 +14,8 @@ print_usage() ...@@ -14,7 +14,8 @@ print_usage()
{ {
[ "$1" = 0 ] || exec >&2 [ "$1" = 0 ] || exec >&2
echo "Usage: ${0##*/} [-s watch_sec] ObjectID1[@node],ObjectID2,.." echo "Usage: ${0##*/} [-s watch_sec | -d] ObjectID1[@node],ObjectID2,.."
echo " -d - dump state. Print state and exit"
# echo "" # echo ""
# uniset2-admin --help # uniset2-admin --help
...@@ -25,12 +26,15 @@ print_usage() ...@@ -25,12 +26,15 @@ print_usage()
[ -z "$1" ] && print_usage 1 [ -z "$1" ] && print_usage 1
#parse command line options #parse command line options
dump=
case "$1" in case "$1" in
-h|--help) print_usage 0;; -h|--help) print_usage 0;;
-s|--sec) shift; WATCH_SEC=$1; shift;; -s|--sec) shift; WATCH_SEC=$1; shift;;
-d|--dump) dump=1; shift;;
esac esac
OID=$1 OID=$1
shift shift
$WATCH -n $WATCH_SEC uniset2-admin --oinfo ${OID} $* [ -z "$dump" ] && $WATCH -n $WATCH_SEC uniset2-admin --oinfo ${OID} $*
\ No newline at end of file [ -n "$dump" ] && uniset2-admin --oinfo ${OID} $*
...@@ -1021,8 +1021,8 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO() ...@@ -1021,8 +1021,8 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO()
ostringstream s; ostringstream s;
s &lt;&lt; myname &lt;&lt; ": " &lt;&lt; endl; s &lt;&lt; myname &lt;&lt; ": " &lt;&lt; endl;
<xsl:for-each select="//smap/item"> <xsl:for-each select="//smap/item">
s &lt;&lt; " " &lt;&lt; setw(20) &lt;&lt; std::right &lt;&lt; "<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>" s &lt;&lt; " " &lt;&lt; setw(30) &lt;&lt; std::right &lt;&lt; "<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>"
&lt;&lt; "(" &lt;&lt; setw(20) &lt;&lt; std::left &lt;&lt; ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>)) &lt;&lt; ")" &lt;&lt; "(" &lt;&lt; setw(30) &lt;&lt; std::left &lt;&lt; ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>)) &lt;&lt; ")"
&lt;&lt; std::right &lt;&lt; " = " &lt;&lt; setw(6) &lt;&lt; <xsl:call-template name="setprefix"/><xsl:value-of select="@name"/> &lt;&lt; std::right &lt;&lt; " = " &lt;&lt; setw(6) &lt;&lt; <xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>
&lt;&lt; endl; &lt;&lt; endl;
</xsl:for-each> </xsl:for-each>
......
...@@ -29,12 +29,16 @@ ...@@ -29,12 +29,16 @@
#include "UniSetTypes.h" #include "UniSetTypes.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#ifndef VMON_DEF_FUNC #ifndef VMON_DEF_FUNC
#define VMON_DEF_FUNC(T) void add( const std::string& name, const T& v ) #define VMON_DEF_FUNC(T) \
void add( const std::string& name, const T& v );\
const std::string pretty_str( const std::string& name, const T* v )
#endif #endif
#ifndef VMON_DEF_FUNC2 #ifndef VMON_DEF_FUNC2
#define VMON_DEF_FUNC2(T) \ #define VMON_DEF_FUNC2(T) \
void add( const std::string& name, const T& v );\ void add( const std::string& name, const T& v );\
void add( const std::string& name, const unsigned T& v ) void add( const std::string& name, const unsigned T& v );\
const std::string pretty_str( const std::string& name, const T* v );\
const std::string pretty_str( const std::string& name, const unsigned T* v )
#endif #endif
#ifndef VMON_DEF_MAP #ifndef VMON_DEF_MAP
...@@ -124,6 +128,10 @@ class VMonitor ...@@ -124,6 +128,10 @@ class VMonitor
// VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long // VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long
void add( const std::string& name, const std::string& v ); void add( const std::string& name, const std::string& v );
const std::string pretty_str( const std::string& name, const std::string* v );
inline int getNameWidth(){ return nameWidth; }
inline void setNameWidth( int w ){ nameWidth = w; }
protected: protected:
...@@ -138,6 +146,8 @@ class VMonitor ...@@ -138,6 +146,8 @@ class VMonitor
VMON_DEF_MAP(double); VMON_DEF_MAP(double);
// VMON_DEF_MAP3(UniSetTypes::ObjectId,ObjectId); // <-- long // VMON_DEF_MAP3(UniSetTypes::ObjectId,ObjectId); // <-- long
VMON_DEF_MAP3(std::string,string); VMON_DEF_MAP3(std::string,string);
int nameWidth = { 30 };
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#endif #endif
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
#define VMON_IMPL_ADD(T) void VMonitor::add( const std::string& name, const T& v ) \ #define VMON_IMPL_ADD(T) void VMonitor::add( const std::string& name, const T& v ) \
{\ {\
m_##T.emplace(&v,name); \ m_##T.emplace(&v,name); \
} \
\
const std::string VMonitor::pretty_str( const std::string& name, const T* v ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_ADD2(T) \ #define VMON_IMPL_ADD2(T) \
...@@ -17,11 +24,29 @@ void VMonitor::add( const std::string& name, const T& v ) \ ...@@ -17,11 +24,29 @@ void VMonitor::add( const std::string& name, const T& v ) \
void VMonitor::add( const std::string& name, const unsigned T& v ) \ void VMonitor::add( const std::string& name, const unsigned T& v ) \
{\ {\
m_unsigned_##T.emplace(&v,name); \ m_unsigned_##T.emplace(&v,name); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T* v ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const unsigned T* v ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_ADD3(T,M) void VMonitor::add( const std::string& name, const T& v ) \ #define VMON_IMPL_ADD3(T,M) void VMonitor::add( const std::string& name, const T& v ) \
{\ {\
m_##M.emplace(&v,name); \ m_##M.emplace(&v,name); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T* v ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_PRN(M,T) \ #define VMON_IMPL_PRN(M,T) \
...@@ -51,25 +76,25 @@ void VMonitor::add( const std::string& name, const unsigned T& v ) \ ...@@ -51,25 +76,25 @@ void VMonitor::add( const std::string& name, const unsigned T& v ) \
#define VMON_IMPL_PRET(T) \ #define VMON_IMPL_PRET(T) \
{\ {\
for( const auto& e: m_##T ) \ for( const auto& e: m_##T ) \
os << std::right << std::setw(25) << e.second << std::left << " = " << std::right << std::setw(6) << *(e.first) << std::endl;\ os << pretty_str(e.second,e.first) << std::endl;\
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_PRET2(T) \ #define VMON_IMPL_PRET2(T) \
{\ {\
for( const auto& e: m_##T ) \ for( const auto& e: m_##T ) \
os << std::right << std::setw(25) << e.second << std::left << " = " << std::right << std::setw(6) << *(e.first) << std::endl;\ os << pretty_str(e.second,e.first) << std::endl;\
\ \
for( const auto& e: m_unsigned_##T ) \ for( const auto& e: m_unsigned_##T ) \
os << std::right << std::setw(25) << e.second << std::left << " = " << std::right << std::setw(6) << *(e.first) << std::endl;\ os << pretty_str(e.second,e.first) << std::endl;\
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_PRET_CHAR \ #define VMON_IMPL_PRET_CHAR \
{\ {\
for( const auto& e: m_char ) \ for( const auto& e: m_char ) \
os << std::right << std::setw(25) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\ os << std::right << std::setw(nameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\
\ \
for( const auto& e: m_unsigned_char ) \ for( const auto& e: m_unsigned_char ) \
os << std::right << std::setw(25) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\ os << std::right << std::setw(nameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
VMON_IMPL_ADD2(int) VMON_IMPL_ADD2(int)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment