Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions site/source/docs/porting/files/packaging_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ Monitoring file usage

.. important:: Only package the files your app actually needs, in order to reduce download size and improve startup speed.

There is an option to log which files are actually used at runtime. To use it, define the :js:attr:`Module.logReadFiles` object. Each file that is read will be logged to stderr.

An alternative approach is to look at :js:func:`FS.readFiles` in your compiled JavaScript. This is an object with keys for all the files that were read from. You may find it easier to use than logging as it records files rather than potentially multiple file accesses.
There is an option to log which files are actually used at runtime. To use it,
define the :js:attr:`Module.logReadFiles` object. Each file that is read will be
logged to stderr. This options requires that :ref:`FS_DEBUG` is set.

An alternative approach is to look at :js:func:`FS.readFiles` in your compiled
JavaScript. This is an object with keys for all the files that were read from.
You may find it easier to use than logging as it records files rather than
potentially multiple file accesses.

.. note:: You can also modify the :js:func:`FS.readFiles` object or remove it entirely. This can be useful, say, in order to see which files are read between two points in time in your app.

Expand Down
14 changes: 4 additions & 10 deletions src/lib/libfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ FS.staticInit();`;
ignorePermissions: true,
#if FS_DEBUG
trackingDelegate: {},
readFiles: {},
#endif
filesystems: null,
syncFSRequests: 0, // we warn if there are multiple in flight at once
#if expectToReceiveOnModule('logReadFiles')
readFiles: {},
#endif
#if ASSERTIONS
ErrnoError: class extends Error {
#else
Expand Down Expand Up @@ -1160,17 +1158,13 @@ FS.staticInit();`;
if (created) {
FS.chmod(node, mode & 0o777);
}
#if expectToReceiveOnModule('logReadFiles')
#if FS_DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR changing the requirement of FS_DEBUG, or just documenting it? From the description I thought the latter, but the code seems to actually add it..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message was already wrapped in FS_DEBUG yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe there was some confusion about how this feature worked. See #7418, where the log message was changed.

The log message is the feature really. Since it was already wrapped in FS_DEBUG I think its best to document that. I seems reasonable to run in FS_DEBUG mode if want to get a list of opened files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the log there is old line 1166 though, FS.readFiles[path] = 1? I think users might have just used that, without the logging?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps? Seems like we should probably keeps this as just one feature though. Bifurcating it further seems like complexity we don't need. Putting the whole feature behind FS_DEBUG seems like the most sensible thing to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I think I disagree. IIUC, the point of the feature is to be able to read FS.readFiles to see which files were actually read. FS_DEBUG, otoh, is entirely a debug feature to add verbose logging? So I can definitely see how you might want one and not the other. This feature just happens to also have FS_DEBUG in it, to add verbose logging, but that's incidental.

With that said I'm not opposed to changing this feature - and maybe it isn't even used by anyone at this point. But perhaps we should ask on the mailing list first, before changing or removing it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs the logging on the file is the main way the feature works:

There is an option to log which files are actually used at runtime. To use it, define the :js:attr:`Module.logReadFiles` object. Each file that is read will be logged to stderr.

The option is called logReadFiles because it logs to the console.

The fact that you can also read FS.readFiles true, and but more of secordary usage, at least according to the docs:

An alternative approach is to look at :js:func:`FS.readFiles` in your compiled
JavaScript. This is an object with keys for all the files that were read from.
You may find it easier to use than logging as it records files rather than
potentially multiple file accesses.

Basically when you enable logReadFiles you get two options for how to extract the list of files, right?

Being able to turn them on and off individually seems pretty overkill.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I opened a much smaller PR instead: #26189

