nat_linden avatar nat_linden committed e7d3ecb

CHOP-753: Add timestamp to LLMemoryInfo's LLSD stats block.
For postprocessing these stats, we'll want the time at which they were
captured. We'll want the current framerate too, but handle that at a higher
level.

Comments (0)

Files changed (1)

indra/llcommon/llsys.cpp

 #include <boost/foreach.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/range.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/type_traits/is_float.hpp>
 
 using namespace llsd;
 
 		mStats(LLSD::emptyArray())
 	{}
 
-	void add(const LLSD::String& name, LLSD::Integer value)
+	// Store every integer type as LLSD::Integer.
+	template <class T>
+	void add(const LLSD::String& name, const T& value,
+			 typename boost::enable_if<boost::is_integral<T> >::type* = 0)
+	{
+		mStats.append(LLSDArray(name)(LLSD::Integer(value)));
+	}
+
+	// Store every floating-point type as LLSD::Real.
+	template <class T>
+	void add(const LLSD::String& name, const T& value,
+			 typename boost::enable_if<boost::is_float<T> >::type* = 0)
+	{
+		mStats.append(LLSDArray(name)(LLSD::Real(value)));
+	}
+
+	// Hope that LLSD::Date values are sufficiently unambiguous.
+	void add(const LLSD::String& name, const LLSD::Date& value)
 	{
 		mStats.append(LLSDArray(name)(value));
 	}
 	// Now stream stats
 	BOOST_FOREACH(LLSD pair, inArray(mStatsArray))
 	{
-		s << pfx << std::setw(key_width+1) << (pair[0].asString() + ':')
-		  << ' '
-		  << std::setw(12) << pair[1].asInteger() << std::endl;
+		s << pfx << std::setw(key_width+1) << (pair[0].asString() + ':') << ' ';
+		if (pair[1].isInteger())
+			s << std::setw(12) << pair[1].asInteger();
+		else if (pair[1].isReal())
+			s << std::fixed << std::setprecision(1) << pair[1].asReal();
+		else if (pair[1].isDate())
+			pair[1].asDate().toStream(s);
+		else
+			s << pair[1];           // just use default LLSD formatting
+		s << std::endl;
 	}
 }
 
 	// This implementation is derived from stream() code (as of 2011-06-29).
 	StatsArray stats;
 
+	// associate timestamp for analysis over time
+	stats.add("timestamp", LLDate::now());
+
 #if LL_WINDOWS
 	MEMORYSTATUSEX state;
 	state.dwLength = sizeof(state);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.