mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 14:23:36 +08:00
feat(logger): add support for small flash storage
Move log cleanup from boot to log start, delete individual .ulg files
(oldest first) instead of entire directories, and add a max log file
size. This makes it practical to run the logger on small flash targets
(e.g. 128 MB W25N NAND) while still allowing logs to be downloaded via
MAVLink FTP before they are removed.
- Move cleanup from boot to log start so logs can be downloaded first.
- Delete individual .ulg files (oldest first) instead of whole dirs.
- Add SDLOG_MAX_SIZE parameter (default 4095 MiB, just under FAT32 limit).
- Prioritize directories from the naming scheme not currently in use
(e.g. delete sess dirs first when using date dirs).
- Simplify get_log_time to rely on clock_gettime (GPS driver sets it).
- Safer string handling in directory parsing.
- Log elapsed cleanup time for diagnostics.
- Split pure parsing helpers into util_parse.{h,cpp} and add unit tests
(loggerUtilTest.cpp). Move px4_add_unit_gtest outside the BUILD_TESTING
guard for consistency with the rest of the tree; the macro already
checks BUILD_TESTING internally.
Sponsored by CubePilot.
This commit is contained in:
@@ -83,6 +83,27 @@ This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz,
|
||||
|
||||
There are several scripts to analyze and convert logging files in the [pyulog](https://github.com/PX4/pyulog) repository.
|
||||
|
||||
## Log Cleanup
|
||||
|
||||
PX4 automatically manages log storage by cleaning up old logs when starting to log.
|
||||
Cleanup is triggered based on two criteria:
|
||||
|
||||
- **Storage-based cleanup**: Ensures minimum free space (300 MB or 10% of disk, whichever is smaller) is available.
|
||||
- **Count-based cleanup**: If [SDLOG_DIRS_MAX](../advanced_config/parameter_reference.md#SDLOG_DIRS_MAX) is set, limits the total number of log directories.
|
||||
|
||||
The cleanup algorithm prioritizes deleting logs from the directory naming scheme not currently in use.
|
||||
PX4 uses two directory naming schemes:
|
||||
|
||||
- **Session directories** (`sess001`, `sess002`, etc.) - used when the system doesn't have valid time information
|
||||
- **Date directories** (`2024-01-15`, `2024-01-16`, etc.) - used when the system has valid time (e.g., from GPS)
|
||||
|
||||
When cleanup is needed:
|
||||
|
||||
- If the system has valid time (using date directories): old session directories are deleted first
|
||||
- If the system doesn't have valid time (using session directories): old date directories are deleted first
|
||||
|
||||
This ensures that stale logs from a different time mode are cleaned up before current logs.
|
||||
|
||||
## File size limitations
|
||||
|
||||
The maximum file size depends on the file system and OS.
|
||||
|
||||
Reference in New Issue
Block a user