PerfTraceTool

This commit is contained in:
rusefi 2019-11-25 00:57:36 -05:00
parent 9a0b66791b
commit 603f7e9ecb
5 changed files with 138 additions and 2 deletions

View File

@ -1,4 +1,7 @@
/**
* @file perf_trace.h
*
*/
#pragma once
#include <cstdint>
@ -9,6 +12,8 @@
// each element in PE more than once, as they should each indicate that a specific thing began,
// ended, or occured.
enum class PE : uint8_t {
// The tag below is consumed by PerfTraceTool.java
// enum_start_tag
INVALID,
ISR,
ContextSwitch,
@ -48,6 +53,9 @@ enum class PE : uint8_t {
TunerStudioHandleCrcCommand,
PwmConfigTogglePwmState,
PwmConfigStateChangeCallback,
// enum_end_tag
// The tag above is consumed by PerfTraceTool.java
// please note that the tool requires a comma at the end of last value
};
void perfEventBegin(PE event, uint8_t data);

View File

@ -0,0 +1,5 @@
#
# this tool might have enough flexibility to generate both C# and java class depending on specified "top line" and "stringClassName" parameters?
#
java -jar ../java_console_binary/rusefi_console.jar ptrace_enums development/perf_trace.h ../java_console/models/src/com/rusefi/tracing/EnumNames.java "package com.rusefi.tracing;" "public static final String"

View File

@ -0,0 +1,72 @@
package com.rusefi;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class PerfTraceTool {
private static final String EOL = "\r\n";
public static void readPerfTrace(String inputFileName, String outputFileName, String topClassLine, String stringType) throws IOException {
List<String> enumNames = readEnums(inputFileName);
System.out.println("Got enums: " + enumNames);
writeClass(outputFileName, enumNames, topClassLine, stringType);
}
private static void writeClass(String outputFileName, List<String> enumNames, String topClassLine, String stringType) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName));
writer.write(topClassLine + EOL + EOL);
writer.write("public class EnumNames {" + EOL);
writer.write("\t" +
stringType +
"[] TypeNames = {" + EOL);
for (String enumValue : enumNames)
writer.write("\t\"" + enumValue + "\"," + EOL);
writer.write("\t};" + EOL);
writer.write("}" + EOL);
writer.close();
System.out.println("Done writing to " + outputFileName);
}
private static List<String> readEnums(String inputFileName) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(inputFileName));
boolean weAreInBusiness = false;
List<String> result = new ArrayList<>();
String line;
while ((line = br.readLine()) != null) {
if (line.contains("enum_start_tag")) {
weAreInBusiness = true;
continue;
}
if (line.contains("enum_end_tag")) {
// we are done here
break;
}
if (!weAreInBusiness)
continue;
line = line.trim().replaceAll("\\s", "");
if (line.endsWith(",")) {
result.add(line.substring(0, line.length() - 1));
}
}
return result;
}
}

View File

@ -0,0 +1,45 @@
package com.rusefi.tracing;
public class EnumNames {
public static final String[] TypeNames = {
"INVALID",
"ISR",
"ContextSwitch",
"OutputPinSetValue",
"DecodeTriggerEvent",
"EnginePeriodicFastCallback",
"EnginePeriodicSlowCallback",
"EngineStatePeriodicFastCallback",
"HandleShaftSignal",
"EventQueueInsertTask",
"EventQueueExecuteAll",
"SingleTimerExecutorDoExecute",
"SingleTimerExecutorScheduleTimerCallback",
"PeriodicControllerPeriodicTask",
"PeriodicTimerControllerPeriodicTask",
"AdcCallbackFast",
"AdcCallbackSlow",
"AdcConversionSlow",
"AdcConversionFast",
"AdcSubscriptionUpdateSubscribers",
"GetRunningFuel",
"GetInjectionDuration",
"HandleFuel",
"MainTriggerCallback",
"OnTriggerEventSparkLogic",
"ShaftPositionListeners",
"GetBaseFuel",
"GetTpsEnrichment",
"GetSpeedDensityFuel",
"WallFuelAdjust",
"MapAveragingTriggerCallback",
"AdcCallbackFastComplete",
"SingleTimerExecutorScheduleByTimestamp",
"ScheduleByAngle",
"EventQueueExecuteCallback",
"PwmGeneratorCallback",
"TunerStudioHandleCrcCommand",
"PwmConfigTogglePwmState",
"PwmConfigStateChangeCallback",
};
}

View File

@ -49,7 +49,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20191124;
public static final int CONSOLE_VERSION = 20191125;
public static final String INI_FILE_PATH = System.getProperty("ini_file_path", "..");
public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", "..");
public static final String TOOLS_PATH = System.getProperty("tools_path", ".");
@ -60,6 +60,7 @@ public class Launcher {
private static final String TOOL_NAME_COMPILE_FSIO_FILE = "compile_fsio_file";
private static final String TOOL_NAME_REBOOT_ECU = "reboot_ecu";
private static final String TOOL_NAME_FIRING_ORDER = "firing_order";
private static final String TOOL_NAME_PERF_ENUMS = "ptrace_enums";
// todo: rename to something more FSIO-specific? would need to update documentation somewhere
private static final String TOOL_NAME_COMPILE = "compile";
@ -336,6 +337,11 @@ public class Launcher {
System.exit(0);
}
if (TOOL_NAME_PERF_ENUMS.equals(toolName)) {
PerfTraceTool.readPerfTrace(args[1], args[2], args[3], args[4]);
System.exit(0);
}
System.out.println("Optional tools: " + Arrays.asList(TOOL_NAME_COMPILE_FSIO_FILE,
TOOL_NAME_COMPILE,
TOOL_NAME_REBOOT_ECU,