Skip to content

Commit ef5ae34

Browse files
committed
Add simple storage analyser app, fix espruino/EspruinoAppLoaderCore#68
1 parent 6f309a8 commit ef5ae34

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

apps/storageanalyzer/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App!

apps/storageanalyzer/app.png

1.7 KB
Loading

apps/storageanalyzer/custom.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" href="../../css/spectre.min.css">
4+
</head>
5+
<body>
6+
7+
<script src="../../core/lib/customize.js"></script>
8+
<div id="storageInfo"></div>
9+
10+
<script>
11+
// Called when we know what device we're using
12+
function onInit(device) {
13+
Util.showModal("Reading Storage...");
14+
Puck.eval(`require("Storage").list(/\\.info$/).map(appInfoName => {
15+
let appInfo = require("Storage").readJSON(appInfoName,1)||{};
16+
//print(appInfoName, appInfo);
17+
var fileSize = 0, dataSize = 0;
18+
appInfo.files.split(",").forEach(f => fileSize += require("Storage").read(f).length);
19+
var data = (appInfo.data||"").split(";");
20+
function wildcardToRegexp(wc) {
21+
return new RegExp("^"+wc.replaceAll(".","\\\\.").replaceAll("?",".*")+"$");
22+
}
23+
// normal files
24+
if (data[0]) data[0].split(",").forEach(wc => {
25+
require("Storage").list(wildcardToRegexp(wc), {sf:false}).forEach(f => {
26+
dataSize += require("Storage").read(f).length
27+
});
28+
});
29+
// storage files
30+
if (data[1]) data[1].split(",").forEach(wc => {
31+
require("Storage").list(wildcardToRegexp(wc), {sf:true}).forEach(f => {
32+
dataSize += require("Storage").open(f,"r").getLength();
33+
});
34+
});
35+
return [appInfo.id, fileSize, dataSize];
36+
})`, function(apps) {
37+
apps.sort((a,b) => (b[1]+b[2]) - (a[1]+a[2]));
38+
Util.hideModal();
39+
console.log(apps);
40+
document.getElementById("storageInfo").innerHTML = `
41+
<table class="table table-striped">
42+
<thead>
43+
<tr>
44+
<th>App</th>
45+
<th>Code (kb)</th>
46+
<th>Data (kb)</th>
47+
<th>Total (kb)</th>
48+
</tr>
49+
</thead>
50+
<tbody>
51+
${apps.map(app => `
52+
<tr>
53+
<td>${app[0]}</td>
54+
<td>${(app[1]/1000).toFixed(1)}</td>
55+
<td>${(app[2]/1000).toFixed(1)}</td>
56+
<td>${((app[1]+app[2])/1000).toFixed(1)}</td>
57+
</tr>`).join("")}
58+
</tbody>
59+
</table>`;
60+
if (apps.length === 0) {
61+
document.getElementById("storageInfo").innerHTML = "<p>No apps found</p>";
62+
}
63+
});
64+
}
65+
66+
67+
</script>
68+
</body>
69+
</html>

apps/storageanalyzer/metadata.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "storageanalyzer",
3+
"name": "Storage Analyzer",
4+
"version": "0.01",
5+
"description": "Analyses Bangle.js storage and shows which apps are using it",
6+
"icon": "app.png",
7+
"type": "RAM",
8+
"tags": "tool,storage,flash,memory",
9+
"supports": ["BANGLEJS","BANGLEJS2"],
10+
"custom": "custom.html",
11+
"customConnect": true,
12+
"storage": []
13+
}

0 commit comments

Comments
 (0)