diff --git a/fstrim.c b/fstrim.c index a9f5f0a..4911778 100644 --- a/fstrim.c +++ b/fstrim.c @@ -22,14 +22,34 @@ #include #include #include +#include #include #include #define LOG_TAG "fstrim" #include "cutils/log.h" #include "hardware_legacy/power.h" +/* These numbers must match what the MountService specified in + * frameworks/base/services/java/com/android/server/EventLogTags.logtags + */ +#define LOG_FSTRIM_START 2755 +#define LOG_FSTRIM_FINISH 2756 + #define FSTRIM_WAKELOCK "dofstrim" +static unsigned long long get_boot_time_ms(void) +{ + struct timespec t; + unsigned long long time_ms; + + t.tv_sec = 0; + t.tv_nsec = 0; + clock_gettime(CLOCK_BOOTTIME, &t); + time_ms = (t.tv_sec * 1000LL) + (t.tv_nsec / 1000000); + + return time_ms; +} + static void *do_fstrim_filesystems(void *ignored) { int i; @@ -41,6 +61,9 @@ static void *do_fstrim_filesystems(void *ignored) SLOGI("Starting fstrim work...\n"); + /* Log the start time in the event log */ + LOG_EVENT_LONG(LOG_FSTRIM_START, get_boot_time_ms()); + for (i = 0; i < fstab->num_entries; i++) { /* Skip raw partitions */ if (!strcmp(fstab->recs[i].fs_type, "emmc") || @@ -83,6 +106,10 @@ static void *do_fstrim_filesystems(void *ignored) SLOGI("Trimmed %llu bytes on %s\n", range.len, fstab->recs[i].mount_point); close(fd); } + + /* Log the finish time in the event log */ + LOG_EVENT_LONG(LOG_FSTRIM_FINISH, get_boot_time_ms()); + SLOGI("Finished fstrim work.\n"); /* Release the wakelock that let us work */