mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
uart.mitm: Implemented btsnoop timestamp handling.
This commit is contained in:
parent
1dd9d46415
commit
296fb31358
4 changed files with 25 additions and 9 deletions
|
@ -138,7 +138,7 @@ namespace ams::mitm::uart {
|
|||
void UartLogger::FlushCache() {
|
||||
for (size_t i=0; i<this->m_cache_count; i++) {
|
||||
UartLogMessage *cache_msg=&this->m_cache_list[i];
|
||||
this->WriteLogPacket(cache_msg->datalog_file, cache_msg->file_pos, cache_msg->dir, cache_msg->data, cache_msg->size);
|
||||
this->WriteLogPacket(cache_msg->datalog_file, cache_msg->file_pos, cache_msg->timestamp, cache_msg->dir, cache_msg->data, cache_msg->size);
|
||||
}
|
||||
|
||||
this->m_cache_count = 0;
|
||||
|
@ -184,7 +184,7 @@ namespace ams::mitm::uart {
|
|||
|
||||
/* Append the specified packet to the datalog via WriteLog. */
|
||||
/* dir: false = Send (host->controller), true = Receive (controller->host). */
|
||||
void UartLogger::WriteLogPacket(FsFile *f, size_t *datalog_pos, bool dir, const void* buffer, size_t size) {
|
||||
void UartLogger::WriteLogPacket(FsFile *f, size_t *datalog_pos, s64 timestamp, bool dir, const void* buffer, size_t size) {
|
||||
struct {
|
||||
u32 original_length;
|
||||
u32 included_length;
|
||||
|
@ -200,8 +200,7 @@ namespace ams::mitm::uart {
|
|||
ams::util::StoreBigEndian(&pkt_hdr.original_length, static_cast<u32>(size));
|
||||
ams::util::StoreBigEndian(&pkt_hdr.included_length, static_cast<u32>(size));
|
||||
ams::util::StoreBigEndian(&pkt_hdr.packet_flags, flags);
|
||||
|
||||
/* Currently we leave the timestamp at value 0. */
|
||||
ams::util::StoreBigEndian(&pkt_hdr.timestamp_microseconds, timestamp);
|
||||
|
||||
this->WriteLog(f, datalog_pos, &pkt_hdr, sizeof(pkt_hdr));
|
||||
this->WriteLog(f, datalog_pos, buffer, size);
|
||||
|
@ -209,7 +208,7 @@ namespace ams::mitm::uart {
|
|||
|
||||
/* Send the specified data to the Logger thread. */
|
||||
/* dir: false = Send (host->controller), true = Receive (controller->host). */
|
||||
void UartLogger::SendLogData(FsFile *f, size_t *file_pos, bool dir, const void* buffer, size_t size) {
|
||||
void UartLogger::SendLogData(FsFile *f, size_t *file_pos, s64 timestamp_base, s64 tick_base, bool dir, const void* buffer, size_t size) {
|
||||
/* Ignore log data which is too large. */
|
||||
if (size > this->QueueBufferSize) return;
|
||||
|
||||
|
@ -220,6 +219,12 @@ namespace ams::mitm::uart {
|
|||
/* Setup the msg and send it. */
|
||||
msg->type = 1;
|
||||
msg->dir = dir;
|
||||
if (timestamp_base) {
|
||||
msg->timestamp = (armTicksToNs(armGetSystemTick() - tick_base) / 1000) + timestamp_base;
|
||||
}
|
||||
else {
|
||||
msg->timestamp = 0;
|
||||
}
|
||||
msg->datalog_file = f;
|
||||
msg->file_pos = file_pos;
|
||||
msg->size = size;
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace ams::mitm::uart {
|
|||
struct UartLogMessage {
|
||||
u8 type;
|
||||
bool dir;
|
||||
s64 timestamp;
|
||||
FsFile *datalog_file;
|
||||
size_t *file_pos;
|
||||
size_t size;
|
||||
|
@ -57,7 +58,7 @@ namespace ams::mitm::uart {
|
|||
|
||||
void WriteCmdLog(const char *path, const char *str, size_t *file_pos);
|
||||
void WriteLog(FsFile *f, size_t *datalog_pos, const void* buffer, size_t size);
|
||||
void WriteLogPacket(FsFile *f, size_t *datalog_pos, bool dir, const void* buffer, size_t size);
|
||||
void WriteLogPacket(FsFile *f, size_t *datalog_pos, s64 timestamp, bool dir, const void* buffer, size_t size);
|
||||
public:
|
||||
UartLogger();
|
||||
~UartLogger();
|
||||
|
@ -66,7 +67,7 @@ namespace ams::mitm::uart {
|
|||
|
||||
void InitializeDataLog(FsFile *f, size_t *datalog_pos);
|
||||
|
||||
void SendLogData(FsFile *f, size_t *file_pos, bool dir, const void* buffer, size_t size);
|
||||
void SendLogData(FsFile *f, size_t *file_pos, s64 timestamp_base, s64 tick_base, bool dir, const void* buffer, size_t size);
|
||||
void SendTextLogData(const char *path, size_t *file_pos, const char *str);
|
||||
};
|
||||
|
||||
|
|
|
@ -45,7 +45,14 @@ namespace ams::mitm::uart {
|
|||
/* Get a timestamp. */
|
||||
u64 timestamp0=0, timestamp1;
|
||||
this->TryGetCurrentTimestamp(×tamp0);
|
||||
timestamp1 = svcGetSystemTick();
|
||||
timestamp1 = armGetSystemTick();
|
||||
|
||||
/* Setup the btsnoop base timestamps. */
|
||||
this->m_timestamp_base = timestamp0;
|
||||
if (this->m_timestamp_base) {
|
||||
this->m_timestamp_base = 0x00E03AB44A676000 + (this->m_timestamp_base - 946684800) * 1000000;
|
||||
}
|
||||
this->m_tick_base = timestamp1;
|
||||
|
||||
/* Setup/create the logging directory. */
|
||||
std::snprintf(this->m_base_path, sizeof(this->m_base_path), "uart_logs/%011lu_%011lu_%016lx", timestamp0, timestamp1, static_cast<u64>(this->m_client_info.program_id));
|
||||
|
@ -204,7 +211,7 @@ namespace ams::mitm::uart {
|
|||
/* Only write to the file if data-logging is enabled and initialized. */
|
||||
if (this->m_data_logging_enabled && this->m_datalog_ready) {
|
||||
std::shared_ptr<UartLogger> logger = mitm::uart::g_logger;
|
||||
logger->SendLogData(&this->m_datalog_file, &this->m_datalog_pos, dir, cache_buffer, pkt_len);
|
||||
logger->SendLogData(&this->m_datalog_file, &this->m_datalog_pos, this->m_timestamp_base, this->m_tick_base, dir, cache_buffer, pkt_len);
|
||||
}
|
||||
(*cache_pos)-= pkt_len;
|
||||
if (*cache_pos) {
|
||||
|
|
|
@ -45,6 +45,9 @@ namespace ams::mitm::uart {
|
|||
|
||||
static constexpr inline size_t CacheBufferSize = 0x1000;
|
||||
|
||||
s64 m_timestamp_base;
|
||||
s64 m_tick_base;
|
||||
|
||||
char m_base_path[256];
|
||||
|
||||
size_t m_cmdlog_pos;
|
||||
|
|
Loading…
Reference in a new issue