logging simplification: switch bare functions to member functions (#1788)

* first pass

* first pass

* const means we don't have to check!

* static

* test fixup
This commit is contained in:
Matthew Kennedy 2020-09-11 17:08:11 -07:00 committed by GitHub
parent a0cd451c5d
commit d941bdc502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 117 additions and 163 deletions

View File

@ -176,7 +176,7 @@ static systime_t timeOfPreviousPrintVersion = (systime_t) -1;
#if EFI_PROD_CODE #if EFI_PROD_CODE
static void printOutPin(const char *pinName, brain_pin_e hwPin) { static void printOutPin(const char *pinName, brain_pin_e hwPin) {
if (hwPin != GPIO_UNASSIGNED) { if (hwPin != GPIO_UNASSIGNED) {
appendPrintf(&logger, "%s%s%s@%s%s", PROTOCOL_OUTPIN, DELIMETER, pinName, hwPortname(hwPin), DELIMETER); logger.appendPrintf("%s%s%s@%s%s", PROTOCOL_OUTPIN, DELIMETER, pinName, hwPortname(hwPin), DELIMETER);
} }
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */

View File

@ -119,7 +119,7 @@ static void printToStream(MemoryStream *stream, const char *fmt, va_list ap) {
} }
static void printWarning(const char *fmt, va_list ap) { static void printWarning(const char *fmt, va_list ap) {
resetLogging(&logger); // todo: is 'reset' really needed here? logger.reset(); // todo: is 'reset' really needed here?
appendMsgPrefix(&logger); appendMsgPrefix(&logger);
logger.append(WARNING_PREFIX); logger.append(WARNING_PREFIX);
@ -137,7 +137,7 @@ static void printWarning(const char *fmt, va_list ap) {
} }
logger.append(warningBuffer); logger.append(warningBuffer);
append(&logger, DELIMETER); logger.append(DELIMETER);
scheduleLogging(&logger); scheduleLogging(&logger);
} }

View File

@ -58,7 +58,7 @@ int waveChartUsedSize;
//#define DEBUG_WAVE 1 //#define DEBUG_WAVE 1
#if DEBUG_WAVE #if DEBUG_WAVE
static Logging debugLogging; static LoggingWithStorage debugLogging("debug");
#endif /* DEBUG_WAVE */ #endif /* DEBUG_WAVE */
static LoggingWithStorage logger("wave info"); static LoggingWithStorage logger("wave info");
@ -76,11 +76,10 @@ static void resetNow(void) {
} }
#endif #endif
WaveChart::WaveChart() { WaveChart::WaveChart() : logging("wave chart", WAVE_LOGGING_BUFFER, sizeof(WAVE_LOGGING_BUFFER)) {
} }
void WaveChart::init() { void WaveChart::init() {
logging.initLoggingExt("wave chart", WAVE_LOGGING_BUFFER, sizeof(WAVE_LOGGING_BUFFER));
isInitialized = true; isInitialized = true;
reset(); reset();
} }
@ -89,11 +88,11 @@ void WaveChart::reset() {
#if DEBUG_WAVE #if DEBUG_WAVE
scheduleSimpleMsg(&debugLogging, "reset while at ", counter); scheduleSimpleMsg(&debugLogging, "reset while at ", counter);
#endif /* DEBUG_WAVE */ #endif /* DEBUG_WAVE */
resetLogging(&logging); logging.reset();
counter = 0; counter = 0;
startTimeNt = 0; startTimeNt = 0;
collectingData = false; collectingData = false;
appendPrintf(&logging, "%s%s", PROTOCOL_ENGINE_SNIFFER, DELIMETER); logging.appendPrintf( "%s%s", PROTOCOL_ENGINE_SNIFFER, DELIMETER);
} }
void WaveChart::startDataCollection() { void WaveChart::startDataCollection() {
@ -144,8 +143,8 @@ void WaveChart::publishIfFull() {
} }
void WaveChart::publish() { void WaveChart::publish() {
appendPrintf(&logging, DELIMETER); logging.appendPrintf( DELIMETER);
waveChartUsedSize = loggingSize(&logging); waveChartUsedSize = logging.loggingSize();
#if DEBUG_WAVE #if DEBUG_WAVE
Logging *l = &chart->logging; Logging *l = &chart->logging;
scheduleSimpleMsg(&debugLogging, "IT'S TIME", strlen(l->buffer)); scheduleSimpleMsg(&debugLogging, "IT'S TIME", strlen(l->buffer));
@ -211,20 +210,20 @@ void WaveChart::addEvent3(const char *name, const char * msg) {
uint32_t diffNt = nowNt - startTimeNt; uint32_t diffNt = nowNt - startTimeNt;
uint32_t time100 = NT2US(diffNt / ENGINE_SNIFFER_UNIT_US); uint32_t time100 = NT2US(diffNt / ENGINE_SNIFFER_UNIT_US);
if (remainingSize(&logging) > 35) { if (logging.remainingSize() > 35) {
/** /**
* printf is a heavy method, append is used here as a performance optimization * printf is a heavy method, append is used here as a performance optimization
*/ */
appendFast(&logging, name); logging.appendFast(name);
appendChar(&logging, CHART_DELIMETER); logging.appendChar(CHART_DELIMETER);
appendFast(&logging, msg); logging.appendFast(msg);
appendChar(&logging, CHART_DELIMETER); logging.appendChar(CHART_DELIMETER);
// time100 -= startTime100; // time100 -= startTime100;
itoa10(timeBuffer, time100); itoa10(timeBuffer, time100);
appendFast(&logging, timeBuffer); logging.appendFast(timeBuffer);
appendChar(&logging, CHART_DELIMETER); logging.appendChar(CHART_DELIMETER);
logging.linePointer[0] = 0; logging.appendChar('\0');
} }
if (!alreadyLocked) { if (!alreadyLocked) {
unlockOutputBuffer(); unlockOutputBuffer();
@ -240,10 +239,6 @@ void initWaveChart(WaveChart *chart) {
printStatus(); printStatus();
#if DEBUG_WAVE
initLoggingExt(&debugLogging, "wave chart debug", &debugLogging.DEFAULT_BUFFER, sizeof(debugLogging.DEFAULT_BUFFER));
#endif
#if EFI_HISTOGRAMS #if EFI_HISTOGRAMS
initHistogram(&engineSnifferHisto, "wave chart"); initHistogram(&engineSnifferHisto, "wave chart");
#endif /* EFI_HISTOGRAMS */ #endif /* EFI_HISTOGRAMS */

View File

@ -171,38 +171,38 @@ static void reportWave(Logging *logging, int index) {
float dwellMs = getSignalOnTime(index); float dwellMs = getSignalOnTime(index);
float periodMs = getSignalPeriodMs(index); float periodMs = getSignalPeriodMs(index);
appendPrintf(logging, "duty%d%s", index, DELIMETER); logging->appendPrintf("duty%d%s", index, DELIMETER);
appendFloat(logging, 100.0f * dwellMs / periodMs, 2); logging->appendFloat(100.0f * dwellMs / periodMs, 2);
appendPrintf(logging, "%s", DELIMETER); logging->appendPrintf("%s", DELIMETER);
/** /**
* that's the ON time of the LAST signal * that's the ON time of the LAST signal
*/ */
appendPrintf(logging, "dwell%d%s", index, DELIMETER); logging->appendPrintf("dwell%d%s", index, DELIMETER);
appendFloat(logging, dwellMs, 2); logging->appendFloat(dwellMs, 2);
appendPrintf(logging, "%s", DELIMETER); logging->appendPrintf("%s", DELIMETER);
/** /**
* that's the total ON time during the previous engine cycle * that's the total ON time during the previous engine cycle
*/ */
appendPrintf(logging, "total_dwell%d%s", index, DELIMETER); logging->appendPrintf("total_dwell%d%s", index, DELIMETER);
appendFloat(logging, readers[index].prevTotalOnTimeUs / 1000.0f, 2); logging->appendFloat(readers[index].prevTotalOnTimeUs / 1000.0f, 2);
appendPrintf(logging, "%s", DELIMETER); logging->appendPrintf("%s", DELIMETER);
appendPrintf(logging, "period%d%s", index, DELIMETER); logging->appendPrintf("period%d%s", index, DELIMETER);
appendFloat(logging, periodMs, 2); logging->appendFloat(periodMs, 2);
appendPrintf(logging, "%s", DELIMETER); logging->appendPrintf("%s", DELIMETER);
uint32_t offsetUs = getWaveOffset(index); uint32_t offsetUs = getWaveOffset(index);
int rpm = GET_RPM(); int rpm = GET_RPM();
if (rpm != 0) { if (rpm != 0) {
float oneDegreeUs = getOneDegreeTimeUs(rpm); float oneDegreeUs = getOneDegreeTimeUs(rpm);
appendPrintf(logging, "advance%d%s", index, DELIMETER); logging->appendPrintf("advance%d%s", index, DELIMETER);
float angle = (offsetUs / oneDegreeUs) - tdcPosition(); float angle = (offsetUs / oneDegreeUs) - tdcPosition();
fixAngle(angle, "waveAn", CUSTOM_ERR_6564); fixAngle(angle, "waveAn", CUSTOM_ERR_6564);
appendFloat(logging, angle, 3); logging->appendFloat(angle, 3);
appendPrintf(logging, "%s", DELIMETER); logging->appendPrintf("%s", DELIMETER);
} }
} }
} }

View File

@ -49,7 +49,7 @@ void scAddData(float angle, float value) {
* data after we have added some data - meaning it's time to flush * data after we have added some data - meaning it's time to flush
*/ */
// message terminator // message terminator
appendPrintf(&scLogging, DELIMETER); scLogging.appendPrintf(DELIMETER);
// output pending data // output pending data
scheduleLogging(&scLogging); scheduleLogging(&scLogging);
pendingData = false; pendingData = false;
@ -58,13 +58,13 @@ void scAddData(float angle, float value) {
} }
if (!pendingData) { if (!pendingData) {
pendingData = true; pendingData = true;
resetLogging(&scLogging); scLogging.reset();
// message header // message header
appendPrintf(&scLogging, "%s%s", PROTOCOL_ANALOG_CHART, DELIMETER); scLogging.appendPrintf( "%s%s", PROTOCOL_ANALOG_CHART, DELIMETER);
} }
if (remainingSize(&scLogging) > 100) { if (scLogging.remainingSize() > 100) {
appendPrintf(&scLogging, "%.2f|%.2f|", angle, value); scLogging.appendPrintf( "%.2f|%.2f|", angle, value);
} }
#endif /* EFI_TEXT_LOGGING */ #endif /* EFI_TEXT_LOGGING */
} }

View File

@ -385,10 +385,10 @@ static void printFullAdcReport(Logging *logger) {
int pin = getAdcChannelPin(hwIndex); int pin = getAdcChannelPin(hwIndex);
int adcValue = getAvgAdcValue(hwIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size()); int adcValue = getAvgAdcValue(hwIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size());
appendPrintf(logger, " F ch%d %s%d", index, portname(port), pin); logger->appendPrintf(" F ch%d %s%d", index, portname(port), pin);
appendPrintf(logger, " ADC%d 12bit=%d", hwIndex, adcValue); logger->appendPrintf(" ADC%d 12bit=%d", hwIndex, adcValue);
float volts = adcToVolts(adcValue); float volts = adcToVolts(adcValue);
appendPrintf(logger, " v=%.2f", volts); logger->appendPrintf(" v=%.2f", volts);
appendMsgPostfix(logger); appendMsgPostfix(logger);
scheduleLogging(logger); scheduleLogging(logger);
@ -405,10 +405,10 @@ static void printFullAdcReport(Logging *logger) {
int pin = getAdcChannelPin(hwIndex); int pin = getAdcChannelPin(hwIndex);
int adcValue = slowAdc.getAdcValueByIndex(index); int adcValue = slowAdc.getAdcValueByIndex(index);
appendPrintf(logger, " S ch%d %s%d", index, portname(port), pin); logger->appendPrintf(" S ch%d %s%d", index, portname(port), pin);
appendPrintf(logger, " ADC%d 12bit=%d", hwIndex, adcValue); logger->appendPrintf(" ADC%d 12bit=%d", hwIndex, adcValue);
float volts = adcToVolts(adcValue); float volts = adcToVolts(adcValue);
appendPrintf(logger, " v=%.2f", volts); logger->appendPrintf(" v=%.2f", volts);
appendMsgPostfix(logger); appendMsgPostfix(logger);
scheduleLogging(logger); scheduleLogging(logger);

View File

@ -145,7 +145,7 @@ void printDateTime(void) {
date_get_tm(&timp); date_get_tm(&timp);
appendMsgPrefix(&logger); appendMsgPrefix(&logger);
appendPrintf(&logger, "Current RTC localtime is: %04u-%02u-%02u %02u:%02u:%02u w=%d", timp.tm_year + 1900, timp.tm_mon + 1, timp.tm_mday, timp.tm_hour, logger.appendPrintf( "Current RTC localtime is: %04u-%02u-%02u %02u:%02u:%02u w=%d", timp.tm_year + 1900, timp.tm_mon + 1, timp.tm_mday, timp.tm_hour,
timp.tm_min, timp.tm_sec, rtcWorks); timp.tm_min, timp.tm_sec, rtcWorks);
appendMsgPostfix(&logger); appendMsgPostfix(&logger);
scheduleLogging(&logger); scheduleLogging(&logger);

View File

@ -73,26 +73,22 @@ static IntermediateLogging intermediateLogging;
/** /**
* @returns true if data does not fit into this buffer * @returns true if data does not fit into this buffer
*/ */
static ALWAYS_INLINE bool validateBuffer(Logging *logging, const char *text, uint32_t extraLen) { bool Logging::validateBuffer(const char *text, uint32_t extraLen) {
if (logging->buffer == NULL) { if (remainingSize() < extraLen + 1) {
firmwareError(CUSTOM_ERR_LOGGING_NOT_READY, "Logging not initialized: %s", logging->name);
return true;
}
if (remainingSize(logging) < extraLen + 1) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
const char * msg = extraLen > 50 ? "(long)" : text; const char * msg = extraLen > 50 ? "(long)" : text;
warning(CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s %d [%s]", logging->name, extraLen, msg); warning(CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s %d [%s]", name, extraLen, msg);
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
return true; return true;
} }
return false; return false;
} }
void Logging::append(const char *text) { void Logging::append(const char *text) {
efiAssertVoid(CUSTOM_APPEND_NULL, text != NULL, "append NULL"); efiAssertVoid(CUSTOM_APPEND_NULL, text != NULL, "append NULL");
uint32_t extraLen = efiStrlen(text); uint32_t extraLen = efiStrlen(text);
bool isCapacityProblem = validateBuffer(this, text, extraLen); bool isCapacityProblem = validateBuffer(text, extraLen);
if (isCapacityProblem) { if (isCapacityProblem) {
return; return;
} }
@ -103,20 +99,14 @@ void Logging::append(const char *text) {
linePointer += extraLen; linePointer += extraLen;
} }
// todo: inline
void append(Logging *logging, const char *text) {
logging->append(text);
}
/** /**
* @note This method if fast because it does not validate much, be sure what you are doing * @note This method if fast because it does not validate much, be sure what you are doing
*/ */
void appendFast(Logging *logging, const char *text) { void Logging::appendFast(const char *text) {
char *s; char *s = linePointer;
s = logging->linePointer;
while ((*s++ = *text++) != 0) while ((*s++ = *text++) != 0)
; ;
logging->linePointer = s - 1; linePointer = s - 1;
} }
/** /**
@ -138,15 +128,6 @@ void Logging::vappendPrintf(const char *fmt, va_list arg) {
#endif // EFI_UNIT_TEST #endif // EFI_UNIT_TEST
} }
// todo: replace with logging->appendPrintf
void appendPrintf(Logging *logging, const char *fmt, ...) {
efiAssertVoid(CUSTOM_APPEND_STACK, getCurrentRemainingStack() > 128, "lowstck#4");
va_list ap;
va_start(ap, fmt);
logging->vappendPrintf(fmt, ap);
va_end(ap);
}
void Logging::appendPrintf(const char *fmt, ...) { void Logging::appendPrintf(const char *fmt, ...) {
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
va_list ap; va_list ap;
@ -162,19 +143,7 @@ void Logging::appendPrintf(const char *fmt, ...) {
#endif // EFI_UNIT_TEST #endif // EFI_UNIT_TEST
} }
void Logging::initLoggingExt(const char *name, char *buffer, int bufferSize) { void Logging::appendFloat(float value, int precision) {
this->name = name;
this->buffer = buffer;
this->bufferSize = bufferSize;
resetLogging(this);
this->isInitialized = true;
}
int isInitialized(Logging *logging) {
return logging->isInitialized;
}
void appendFloat(Logging *logging, float value, int precision) {
/** /**
* todo: #1 this implementation is less than perfect * todo: #1 this implementation is less than perfect
* todo: #2 The only way to avoid double promotion would probably be using *float instead of float * todo: #2 The only way to avoid double promotion would probably be using *float instead of float
@ -182,26 +151,26 @@ void appendFloat(Logging *logging, float value, int precision) {
*/ */
switch (precision) { switch (precision) {
case 1: case 1:
appendPrintf(logging, "%.1f", value); appendPrintf("%.1f", value);
break; break;
case 2: case 2:
appendPrintf(logging, "%.2f", value); appendPrintf("%.2f", value);
break; break;
case 3: case 3:
appendPrintf(logging, "%.3f", value); appendPrintf("%.3f", value);
break; break;
case 4: case 4:
appendPrintf(logging, "%.4f", value); appendPrintf("%.4f", value);
break; break;
case 5: case 5:
appendPrintf(logging, "%.5f", value); appendPrintf("%.5f", value);
break; break;
case 6: case 6:
appendPrintf(logging, "%.6f", value); appendPrintf("%.6f", value);
break; break;
default: default:
appendPrintf(logging, "%.2f", value); appendPrintf("%.2f", value);
} }
} }
@ -210,7 +179,7 @@ static char header[16];
/** /**
* this method should invoked on the main thread only * this method should invoked on the main thread only
*/ */
void printWithLength(char *line) { static void printWithLength(char *line) {
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
int len; int len;
char *p; char *p;
@ -248,21 +217,16 @@ void printWithLength(char *line) {
} }
void appendMsgPrefix(Logging *logging) { void appendMsgPrefix(Logging *logging) {
append(logging, PROTOCOL_MSG DELIMETER); logging->append(PROTOCOL_MSG DELIMETER);
} }
void appendMsgPostfix(Logging *logging) { void appendMsgPostfix(Logging *logging) {
append(logging, DELIMETER); logging->append(DELIMETER);
} }
void resetLogging(Logging *logging) { void Logging::reset() {
char *buffer = logging->buffer; linePointer = buffer;
if (buffer == NULL) { *linePointer = 0;
firmwareError(ERROR_NULL_BUFFER, "Null buffer: %s", logging->name);
return;
}
logging->linePointer = buffer;
logging->linePointer[0] = 0;
} }
/** /**
@ -279,24 +243,17 @@ void printMsg(Logging *logger, const char *fmt, ...) {
logger->vappendPrintf(fmt, ap); logger->vappendPrintf(fmt, ap);
va_end(ap); va_end(ap);
append(logger, DELIMETER); logger->append(DELIMETER);
printWithLength(logger->buffer); printWithLength(logger->buffer);
resetLogging(logger); logger->reset();
} }
uint32_t remainingSize(Logging *logging) { Logging::Logging(char const *name, char *buffer, int bufferSize)
return logging->bufferSize - loggingSize(logging); : name(name)
} , buffer(buffer)
, bufferSize(bufferSize)
Logging::Logging() { {
} reset();
Logging::Logging(char const *name, char *buffer, int bufferSize) : Logging() {
#if ! EFI_UNIT_TEST
initLoggingExt(name, buffer, bufferSize);
#else
this->buffer = buffer;
#endif /* ! EFI_UNIT_TEST */
} }
LoggingWithStorage::LoggingWithStorage(const char *name) : Logging(name, DEFAULT_BUFFER, sizeof(DEFAULT_BUFFER)) { LoggingWithStorage::LoggingWithStorage(const char *name) : Logging(name, DEFAULT_BUFFER, sizeof(DEFAULT_BUFFER)) {

View File

@ -17,28 +17,51 @@
// size of buffers? // size of buffers?
class Logging { class Logging {
public: public:
Logging(); Logging() = delete;
Logging(const char *name, char *buffer, int bufferSize); Logging(const char *name, char *buffer, int bufferSize);
void initLoggingExt(const char *name, char *buffer, int bufferSize);
void reset();
void vappendPrintf(const char *fmt, va_list arg); void vappendPrintf(const char *fmt, va_list arg);
void append(const char *text); void append(const char *text);
void appendFast(const char *text); void appendFast(const char *text);
void appendPrintf(const char *fmt, ...); void appendPrintf(const char *fmt, ...);
const char *name = nullptr; void appendFloat(float value, int precision);
char SMALL_BUFFER[40];
/**
* This macro breaks the normal zero=termination constraint, please take care of this outside of this function
*/
void appendChar(char c) {
*linePointer = c;
linePointer++;
}
size_t loggingSize() const {
return (uintptr_t)linePointer - (uintptr_t)buffer;
}
size_t remainingSize() const {
return bufferSize - loggingSize();
}
//private:
bool validateBuffer(const char *text, uint32_t extraLen);
const char* const name = nullptr;
/** /**
* Zero-terminated buffer of pending debug message * Zero-terminated buffer of pending debug message
* *
* Unless a larger external buffer is specified, this is just a pointer to DEFAULT_BUFFER * Unless a larger external buffer is specified, this is just a pointer to DEFAULT_BUFFER
*/ */
char *buffer = nullptr; char* const buffer = nullptr;
const int bufferSize = 0;
/** /**
* This pointer is always pointing at the position within the buffer into which next * This pointer is always pointing at the position within the buffer into which next
* write operation would append additional data * write operation would append additional data
*/ */
char *linePointer = nullptr; char *linePointer = nullptr;
int bufferSize = 0;
volatile bool isInitialized = false;
}; };
class LoggingWithStorage : public Logging { class LoggingWithStorage : public Logging {
@ -47,14 +70,8 @@ public:
char DEFAULT_BUFFER[200]; char DEFAULT_BUFFER[200];
}; };
int isInitialized(Logging *logging);
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize); void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize);
void appendFloat(Logging *logging, float value, int precision);
void resetLogging(Logging *logging);
void appendMsgPrefix(Logging *logging); void appendMsgPrefix(Logging *logging);
void appendMsgPostfix(Logging *logging); void appendMsgPostfix(Logging *logging);
@ -67,20 +84,7 @@ extern "C"
#define lockOutputBuffer lockAnyContext #define lockOutputBuffer lockAnyContext
#define unlockOutputBuffer unlockAnyContext #define unlockOutputBuffer unlockAnyContext
uint32_t remainingSize(Logging *logging);
#define loggingSize(logging) ((int) (logging)->linePointer - (int) ((logging)->buffer))
void printMsg(Logging *logging, const char *fmt, ...); void printMsg(Logging *logging, const char *fmt, ...);
void appendPrintf(Logging *logging, const char *fmt, ...);
void append(Logging *logging, const char *text);
void appendFast(Logging *logging, const char *text);
/**
* This macro breaks the normal zero=termination constraint, please take care of this outside of this macro
*/
#define appendChar(logging, symbol) {(logging)->linePointer[0] = (symbol);(logging)->linePointer++;}
/** /**
* this method copies the line into the intermediate buffer for later output by * this method copies the line into the intermediate buffer for later output by
@ -91,5 +95,3 @@ void scheduleLogging(Logging *logging);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
void printWithLength(char *line);

View File

@ -312,12 +312,12 @@ void printHistogram(Logging *logging, histogram_s *histogram) {
int report[5]; int report[5];
int len = hsReport(histogram, report); int len = hsReport(histogram, report);
resetLogging(logging); logging->reset();
appendMsgPrefix(logging); appendMsgPrefix(logging);
appendPrintf(logging, "histogram %s *", histogram->name); logging.appendPrintf("histogram %s *", histogram->name);
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
appendPrintf(logging, "%d ", report[i]); logging.appendPrintf("%d ", report[i]);
appendPrintf(logging, "*"); logging.appendPrintf("*");
appendMsgPostfix(logging); appendMsgPostfix(logging);
scheduleLogging(logging); scheduleLogging(logging);
#else #else

View File

@ -82,7 +82,7 @@ void scheduleLogging(Logging *logging) {
if (!alreadyLocked) { if (!alreadyLocked) {
unlockOutputBuffer(); unlockOutputBuffer();
} }
resetLogging(logging); logging->reset();
return; return;
} }
// memcpy is faster then strcpy because it is not looking for line terminator // memcpy is faster then strcpy because it is not looking for line terminator
@ -91,7 +91,7 @@ void scheduleLogging(Logging *logging) {
if (!alreadyLocked) { if (!alreadyLocked) {
unlockOutputBuffer(); unlockOutputBuffer();
} }
resetLogging(logging); logging->reset();
#endif /* EFI_TEXT_LOGGING */ #endif /* EFI_TEXT_LOGGING */
} }
@ -167,7 +167,7 @@ void scheduleMsg(Logging *logging, const char *format, ...) {
return; return;
} }
int wasLocked = lockAnyContext(); int wasLocked = lockAnyContext();
resetLogging(logging); // todo: is 'reset' really needed here? logging->reset(); // todo: is 'reset' really needed here?
appendMsgPrefix(logging); appendMsgPrefix(logging);
va_list ap; va_list ap;

