mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(log): Adds new timestamp APIs and bootloader log Kconfigs
This commit is contained in:
@@ -4,64 +4,16 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_cpu.h" // for esp_cpu_get_cycle_count()
|
||||
#include "esp_compiler.h"
|
||||
#include "esp_private/log_util.h"
|
||||
#include "esp_private/log_lock.h"
|
||||
#include "esp_log_timestamp.h"
|
||||
|
||||
static inline bool is_early_log(void)
|
||||
{
|
||||
return xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED;
|
||||
}
|
||||
|
||||
char *esp_log_system_timestamp(void)
|
||||
{
|
||||
static char buffer[18] = {0};
|
||||
static _lock_t bufferLock = 0;
|
||||
|
||||
if (is_early_log()) {
|
||||
uint32_t timestamp = esp_log_early_timestamp();
|
||||
for (uint8_t i = 0; i < sizeof(buffer); i++) {
|
||||
if ((timestamp > 0) || (i == 0)) {
|
||||
for (uint8_t j = sizeof(buffer) - 1; j > 0; j--) {
|
||||
buffer[j] = buffer[j - 1];
|
||||
}
|
||||
buffer[0] = (char)(timestamp % 10) + '0';
|
||||
timestamp /= 10;
|
||||
} else {
|
||||
buffer[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
} else {
|
||||
struct timeval tv;
|
||||
struct tm timeinfo;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
localtime_r(&tv.tv_sec, &timeinfo);
|
||||
|
||||
_lock_acquire(&bufferLock);
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"%02d:%02d:%02d.%03ld",
|
||||
timeinfo.tm_hour,
|
||||
timeinfo.tm_min,
|
||||
timeinfo.tm_sec,
|
||||
tv.tv_usec / 1000);
|
||||
_lock_release(&bufferLock);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
#include "sdkconfig.h"
|
||||
|
||||
uint32_t esp_log_timestamp(void)
|
||||
{
|
||||
if (unlikely(is_early_log())) {
|
||||
if (unlikely(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED)) {
|
||||
return esp_log_early_timestamp();
|
||||
}
|
||||
static uint32_t base = 0;
|
||||
|
||||
Reference in New Issue
Block a user