mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 20:39:08 -06:00
Enable real time monitoring of StatsCollector data
This commit is contained in:
@@ -68,7 +68,7 @@ namespace openspace {
|
||||
, maxSplitDepth(22)
|
||||
, _savedCamera(nullptr)
|
||||
, _tileProviderManager(tileProviderManager)
|
||||
, stats(StatsCollector(absPath("test_stats")))
|
||||
, stats(StatsCollector(absPath("test_stats"), 1))
|
||||
{
|
||||
|
||||
auto geometry = std::make_shared<SkirtedGrid>(
|
||||
|
||||
@@ -89,8 +89,13 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
// copy last, i.e. current record
|
||||
StatsRecord<T> lastRecord = _data.back();
|
||||
_data.clear();
|
||||
// add it again after cleared the vector
|
||||
_data.push_back(lastRecord);
|
||||
_writePos = 0;
|
||||
|
||||
}
|
||||
|
||||
void writeHeader(std::ostream& os) {
|
||||
@@ -137,11 +142,13 @@ namespace openspace {
|
||||
|
||||
StatsCollector() = delete;
|
||||
|
||||
StatsCollector(const std::string& filename, const std::string& delimiter = ",", bool enabled = true)
|
||||
StatsCollector(const std::string& filename, int dumpEveryXRecord, const std::string& delimiter = ",", bool enabled = true)
|
||||
: _filename(filename)
|
||||
, _dumpEveryXRecord(dumpEveryXRecord)
|
||||
, _recordsSinceLastDump(0)
|
||||
, _enabled(enabled)
|
||||
, _delimiter(delimiter)
|
||||
, _hasWrittenHead(false)
|
||||
, _hasWrittenHeader(false)
|
||||
, i(TemplatedStatsCollector<int>(_enabled, delimiter))
|
||||
, d(TemplatedStatsCollector<double>(_enabled, delimiter))
|
||||
{
|
||||
@@ -154,6 +161,11 @@ namespace openspace {
|
||||
|
||||
void startNewRecord() {
|
||||
if (_enabled) {
|
||||
if (_dumpEveryXRecord && ++_recordsSinceLastDump >= _dumpEveryXRecord) {
|
||||
dumpToDisk();
|
||||
_recordsSinceLastDump = 0;
|
||||
}
|
||||
|
||||
i.startNewRecord();
|
||||
d.startNewRecord();
|
||||
}
|
||||
@@ -167,18 +179,24 @@ namespace openspace {
|
||||
_enabled = true;
|
||||
}
|
||||
|
||||
int hasHeaders() {
|
||||
return i.hasHeaders() || d.hasHeaders();
|
||||
}
|
||||
|
||||
void dumpToDisk() {
|
||||
if (!_hasWrittenHead) {
|
||||
writeHead();
|
||||
if (_enabled && hasHeaders()) {
|
||||
if (!_hasWrittenHeader) {
|
||||
writeHeader();
|
||||
}
|
||||
writeData();
|
||||
}
|
||||
writeData();
|
||||
}
|
||||
|
||||
TemplatedStatsCollector<int> i;
|
||||
TemplatedStatsCollector<double> d;
|
||||
|
||||
private:
|
||||
void writeHead() {
|
||||
void writeHeader() {
|
||||
std::ofstream ofs(_filename);
|
||||
if (i.hasHeaders()) {
|
||||
i.writeHeader(ofs);
|
||||
@@ -190,6 +208,7 @@ namespace openspace {
|
||||
else {
|
||||
d.writeHeader(ofs);
|
||||
}
|
||||
_hasWrittenHeader = true;
|
||||
ofs << std::endl;
|
||||
ofs.close();
|
||||
}
|
||||
@@ -211,8 +230,12 @@ namespace openspace {
|
||||
|
||||
std::string _filename;
|
||||
std::string _delimiter;
|
||||
|
||||
int _dumpEveryXRecord;
|
||||
int _recordsSinceLastDump;
|
||||
|
||||
bool _enabled;
|
||||
bool _hasWrittenHead;
|
||||
bool _hasWrittenHeader;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -6,11 +6,27 @@
|
||||
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="start-stop" onclick="startStop()">Start / Stop</button>
|
||||
<svg></svg>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var updateInterval = undefined;
|
||||
|
||||
function startStop(){
|
||||
if(updateInterval === undefined){
|
||||
console.log("Start updating");
|
||||
updateInterval = setInterval(doVis, 1000);
|
||||
doVis(); // Do one immediately
|
||||
}
|
||||
else{
|
||||
console.log("Stop updating");
|
||||
clearInterval(updateInterval);
|
||||
updateInterval = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function doVis(){
|
||||
var filename = "../data/scene/debugglobe/test_stats";
|
||||
|
||||
@@ -107,7 +123,6 @@ function doVis(){
|
||||
});
|
||||
}
|
||||
doVis();
|
||||
//setInterval(doVis, 1000);
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ body {
|
||||
font: 10px sans-serif;
|
||||
}
|
||||
|
||||
#start-stop{
|
||||
display: block;
|
||||
}
|
||||
|
||||
.axis path,
|
||||
.axis line {
|
||||
fill: none;
|
||||
|
||||
Reference in New Issue
Block a user