From d5f97699bc3f52a41d93f0ee50b4e4549d696e08 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Thu, 5 Jul 2018 15:08:48 -0400 Subject: [PATCH] cleanup / reorganize --- app.js | 25 ++----------------------- app/utils.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 6035506..14790df 100755 --- a/app.js +++ b/app.js @@ -85,27 +85,6 @@ function refreshExchangeRate() { } } -var firstCall = true; -function trackMemoryUsage() { - var mbUsed = process.memoryUsage().heapUsed / 1024 / 1024; - mbUsed = Math.round(mbUsed * 100) / 100; - - var mbTotal = process.memoryUsage().heapTotal / 1024 / 1024; - mbTotal = Math.round(mbTotal * 100) / 100; - - var stream = fs.createWriteStream("memoryUsage.csv", {flags:'a'}); - - if (firstCall) { - stream.write("App starting up.\n"); - } - - stream.write(mbUsed + "\n"); - - stream.end(); - - firstCall = false; -} - app.runOnStartup = function() { @@ -198,8 +177,8 @@ app.runOnStartup = function() { // refresh exchange rate periodically setInterval(refreshExchangeRate, 1800000); - trackMemoryUsage(); - setInterval(trackMemoryUsage, 5000); + utils.logMemoryUsage(); + setInterval(utils.logMemoryUsage, 5000); }; app.use(function(req, res, next) { diff --git a/app/utils.js b/app/utils.js index 0017df0..44972f0 100644 --- a/app/utils.js +++ b/app/utils.js @@ -150,6 +150,16 @@ function seededRandomIntBetween(seed, min, max) { return (min + (max - min) * rand); } +function logMemoryUsage() { + var mbUsed = process.memoryUsage().heapUsed / 1024 / 1024; + mbUsed = Math.round(mbUsed * 100) / 100; + + var mbTotal = process.memoryUsage().heapTotal / 1024 / 1024; + mbTotal = Math.round(mbTotal * 100) / 100; + + console.log("memoryUsage: heapUsed=" + mbUsed + ", heapTotal=" + mbTotal + ", ratio=" + parseInt(mbUsed / mbTotal * 100)); +} + function getMinerFromCoinbaseTx(tx) { if (tx == null || tx.vin == null || tx.vin.length == 0) { return null; @@ -208,6 +218,7 @@ module.exports = { formatCurrencyAmountInSmallestUnits: formatCurrencyAmountInSmallestUnits, seededRandom: seededRandom, seededRandomIntBetween: seededRandomIntBetween, + logMemoryUsage: logMemoryUsage, getMinerFromCoinbaseTx: getMinerFromCoinbaseTx, getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight };