Skip to content

Commit

Permalink
doc: move trace-gc doc to script
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-go committed Aug 16, 2022
1 parent c983dad commit afb5bb6
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 1,035 deletions.
1 change: 0 additions & 1 deletion documentation/memory/step3/exercice/.gitignore

This file was deleted.

835 changes: 0 additions & 835 deletions documentation/memory/step3/exercice/package-lock.json

This file was deleted.

23 changes: 0 additions & 23 deletions documentation/memory/step3/exercice/package.json

This file was deleted.

34 changes: 34 additions & 0 deletions documentation/memory/step3/exercice/script-fix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os from 'os';
import fs from 'fs/promises';

let len = 1_000_000;
const fileName = `entries-${Date.now()}`;

async function addEntry () {
const entry = {
timestamp: Date.now(),
memory: os.freemem(),
totalMemory: os.totalmem(),
uptime: os.uptime(),
};

await fs.appendFile(fileName, JSON.stringify(entry) + '\n');
}

async function summary () {
const stats = await fs.lstat(fileName);
console.log(`File size: ${stats.size} bytes! \n`);
}

// execution
(async () => {
await fs.writeFile(fileName, "----START---\n");
while (len > 0) {
await addEntry();
process.stdout.write(`~~> ${len} entries to record\r`);
len--;
};

await summary();
})();

45 changes: 0 additions & 45 deletions documentation/memory/step3/exercice/script.js

This file was deleted.

31 changes: 31 additions & 0 deletions documentation/memory/step3/exercice/script.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os from 'os';

let len = 1_000_000;
const entries = new Set();

function addEntry () {
const entry = {
timestamp: Date.now(),
memory: os.freemem(),
totalMemory: os.totalmem(),
uptime: os.uptime(),
};

entries.add(entry);
}

function summary () {
console.log(`Total: ${entries.size} entries`);
}

// execution
(() => {
while (len > 0) {
addEntry();
process.stdout.write(`~~> ${len} entries to record\r`);
len--;
};

summary();
})();

52 changes: 0 additions & 52 deletions documentation/memory/step3/exercice/server.js

This file was deleted.

Loading

0 comments on commit afb5bb6

Please sign in to comment.