Replies: 2 comments 3 replies
-
Adding a flush/sync method seems reasonable. It wouldn't be supported everywhere though, so there's some thought to avoid misleading developers. Another approach could be to build the sync into write. The write call already accepts a list of items to write. One of those could be a signal to flush. file.write("one two three", file.flush);
|
Beta Was this translation helpful? Give feedback.
-
Another performance update:
(Some clarification about system impact: moving the data logger to a worker reduces the worst case impact of consecutive expensive flash operations on the main VM. However, when a flash block erase happens the entire CPU is essentially halted 'cause the flash chip is busy and the CPU can't fetch instructions. Digging further, the esp32-c3 has a way to suspend an erase operation for instruction fetch but it apparently lengthens the erase time and is only enabled for high priority freertos tasks, i.e., it's only usable for occasional high priority interrupts whose code doesn't fit into ram). Logging to flash is tricky... I wonder whether I should just make a minimal PCB module with an esp32-c3 dedicated to nothing but logging... |
Beta Was this translation helpful? Give feedback.
-
I'm putting together a little data logger class that uses files on an esp32 to save log records. I'm using LittleFS. One issue I'm encountering is that LittleFS only updates the filesystem data structures when sync() or close() is called. In a logging context the natural thing to do is to keep the file open and periodically perform a write. This means that a spontaneous reset causes all logged data to be lost (I tested this).
The moddable File class does not export a sync() method, which means the only option is closing and reopening, which isn't terribly attractive (but I haven't tested the actual overhead). I'm thinking about adding a sync() method to File but am wondering whether I'm overlooking something...
Update: I just tested closing and reopening. It's a no-go. Here are some performance stats using an esp32-c3 with built-in flash:
Update 2: for completeness, the note about committing to flash can be found in the Usage section of the LittleFS readme:
Beta Was this translation helpful? Give feedback.
All reactions