Skip to main content

Event Timestamps

By default, events (Reboot Reasons, Trace Events, and Heartbeat Metrics) are timestamped at the time of upload to Memfault ("received time"). This works well for frequently-connected devices, but for devices that batch-upload many heartbeats at once, the data points may end up tightly clustered in the Device Timeline view.

For fleet-level aggregate values ("Percent State-of-Charge Drop per Hour") the timestamping has no impact. Accurate timestamps can be helpful to correlate Trace or Reboot events with metric values on an individual Device Timeline.

Devices can implement the memfault_platform_time_get_current() platform API, which records a Unix timestamp at the time the data is captured on device ("captured time").

note

Only systems that maintain a notion of time, for example using a Real Time Clock or synced from a GPS or mobile phone, should implement this API. Memfault will not correct out-of-sync timestamps, for example when a Real Time Clock has not been initialized. In that case, be sure to return false from memfault_platform_time_get_current() if there's any uncertainty about the device time quality. Otherwise, your UNIX time will be set to 0.

Timestamps received by Memfault outside of a plausible range (defined as a maximum of 365 days in the past to 5 minutes in the future) will be ignored, and a processing log warning will be logged. In this case the received time will be used instead.

See the header file here for details:

https://github.com/memfault/memfault-firmware-sdk/blob/master/components/include/memfault/core/platform/system_time.h

An example implementation for a system that uses a C standard time API:

#include <time.h>
bool memfault_platform_time_get_current(sMemfaultCurrentTime *thistime) {
// fetch the current unix timestamp in seconds
time_t timestamp = time(NULL);
// if it's less than January 1 2000, return false; time hasn't been
// initialized
if (timestamp < 946702800){
return false;
}

// load the timestamp and return true for a valid timestamp
*thistime = (sMemfaultCurrentTime){
.type = kMemfaultCurrentTimeType_UnixEpochTimeSec,
.info = {
.unix_timestamp_secs = (uint64_t)timestamp,
},
};
return true
}

Zephyr RTOS

The Memfault SDK provides a built-in implementation of memfault_platform_time_get_current() for Zephyr/nRF-Connect SDK projects. To use it, enable the appropriate Kconfig option:

# For Zephyr projects with an RTC:
CONFIG_MEMFAULT_SYSTEM_TIME_SOURCE_RTC=y

# For nRF-Connect SDK projects that use the Nordic Date-Time library (i.e.
# nrf9160 devices):
CONFIG_MEMFAULT_SYSTEM_TIME_SOURCE_DATETIME=y