if (Module['logReadFiles'] && !(flags & {{{ cDefs.O_WRONLY}}})) {
if (!(path in FS.readFiles)) {
if (!FS.readFiles[path]) {
FS.readFiles[path] = 1;
#if FS_DEBUG
dbg(`FS.trackingDelegate error on read file: ${path}`);
#endif
dbg(`FS: read file: ${path}`);
}
}
#endif
#if FS_DEBUG
FS.trackingDelegate['onOpenFile']?.(path, origFlags);
#endif
return stream;
Expand Down
2 changes: 1 addition & 1 deletion src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ var INCOMING_MODULE_JS_API = [
'buffer', 'canvas', 'doNotCaptureKeyboard', 'dynamicLibraries',
'elementPointerLock', 'extraStackTrace', 'forcedAspectRatio',
'instantiateWasm', 'keyboardListeningElement', 'freePreloadedMediaOnUse',
'loadSplitModule', 'locateFile', 'logReadFiles', 'mainScriptUrlOrBlob', 'mem',
'loadSplitModule', 'locateFile', 'mainScriptUrlOrBlob', 'mem',
'monitorRunDependencies', 'noExitRuntime', 'noInitialRun', 'onAbort',
'onExit', 'onFree', 'onFullScreen', 'onMalloc',
'onRealloc', 'onRuntimeInitialized', 'postMainLoop', 'postRun', 'preInit',
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19664,
"a.out.js.gz": 8146,
"a.out.js": 19618,
"a.out.js.gz": 8116,
"a.out.nodebug.wasm": 132844,
"a.out.nodebug.wasm.gz": 49884,
"total": 152508,
"total_gz": 58030,
"total": 152462,
"total_gz": 58000,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19641,
"a.out.js.gz": 8133,
"a.out.js": 19595,
"a.out.js.gz": 8102,
"a.out.nodebug.wasm": 132264,
"a.out.nodebug.wasm.gz": 49542,
"total": 151905,
"total_gz": 57675,
"total": 151859,
"total_gz": 57644,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23325,
"a.out.js.gz": 9127,
"a.out.js": 23279,
"a.out.js.gz": 9095,
"a.out.nodebug.wasm": 172774,
"a.out.nodebug.wasm.gz": 57405,
"total": 196099,
"total_gz": 66532,
"total": 196053,
"total_gz": 66500,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19475,
"a.out.js.gz": 8072,
"a.out.js": 19429,
"a.out.js.gz": 8043,
"a.out.nodebug.wasm": 148169,
"a.out.nodebug.wasm.gz": 55285,
"total": 167644,
"total_gz": 63357,
"total": 167598,
"total_gz": 63328,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm_legacy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19549,
"a.out.js.gz": 8091,
"a.out.js": 19503,
"a.out.js.gz": 8063,
"a.out.nodebug.wasm": 145975,
"a.out.nodebug.wasm.gz": 54915,
"total": 165524,
"total_gz": 63006,
"total": 165478,
"total_gz": 62978,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_lto.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19011,
"a.out.js.gz": 7826,
"a.out.js": 18965,
"a.out.js.gz": 7802,
"a.out.nodebug.wasm": 102076,
"a.out.nodebug.wasm.gz": 39428,
"total": 121087,
"total_gz": 47254,
"total": 121041,
"total_gz": 47230,
"sent": [
"a (emscripten_resize_heap)",
"b (_setitimer_js)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23375,
"a.out.js.gz": 9147,
"a.out.js": 23329,
"a.out.js.gz": 9118,
"a.out.nodebug.wasm": 239224,
"a.out.nodebug.wasm.gz": 79795,
"total": 262599,
"total_gz": 88942,
"total": 262553,
"total_gz": 88913,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_noexcept.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19664,
"a.out.js.gz": 8146,
"a.out.js": 19618,
"a.out.js.gz": 8116,
"a.out.nodebug.wasm": 134851,
"a.out.nodebug.wasm.gz": 50712,
"total": 154515,
"total_gz": 58858,
"total": 154469,
"total_gz": 58828,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_files_js_fs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18283,
"a.out.js.gz": 7464,
"a.out.js": 18237,
"a.out.js.gz": 7441,
"a.out.nodebug.wasm": 381,
"a.out.nodebug.wasm.gz": 260,
"total": 18664,
"total_gz": 7724,
"total": 18618,
"total_gz": 7701,
"sent": [
"a (fd_write)",
"b (fd_read)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 24225,
"a.out.js.gz": 8703,
"a.out.js": 24212,
"a.out.js.gz": 8700,
"a.out.nodebug.wasm": 15138,
"a.out.nodebug.wasm.gz": 7455,
"total": 39363,
"total_gz": 16158,
"total": 39350,
"total_gz": 16155,
"sent": [
"fd_write"
],
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_dylink.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 26705,
"a.out.js.gz": 11396,
"a.out.js": 26659,
"a.out.js.gz": 11369,
"a.out.nodebug.wasm": 17730,
"a.out.nodebug.wasm.gz": 8957,
"total": 44435,
"total_gz": 20353,
"total": 44389,
"total_gz": 20326,
"sent": [
"__syscall_stat64",
"emscripten_resize_heap",
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 244882,
"a.out.js": 244832,
"a.out.nodebug.wasm": 577863,
"total": 822745,
"total": 822695,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
1 change: 0 additions & 1 deletion test/codesize/test_codesize_minimal_O0.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,6 @@ function checkIncomingModuleAPI() {
ignoredModuleProp('freePreloadedMediaOnUse');
ignoredModuleProp('loadSplitModule');
ignoredModuleProp('locateFile');
ignoredModuleProp('logReadFiles');
ignoredModuleProp('mainScriptUrlOrBlob');
ignoredModuleProp('mem');
ignoredModuleProp('monitorRunDependencies');
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_minimal_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19498,
"a.out.js.gz": 7013,
"a.out.js": 19479,
"a.out.js.gz": 7006,
"a.out.nodebug.wasm": 1136,
"a.out.nodebug.wasm.gz": 656,
"total": 20634,
"total_gz": 7669,
"total": 20615,
"total_gz": 7662,
"sent": [],
"imports": [],
"exports": [
Expand Down
12 changes: 6 additions & 6 deletions test/codesize/test_unoptimized_code_size.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"hello_world.js": 56906,
"hello_world.js.gz": 17709,
"hello_world.js": 56888,
"hello_world.js.gz": 17706,
"hello_world.wasm": 15138,
"hello_world.wasm.gz": 7455,
"no_asserts.js": 26576,
"no_asserts.js.gz": 8881,
"no_asserts.wasm": 12187,
"no_asserts.wasm.gz": 5984,
"strict.js": 54881,
"strict.js.gz": 17045,
"strict.js": 54844,
"strict.js.gz": 17038,
"strict.wasm": 15138,
"strict.wasm.gz": 7450,
"total": 180826,
"total_gz": 64524
"total": 180771,
"total_gz": 64514
}