View File

@ -69,20 +69,20 @@ static void runChprintfTest() {
{ {
LoggingWithStorage testLogging("test"); LoggingWithStorage testLogging("test");
appendFloat(&testLogging, 1.23, 5); testLogging.appendFloat(1.23, 5);
appendFloat(&testLogging, 1.234, 2); testLogging.appendFloat(1.234, 2);
assertString(testLogging.buffer, "1.230001.23"); assertString(testLogging.buffer, "1.230001.23");
} }
{ {
LoggingWithStorage testLogging("test"); LoggingWithStorage testLogging("test");
appendFloat(&testLogging, -1.23, 5); testLogging.appendFloat(-1.23, 5);
assertString(testLogging.buffer, "-1.23000"); assertString(testLogging.buffer, "-1.23000");
} }
{ {
LoggingWithStorage testLogging("test"); LoggingWithStorage testLogging("test");
appendPrintf(&testLogging, "a%.2fb%fc", -1.2, -3.4); testLogging.appendPrintf( "a%.2fb%fc", -1.2, -3.4);
assertString(testLogging.buffer, "a-1.20b-3.400000095c"); assertString(testLogging.buffer, "a-1.20b-3.400000095c");
} }

View File

@ -104,7 +104,7 @@ TEST(fuel, testAccelEnrichmentFractionalTps) {
} }
} }
Logging logger; LoggingWithStorage logger("test");
initAccelEnrichment(&logger PASS_ENGINE_PARAMETER_SUFFIX); initAccelEnrichment(&logger PASS_ENGINE_PARAMETER_SUFFIX);
engine->rpmCalculator.setRpmValue(600); engine->rpmCalculator.setRpmValue(600);

View File

@ -16,7 +16,7 @@ efitimems_t currentTimeMillis(void) {
return mockTimeMs; return mockTimeMs;
} }
Logging logging; LoggingWithStorage logging("test");
static float zigZagOffset = 0; static float zigZagOffset = 0;