simulator writes binary log (#3598)
* simulator writes log * replace the file * check that the sim actually fails * put it back * did the sim really not fail? * good, asan does catch it
This commit is contained in:
parent
c29bb71556
commit
178ccdeb4d
|
@ -26,3 +26,6 @@ log.txt
|
|||
|
||||
# Eclipse
|
||||
.metadata/
|
||||
|
||||
# rusEFI simulator makes logs, ignore those
|
||||
rusefi_simulator_log.mlg
|
||||
|
|
|
@ -129,6 +129,22 @@ static void setWarningEnabled(int value) {
|
|||
static NO_CACHE char sdLogBuffer[220];
|
||||
static uint64_t binaryLogCount = 0;
|
||||
|
||||
void writeLogLine(Writer& buffer) {
|
||||
if (!main_loop_started)
|
||||
return;
|
||||
|
||||
if (binaryLogCount == 0) {
|
||||
writeHeader(buffer);
|
||||
} else {
|
||||
updateTunerStudioState(&tsOutputChannels);
|
||||
size_t length = writeBlock(sdLogBuffer);
|
||||
efiAssertVoid(OBD_PCM_Processor_Fault, length <= efi::size(sdLogBuffer), "SD log buffer overflow");
|
||||
buffer.write(sdLogBuffer, length);
|
||||
}
|
||||
|
||||
binaryLogCount++;
|
||||
}
|
||||
|
||||
#endif /* EFI_FILE_LOGGING */
|
||||
|
||||
/**
|
||||
|
@ -145,26 +161,6 @@ static float getAirFlowGauge() {
|
|||
return Sensor::get(SensorType::Maf).value_or(engine->engineState.airFlow);
|
||||
}
|
||||
|
||||
void writeLogLine(Writer& buffer) {
|
||||
#if EFI_FILE_LOGGING
|
||||
if (!main_loop_started)
|
||||
return;
|
||||
|
||||
if (binaryLogCount == 0) {
|
||||
writeHeader(buffer);
|
||||
} else {
|
||||
updateTunerStudioState(&tsOutputChannels);
|
||||
size_t length = writeBlock(sdLogBuffer);
|
||||
efiAssertVoid(OBD_PCM_Processor_Fault, length <= efi::size(sdLogBuffer), "SD log buffer overflow");
|
||||
buffer.write(sdLogBuffer, length);
|
||||
}
|
||||
|
||||
binaryLogCount++;
|
||||
#else
|
||||
(void)buffer;
|
||||
#endif /* EFI_FILE_LOGGING */
|
||||
}
|
||||
|
||||
static int prevCkpEventCounter = -1;
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,14 +16,23 @@
|
|||
|
||||
#if EFI_FILE_LOGGING
|
||||
|
||||
#include "ch.hpp"
|
||||
#include "buffered_writer.h"
|
||||
#include "status_loop.h"
|
||||
|
||||
static bool fs_ready = false;
|
||||
|
||||
int totalLoggedBytes = 0;
|
||||
static int fileCreatedCounter = 0;
|
||||
static int writeCounter = 0;
|
||||
static int totalWritesCounter = 0;
|
||||
static int totalSyncCounter = 0;
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "mmc_card.h"
|
||||
#include "ff.h"
|
||||
#include "hardware.h"
|
||||
#include "status_loop.h"
|
||||
#include "buffered_writer.h"
|
||||
#include "mass_storage_init.h"
|
||||
|
||||
#include "rtc_helper.h"
|
||||
|
@ -40,17 +49,10 @@
|
|||
|
||||
// todo: shall we migrate to enum with enum2string for consistency? maybe not until we start reading sdStatus?
|
||||
static const char *sdStatus = SD_STATE_INIT;
|
||||
static bool fs_ready = false;
|
||||
|
||||
// at about 20Hz we write about 2Kb per second, looks like we flush once every ~2 seconds
|
||||
#define F_SYNC_FREQUENCY 10
|
||||
|
||||
int totalLoggedBytes = 0;
|
||||
static int fileCreatedCounter = 0;
|
||||
static int writeCounter = 0;
|
||||
static int totalWritesCounter = 0;
|
||||
static int totalSyncCounter = 0;
|
||||
|
||||
/**
|
||||
* on't re-read SD card spi device after boot - it could change mid transaction (TS thread could preempt),
|
||||
* which will cause disaster (usually multiple-unlock of the same mutex in UNLOCK_SD_SPI)
|
||||
|
@ -66,8 +68,6 @@ spi_device_e mmcSpiDevice = SPI_NONE;
|
|||
#define LS_RESPONSE "ls_result"
|
||||
#define FILE_LIST_MAX_COUNT 20
|
||||
|
||||
static THD_WORKING_AREA(mmcThreadStack, 3 * UTILITY_THREAD_STACK_SIZE); // MMC monitor thread
|
||||
|
||||
#if HAL_USE_MMC_SPI
|
||||
/**
|
||||
* MMC driver instance.
|
||||
|
@ -468,8 +468,41 @@ struct SdLogBufferWriter final : public BufferedWriter<512> {
|
|||
}
|
||||
};
|
||||
|
||||
#else // not EFI_PROD_CODE (simulator)
|
||||
|
||||
#include <fstream>
|
||||
|
||||
bool mountMmc() {
|
||||
// Stub so the loop thinks the MMC mounted OK
|
||||
return true;
|
||||
}
|
||||
|
||||
class SdLogBufferWriter final : public BufferedWriter<512> {
|
||||
public:
|
||||
bool failed = false;
|
||||
|
||||
SdLogBufferWriter()
|
||||
: m_stream("rusefi_simulator_log.mlg", std::ios::binary | std::ios::trunc)
|
||||
{
|
||||
fs_ready = true;
|
||||
}
|
||||
|
||||
size_t writeInternal(const char* buffer, size_t count) override {
|
||||
m_stream.write(buffer, count);
|
||||
m_stream.flush();
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
std::ofstream m_stream;
|
||||
};
|
||||
|
||||
#endif // EFI_PROD_CODE
|
||||
|
||||
static NO_CACHE SdLogBufferWriter logBuffer;
|
||||
|
||||
|
||||
static THD_WORKING_AREA(mmcThreadStack, 3 * UTILITY_THREAD_STACK_SIZE); // MMC monitor thread
|
||||
static THD_FUNCTION(MMCmonThread, arg) {
|
||||
(void)arg;
|
||||
chRegSetThreadName("MMC Card Logger");
|
||||
|
@ -485,9 +518,11 @@ static THD_FUNCTION(MMCmonThread, arg) {
|
|||
|
||||
while (true) {
|
||||
// if the SPI device got un-picked somehow, cancel SD card
|
||||
#if EFI_PROD_CODE
|
||||
if (engineConfiguration->sdCardSpiDevice == SPI_NONE) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (engineConfiguration->debugMode == DBG_SD_CARD) {
|
||||
tsOutputChannels.debugIntField1 = totalLoggedBytes;
|
||||
|
@ -516,12 +551,14 @@ bool isSdCardAlive(void) {
|
|||
|
||||
// Pre-config load init
|
||||
void initEarlyMmcCard() {
|
||||
#if EFI_PROD_CODE
|
||||
logName[0] = 0;
|
||||
|
||||
addConsoleAction("sdinfo", sdStatistics);
|
||||
addConsoleActionS("ls", listDirectory);
|
||||
addConsoleActionS("del", removeFile);
|
||||
addConsoleAction("incfilename", incLogFileName);
|
||||
#endif // EFI_PROD_CODE
|
||||
}
|
||||
|
||||
void initMmcCard() {
|
||||
|
|
|
@ -134,7 +134,7 @@
|
|||
#define DEBUG_PWM FALSE
|
||||
#define EFI_SIGNAL_EXECUTOR_ONE_TIMER FALSE
|
||||
#define EFI_TUNER_STUDIO_VERBOSE FALSE
|
||||
#define EFI_FILE_LOGGING FALSE
|
||||
#define EFI_FILE_LOGGING TRUE
|
||||
#define EFI_WARNING_LED FALSE
|
||||
#define EFI_VEHICLE_SPEED FALSE
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
extern WaveChart waveChart;
|
||||
|
||||
int getRemainingStack(thread_t *otp) {
|
||||
int getRemainingStack(thread_t*) {
|
||||
return 99999;
|
||||
}
|
||||
|
||||
|
@ -103,6 +103,9 @@ void rusEfiFunctionalTest(void) {
|
|||
|
||||
startLoggingProcessor();
|
||||
|
||||
void initMmcCard();
|
||||
initMmcCard();
|
||||
|
||||
runChprintfTest();
|
||||
|
||||
initPeriodicEvents();
|
||||
|
@ -113,6 +116,9 @@ void rusEfiFunctionalTest(void) {
|
|||
startSerialChannels();
|
||||
|
||||
startLua();
|
||||
|
||||
extern bool main_loop_started;
|
||||
main_loop_started = true;
|
||||
}
|
||||
|
||||
void printPendingMessages(void) {
|
||||
|
|
Loading…
Reference in New Issue