Skip to content

Commit

Permalink
Merge pull request #138 from code-mancers/cleanup-state-on-disconnect
Browse files Browse the repository at this point in the history
Cleanup state on disconnect
  • Loading branch information
iffyuva committed Jan 9, 2015
2 parents d416b6b + 5165ddf commit efaaf06
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 94 deletions.
29 changes: 25 additions & 4 deletions rbkit-charts/examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ var heapRandomData = function () {
};
};

var heapTimeout;
var heapCharts = function() {
setTimeout(heapCharts, 1000);
heapTimeout = setTimeout(heapCharts, 1000);

Rbkit.updateLiveObjectsChart(heapRandomData());
Rbkit.updateHeapChart(heapRandomData());
Expand All @@ -32,14 +33,16 @@ heapCharts();
// =============================== code for gc charts ==============================
// assuming max gc time is 10s

var gcStartTimeout;
var gcChartStart = function () {
setTimeout(gcChartEnd, _.random(0, 10) * 1000);
gcStartTimeout = setTimeout(gcChartEnd, _.random(0, 10) * 1000);

Rbkit.gcStarted(new Date());
};

var gcEndTimeout;
var gcChartEnd = function () {
setTimeout(gcChartStart, 5000);
gcEndTimeout = setTimeout(gcChartStart, 5000);

Rbkit.gcEnded(new Date());
};
Expand Down Expand Up @@ -108,10 +111,28 @@ var gcRandomStats = function () {
};
};

var gcStatsTimeout;
var gcStatsTable = function () {
setTimeout(gcStatsTable, 5000);
gcStatsTimeout = setTimeout(gcStatsTable, 5000);

Rbkit.updateGcStats(gcRandomStats());
};

gcStatsTable();

var reset = function() {
clearTimeout(heapTimeout);
clearTimeout(gcEndTimeout);
clearTimeout(gcStartTimeout);
clearTimeout(gcStatsTimeout);

Rbkit.reset();

setTimeout(function() {
heapCharts();
gcChartStart();
gcStatsTable();
}, 2000);
};

document.getElementById("reset").addEventListener("click", reset);
3 changes: 3 additions & 0 deletions rbkit-charts/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ <h4> GC Stats </h4>
<canvas id='generation-three' width='250' height='250'></canvas>
</div>

<div>
<button id="reset">Reset</button>
</div>
</div>

<script src='../vendor/chart.js'></script>
Expand Down
14 changes: 13 additions & 1 deletion rbkit-charts/src/rbcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ var Rbkit = {
// function to record gc end time
gcEnded: function (timestamp) {
if (!this.gcStartTime) {
console.info("not sure why gc start time is not set");
return;
}

Expand Down Expand Up @@ -155,6 +154,11 @@ var Rbkit = {
},

updateGcStats: function (gcStats) {
if (Object.keys(gcStats).length === 0) {
document.getElementById('gc-stats-table').lastElementChild.innerHTML = '';
return;
}

var gcStatsKeys = Object.keys(this.gcStatsImportantFields);
for (var iter = 0; iter != gcStatsKeys.length; ++iter) {
var token = gcStatsKeys[iter];
Expand Down Expand Up @@ -231,6 +235,7 @@ var Rbkit = {
insertLegend: function (chart, canvasDiv) {
var chartLegend = chart.generateLegend();
var node = this.stringToNode(chartLegend);
canvasDiv.parentNode.lastChild.remove();
canvasDiv.parentNode.appendChild(node);
},

Expand Down Expand Up @@ -300,7 +305,14 @@ var Rbkit = {
this.updateLiveObjectsChart(data.payload);
this.updateHeapChart(data.payload);
break;
case "disconnected":
this.reset();
break;
}
},

reset: function() {
location.reload();
}
};

Expand Down
Loading

0 comments on commit efaaf06

Please sign in to comment.