diff --git a/README.adoc b/README.adoc index ebd1502a..1d0b5417 100644 --- a/README.adoc +++ b/README.adoc @@ -8,10 +8,27 @@ that provides a completely automated preprocessing, compilation, installation and profiling of JavaCard code on JavaCard smart cards or in the jCardSim simulator. +Why profiling? +-------------- +* *Side-channel security* -- non-constant execution time or memory usage can leak secret key material. The per-trap histograms immediately reveal whether a branch or loop depends on secret data. +* *Performance optimisation* -- identify slow operations and decide whether to move them to native JavaCard commands. +* *Hardware validation* -- confirm that your applet behaves identically on the real card and in the simulator before deployment. + +What you get +~~~~~~~~~~~~ +After a successful run, JCProfilerNext produces: + +* timing or memory measurements, +* an interactive visualisation of those measurements with per-line histograms, +* original source files annotated with inline measurement comments, +* frequency table of every JavaCard API call made by your applet (stats mode only). + Prerequisites ------------- * Install JDK 8 or newer. * Obtain a copy of the JavaCard Development Kit, e.g. from this link:https://github.com/martinpaljak/oracle_javacard_sdks[GitHub archive] maintained by Martin Paljak. +* [Real card only] The card must have sufficient free EEPROM space for your applet. The instrumented applet is larger than the original (profiling traps are inserted), so ensure a few extra kilobytes are available. Use `--simulator` to avoid this requirement entirely. +* [Real card only] A PC/SC-compatible smart card reader and its drivers must be installed. .Compatibility Matrix [cols="^1,^2"] @@ -40,6 +57,16 @@ Compilation .. directly using Gradle: `./gradlew run --args='--help'`. .. directly using built JAR: `java -jar build/libs/JCProfilerNext-1.0-SNAPSHOT.jar --help`. .. directly from distribution archives in `build/distributions`. +.. as a standalone binary (recommended): run `./gradlew installDist`, then use + `build/install/JCProfilerNext/bin/JCProfilerNext` (Unix) or + `build\install\JCProfilerNext\bin\JCProfilerNext.bat` (Windows). + You can add this `bin/` directory to your `PATH` for convenient access. + +Profiling Applet Uninstallation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +If you installed an applet on a real card during a profiling run, remove it using +link:https://github.com/martinpaljak/GlobalPlatformPro[GlobalPlatformPro]: +The default package AID is `123456789001` and the default applet AID is `12345678900101`. Execution modes --------------- @@ -58,7 +85,7 @@ locating a user-provided delimiter pattern inside each captured trace. This mode is currently under development and available in the link:https://github.com/crocs-muni/JCProfilerNext/tree/spa-time[`spa-time` branch]. -Time Example +Time example ~~~~~~~~~~~~ Consider the `example` method in the following class. The outer loop is clearly not constant since its iteration count depends on the input value. On the other @@ -108,8 +135,11 @@ public class Example extends Applet { Run as: [source,console] ---- -$ ./gradlew run --args="--work-dir example --jckit jc222_kit --executable example --ins 0xEE --data-regex 00[0-9A-F]{2} --repeat-count 100" +$ ./gradlew run --args="--work-dir example --jckit jc222_kit --entry-point example.Example --executable example --ins 0xEE --data-regex 00[0-9A-F]{2} --repeat-count 100" ---- +The `--entry-point` value is the *fully-qualified class name* (`package.ClassName`). +The `--executable` value is the *unqualified method name* (`methodName`). + JCProfilerNext will process all sources in the `example` directory and will also use this directory to store all intermediate results: @@ -125,7 +155,7 @@ produced by JCProfilerNext, you will see that some parts of the code are indeed not constant, namely if you inspect the corresponding histograms of traps after the `for` loops. -Memory Example +Memory example ~~~~~~~~~~~~~~ Consider the following source code: @@ -169,7 +199,7 @@ deselect memory may also affect the amount of free transient memory and vice ver See link:https://crocs-muni.github.io/JCProfilerNext/example-memory.html[`measurements.html`] for visualisation of the measurements. -Stats Example +Stats example ~~~~~~~~~~~~~ Consider the following source code: @@ -203,6 +233,28 @@ javacard.security,KeyPair,genKeyPair(),1 javacard.security,KeyPair,"KeyPair(byte,short)",1 ---- +FAQ +--- + +*My card is not recognised / connection fails.*:: + Check that a PC/SC driver for your reader is installed and that no other application is locking the card. + +*Compilation fails with a javac error.*:: + Verify that your JDK version is compatible with the target JavaCard SDK — see the Compatibility Matrix. + JDK 8 offers the widest compatibility (JavaCard 2.2.1+). + +*The tool crashes with an unexpected exception.*:: + Re-run with `--debug`, collect the full output, and open an issue at + https://github.com/crocs-muni/JCProfilerNext. + Please include the `--debug` log and the exact command you ran. + +*Measurements are inconsistent between runs.*:: + Increase `--repeat-count` (default: 1000) to reduce statistical noise. + +*What JDK should I use?*:: + JDK 8 is recommended for the widest JavaCard SDK compatibility. + See the Compatibility Matrix under _Prerequisites_ for details. + Limitations ----------- diff --git a/build.gradle b/build.gradle index 739dfc37..9ed10d7a 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ repositories { dependencies { // commandline arguments parsing - implementation 'com.beust:jcommander:1.82' + implementation 'org.jcommander:jcommander:1.85' // last version that supports Java 8 // Spoon implementation 'fr.inria.gforge.spoon:spoon-core:9.1.0' // last version that supports Java 8 diff --git a/src/main/java/jcprofiler/JCProfiler.java b/src/main/java/jcprofiler/JCProfiler.java index 2f888f76..7359987c 100644 --- a/src/main/java/jcprofiler/JCProfiler.java +++ b/src/main/java/jcprofiler/JCProfiler.java @@ -37,17 +37,24 @@ private JCProfiler() {} */ public static void run(final Args args) { if (args.mode == Mode.stats) { - log.info("Collecting API usage statistics."); + log.info(""); + log.info("+---------------------------------+"); + log.info("| Stage 1/1: stats |"); + log.info("+---------------------------------+"); new Instrumenter(args).generateStatistics(); - log.info("Collecting complete."); + log.info(""); + log.info("Done. Results written to: {}", args.workDir.toAbsolutePath()); + log.info(" APIstatistics.csv -- API usage frequency table"); return; } // Instrumentation if (args.startFrom.ordinal() <= Stage.instrumentation.ordinal()) { - log.info("Instrumentation started."); + log.info(""); + log.info("+---------------------------------+"); + log.info("| Stage 1/5: instrumentation |"); + log.info("+---------------------------------+"); JCProfilerUtil.moveToSubDirIfNotExists(args.workDir, JCProfilerUtil.getSourceInputDirectory(args.workDir)); - new Instrumenter(args).process(); log.info("Instrumentation complete."); } @@ -64,7 +71,10 @@ public static void run(final Args args) { // Compilation if (args.startFrom.ordinal() <= Stage.compilation.ordinal()) { - log.info("Compilation started."); + log.info(""); + log.info("+---------------------------------+"); + log.info("| Stage 2/5: compilation |"); + log.info("+---------------------------------+"); Compiler.compile(args, entryPoint); log.info("Compilation complete."); } @@ -75,11 +85,13 @@ public static void run(final Args args) { // Installation CardManager cardManager = null; if (args.startFrom.ordinal() <= Stage.installation.ordinal()) { - // noop for --simulator + log.info(""); + log.info("+---------------------------------+"); + log.info("| Stage 3/5: installation |"); + log.info("+---------------------------------+"); if (args.useSimulator) { - log.info("Skipping installation because simulator is used."); + log.info("Skipping installation (simulator mode)."); } else { - log.info("Installation started."); cardManager = Installer.installOnCard(args, entryPoint); log.info("Installation complete."); } @@ -90,12 +102,15 @@ public static void run(final Args args) { // Profiling if (args.startFrom.ordinal() <= Stage.profiling.ordinal()) { + log.info(""); + log.info("+---------------------------------+"); + log.info("| Stage 4/5: profiling |"); + log.info("+---------------------------------+"); // Connect if the installation was skipped or simulator is used if (cardManager == null) // TODO: move connection stuff to a separate class? cardManager = Installer.connect(args, entryPoint); - log.info("Profiling started."); final AbstractProfiler profiler = AbstractProfiler.create(args, cardManager, model); profiler.profile(); profiler.generateCSV(); @@ -106,11 +121,20 @@ public static void run(final Args args) { return; // Visualisation - log.info("Visualising results."); + log.info(""); + log.info("+---------------------------------+"); + log.info("| Stage 5/5: visualisation |"); + log.info("+---------------------------------+"); final AbstractVisualiser vis = AbstractVisualiser.create(args, model); vis.loadAndProcessMeasurements(); vis.generateHTML(); vis.insertMeasurementsToSources(); - log.info("Visualising results complete."); + log.info("Visualisation complete."); + + log.info(""); + log.info("Done. Results written to: {}", args.workDir.toAbsolutePath()); + log.info(" measurements.csv -- raw per-trap measurements"); + log.info(" measurements.html -- interactive visualisation"); + log.info(" sources_perf/ -- sources annotated with inline measurements"); } } diff --git a/src/main/java/jcprofiler/Main.java b/src/main/java/jcprofiler/Main.java index 5659fe2a..596bf877 100644 --- a/src/main/java/jcprofiler/Main.java +++ b/src/main/java/jcprofiler/Main.java @@ -4,6 +4,7 @@ package jcprofiler; import com.beust.jcommander.JCommander; +import com.beust.jcommander.UnixStyleUsageFormatter; import jcprofiler.args.Args; import jcprofiler.util.JCProfilerUtil; @@ -24,6 +25,7 @@ */ public class Main { private static final Logger log = LoggerFactory.getLogger(Main.class); + private static final String CARD_MANAGER_LOGGER = "cz.muni.fi.crocs.rcard.client.CardManager"; /** * JCProfilerNext's entry point method @@ -32,6 +34,7 @@ public class Main { */ public static void main(final String[] argv) { Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(CARD_MANAGER_LOGGER, Level.WARN); // parse commandline arguments final Args args = new Args(); @@ -39,6 +42,14 @@ public static void main(final String[] argv) { .addObject(args) .programName("JCProfilerNext") .build(); + jc.setUsageFormatter(new UnixStyleUsageFormatter(jc)); + + // show help + if (argv.length == 0) { + jc.usage(); + printHelpExtras(); + return; + } try { jc.parse(argv); @@ -47,19 +58,24 @@ public static void main(final String[] argv) { System.exit(1); } - // show help if (args.help) { jc.usage(); + printHelpExtras(); return; } // TODO: add proper versioning info as well log.info("Welcome to JCProfilerNext!"); - log.info("Command-line arguments parsed successfully."); - if (args.debug) { + if (args.trace) { + args.debug = true; + Configurator.setRootLevel(Level.TRACE); + Configurator.setLevel(CARD_MANAGER_LOGGER, Level.TRACE); + log.info("LogLevel set to TRACE."); + } else if (args.debug) { Configurator.setRootLevel(Level.DEBUG); log.info("LogLevel set to DEBUG."); } + log.debug("Command-line arguments parsed successfully."); // log basic info log.info("Found JavaCard SDK {} ({})", args.jcSDK.getRelease(), args.jcSDK.getRoot().getAbsolutePath()); @@ -82,6 +98,44 @@ public static void main(final String[] argv) { } } + private static void printHelpExtras() { + System.out.println(); + System.out.println("ARGUMENT STRUCTURE"); + System.out.println(" Required arguments for a profiling run: --work-dir and --jckit."); + System.out.println(" --entry-point expects a fully-qualified class name: package.ClassName"); + System.out.println(" --executable expects an unqualified method name: myMethod"); + System.out.println(" Hex values (--cla, --ins, --p1, --p2, --reset-ins) accept either a plain"); + System.out.println(" hex number (e.g. EE) or a 0x-prefixed value (e.g. 0xEE)."); + System.out.println(" Either --data-regex or --data-file must be provided when profiling a method"); + System.out.println(" (not needed for memory profiling of the constructor or stats mode)."); + System.out.println(); + System.out.println("EXAMPLES"); + System.out.println(); + System.out.println(" # Profile a specific method (time mode, real card):"); + System.out.println(" JCProfilerNext --work-dir path/to/applet --jckit path/to/jc304_kit \\"); + System.out.println(" --entry-point com.example.MyApplet --executable myMethod \\"); + System.out.println(" --repeat-count 100 --data-regex \"[0-9A-F]{64}\" --mode time"); + System.out.println(); + System.out.println(" # Profile a method using the simulator, no entry-point needed (single applet):"); + System.out.println(" JCProfilerNext --work-dir path/to/applet --jckit path/to/jc222_kit \\"); + System.out.println(" --executable myMethod --ins 0xEE \\"); + System.out.println(" --data-regex 00[0-9A-F]{2} --simulator"); + System.out.println(); + System.out.println(" # Measure memory usage during constructor (no --executable needed):"); + System.out.println(" JCProfilerNext --work-dir path/to/applet --jckit path/to/jc304_kit --mode memory"); + System.out.println(); + System.out.println(" # Collect API usage statistics:"); + System.out.println(" JCProfilerNext --work-dir path/to/applet --jckit path/to/jc222_kit --mode stats"); + System.out.println(); + System.out.println(" # Run only instrumentation and compilation, skip installation/profiling:"); + System.out.println(" JCProfilerNext --work-dir path/to/applet --jckit path/to/jc222_kit \\"); + System.out.println(" --stop-after compilation"); + System.out.println(); + System.out.println("REPORTING BUGS"); + System.out.println(" If you encounter an unexpected error, re-run with --debug, save the output,"); + System.out.println(" and open an issue at https://github.com/crocs-muni/JCProfilerNext"); + } + /** * Validates command line arguments. * diff --git a/src/main/java/jcprofiler/args/Args.java b/src/main/java/jcprofiler/args/Args.java index 3c8142ea..474262e2 100644 --- a/src/main/java/jcprofiler/args/Args.java +++ b/src/main/java/jcprofiler/args/Args.java @@ -28,8 +28,12 @@ public class Args { description = "Enable debug messages") public boolean debug = false; + @Parameter(names = {"-t", "--trace"}, + description = "Enable trace messages (implies --debug; also reveals raw APDU traffic)") + public boolean trace = false; + @Parameter(names = {"-w", "--work-dir"}, - description = "Path to the working directory", + description = "Path to the working directory (required)", required = true, converter = DirectoryPathConverter.class) public Path workDir; @@ -46,7 +50,7 @@ public class Args { @Parameter(names = {"--jckit"}, required = true, - description = "Path to the root directory with JavaCard development kit", + description = "Path to the root directory with JavaCard development kit (required)", converter = JCKitConverter.class) public JavaCardSDK jcSDK; @@ -62,12 +66,13 @@ public class Args { public boolean useSimulator = false; @Parameter(names = {"--executable"}, - description = "Constructor or method to profile or leave unset to instrument applet entry point " + - "constructor (constructors are custom and memory profiling only)") + description = "Unqualified method name to profile (e.g. myMethod). " + + "Omit to profile the entry-point class constructor (constructors: custom and memory mode only)") public String executable; @Parameter(names = {"--entry-point"}, - description = "Qualified name of a class to be used as an entry point (useful when there are more)") + description = "Fully-qualified class name of the applet entry point (e.g. com.example.MyApplet). " + + "Required when the working directory contains more than one applet class") public String entryPoint; @Parameter(names = {"--install-params"}, @@ -102,26 +107,31 @@ public class Args { @Parameter(names = {"--reset-ins"}, description = "Applet reset instruction in hex", + defaultValueDescription = "0x00", converter = ByteConverter.class) public Byte resetIns; @Parameter(names = {"--cla"}, description = "Applet CLA in hex", + defaultValueDescription = "0x00", converter = ByteConverter.class) public byte cla = 0; @Parameter(names = {"--ins"}, description = "Applet instruction in hex", + defaultValueDescription = "0x00", converter = ByteConverter.class) public byte ins = 0; @Parameter(names = {"--p1"}, description = "Applet P1 in hex", + defaultValueDescription = "0x00", converter = ByteConverter.class) public byte p1 = 0; @Parameter(names = {"--p2"}, description = "Applet P2 in hex", + defaultValueDescription = "0x00", converter = ByteConverter.class) public byte p2 = 0; diff --git a/src/main/java/jcprofiler/compilation/Compiler.java b/src/main/java/jcprofiler/compilation/Compiler.java index 36fac650..060016ca 100644 --- a/src/main/java/jcprofiler/compilation/Compiler.java +++ b/src/main/java/jcprofiler/compilation/Compiler.java @@ -64,7 +64,14 @@ public static void compile(final Args args, final CtClass entryPoint) { final DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); - consoleLogger.setMessageOutputLevel(args.debug ? Project.MSG_VERBOSE : Project.MSG_INFO); + final int messageOutputLevel; + if (args.trace) + messageOutputLevel = Project.MSG_VERBOSE; + else if (args.debug) + messageOutputLevel = Project.MSG_INFO; + else + messageOutputLevel = Project.MSG_WARN; + consoleLogger.setMessageOutputLevel(messageOutputLevel); project.addBuildListener(consoleLogger); // create javacard target diff --git a/src/main/java/jcprofiler/installation/Installer.java b/src/main/java/jcprofiler/installation/Installer.java index 7e2b3497..313ddfa3 100644 --- a/src/main/java/jcprofiler/installation/Installer.java +++ b/src/main/java/jcprofiler/installation/Installer.java @@ -131,7 +131,7 @@ public static CardManager connect(final Args args, final CtClass entryPoint) * could not be selected successfully */ private static CardManager configureSimulator(final Args args, final CtClass entryPoint) { - log.info("Configuring jCardSim simulator."); + log.debug("Configuring jCardSim simulator."); // assure jCardSim compatibility with newer bouncycastle System.setProperty("com.licel.jcardsim.bouncycastle.rsa.allow_unsafe_mod", "true"); diff --git a/src/main/java/jcprofiler/instrumentation/Instrumenter.java b/src/main/java/jcprofiler/instrumentation/Instrumenter.java index af8bbff6..924dbe57 100644 --- a/src/main/java/jcprofiler/instrumentation/Instrumenter.java +++ b/src/main/java/jcprofiler/instrumentation/Instrumenter.java @@ -92,14 +92,14 @@ public void process() { spoon.addProcessor(new SpoonWorkarounds.FixStaticMethodImportProcessor()); spoon.addProcessor(new SpoonWorkarounds.FixStaticFieldImportProcessor()); - log.info("Instrumenting existing classes."); + log.debug("Instrumenting existing classes."); spoon.process(); // save the result spoon.getEnvironment().setOutputType(OutputType.CLASSES); spoon.setSourceOutputDirectory(outputDir.toFile()); - log.info("Saving instrumented classes."); + log.debug("Saving instrumented classes."); spoon.prettyprint(); // check that all PMC members are unique @@ -138,7 +138,7 @@ private CtModel buildModel(final Launcher spoon) { * @param model Spoon model */ private void checkArguments(final CtModel model) { - log.info("Validating '--entry-point' and '--executable' arguments."); + log.debug("Validating '--entry-point' and '--executable' arguments."); // validate args.entryPoint args.entryPoint = JCProfilerUtil.getEntryPoint(model, args.entryPoint).getQualifiedName(); @@ -168,7 +168,7 @@ private void checkArguments(final CtModel model) { * @throws UnsupportedOperationException for multipackage projects, for projects using the default package */ private void addMissingClasses(final Launcher spoon) { - log.info("Generating additional classes."); + log.debug("Generating additional classes."); // this atrocity seems to be required as Spoon does not allow a module rebuild :( final Launcher tmpSpoon = new Launcher(); diff --git a/src/main/java/jcprofiler/instrumentation/processors/AbstractInsertTrapProcessor.java b/src/main/java/jcprofiler/instrumentation/processors/AbstractInsertTrapProcessor.java index dd6eaa02..1693afff 100644 --- a/src/main/java/jcprofiler/instrumentation/processors/AbstractInsertTrapProcessor.java +++ b/src/main/java/jcprofiler/instrumentation/processors/AbstractInsertTrapProcessor.java @@ -77,7 +77,7 @@ public void process(final T executable) { trapNamePrefix = JCProfilerUtil.getTrapNamePrefix(executable); // instrument - log.info("Instrumenting {}.", fullSignature); + log.debug("Instrumenting {}.", fullSignature); final CtBlock block = executable.getBody(); if (isEmptyBlock(block)) { diff --git a/src/main/java/jcprofiler/instrumentation/processors/AbstractModifyEntryPointProcessor.java b/src/main/java/jcprofiler/instrumentation/processors/AbstractModifyEntryPointProcessor.java index e7beb623..6f3b5755 100644 --- a/src/main/java/jcprofiler/instrumentation/processors/AbstractModifyEntryPointProcessor.java +++ b/src/main/java/jcprofiler/instrumentation/processors/AbstractModifyEntryPointProcessor.java @@ -56,7 +56,7 @@ public boolean isToBeProcessed(final CtClass cls) { * @param fieldName custom instruction field name */ protected void process(final CtClass cls, final String fieldName) { - log.info("Instrumenting entry point class {}.", cls.getQualifiedName()); + log.debug("Instrumenting entry point class {}.", cls.getQualifiedName()); // get process(APDU) method final CtMethod processMethod = JCProfilerUtil.getProcessMethod(cls); diff --git a/src/main/java/jcprofiler/profiling/AbstractProfiler.java b/src/main/java/jcprofiler/profiling/AbstractProfiler.java index 5c9c897e..628bd4ca 100644 --- a/src/main/java/jcprofiler/profiling/AbstractProfiler.java +++ b/src/main/java/jcprofiler/profiling/AbstractProfiler.java @@ -170,7 +170,7 @@ protected String getTrapName(final short trapID) { * @throws RuntimeException if the extraction of traps from profiled executable failed */ private void buildPerfMapping() { - log.info("Looking for traps in the {}.", profiledExecutableSignature); + log.debug("Looking for traps in the {}.", profiledExecutableSignature); final String trapNamePrefix = JCProfilerUtil.getTrapNamePrefix(profiledExecutable); // get traps form profiledExecutable @@ -197,7 +197,7 @@ private void buildPerfMapping() { for (final CtField f : traps) { final CtLiteral evaluated = f.getDefaultExpression().partiallyEvaluate(); trapNameMap.put(evaluated.getValue().shortValue(), f.getSimpleName()); - log.info("Found {}.", f.getSimpleName()); + log.debug("Found {}.", f.getSimpleName()); } } @@ -218,7 +218,7 @@ protected void generateInputs(int size) { // regex if (args.dataRegex != null) { - log.info("Generating inputs from regular expression {}.", args.dataRegex); + log.debug("Generating inputs from regular expression {}.", args.dataRegex); final RgxGen rgxGen = RgxGen.parse(args.dataRegex); for (int i = 0; i < size * 100; i++) { diff --git a/src/main/java/jcprofiler/profiling/TimeProfiler.java b/src/main/java/jcprofiler/profiling/TimeProfiler.java index 9fee390b..2dca944b 100644 --- a/src/main/java/jcprofiler/profiling/TimeProfiler.java +++ b/src/main/java/jcprofiler/profiling/TimeProfiler.java @@ -60,12 +60,16 @@ protected void profileImpl() { // main profiling loop generateInputs(args.repeatCount); + final int progressStep = Math.max(1, args.repeatCount / 10); for (int round = 1; round <= args.repeatCount; round++) { final CommandAPDU triggerAPDU = getInputAPDU(round); final String input = Util.bytesToHex(triggerAPDU.getBytes()); - log.info("Round: {}/{} APDU: {}", round, args.repeatCount, input); + log.debug("Round: {}/{} APDU: {}", round, args.repeatCount, input); profileSingleStep(triggerAPDU); + + if (round % progressStep == 0 || round == args.repeatCount) + log.info("Progress: {}/{} rounds completed.", round, args.repeatCount); } // sanity check @@ -94,7 +98,7 @@ protected void profileImpl() { * @throws RuntimeException if setting the next fatal performance trap failed */ private void setTrap(short trapID) throws CardException { - log.debug("Setting next trap to {}.", getTrapName(trapID)); + log.trace("Setting next trap to {}.", getTrapName(trapID)); CommandAPDU setTrap = new CommandAPDU(args.cla, JCProfilerUtil.INS_PERF_HANDLER, 0, 0, Util.shortToByteArray(trapID)); @@ -123,7 +127,7 @@ private void profileSingleStep(CommandAPDU triggerAPDU) throws CardException { // execute target operation final String trapName = getTrapName(trapID); - log.debug("Measuring {}.", trapName); + log.trace("Measuring {}.", trapName); final ResponseAPDU response = cardManager.transmit(triggerAPDU); // SW should be equal to the trap ID @@ -137,7 +141,7 @@ private void profileSingleStep(CommandAPDU triggerAPDU) throws CardException { // we have not reached expected performance trap unreachedTraps.add(trapName); measurements.computeIfAbsent(trapName, k -> new ArrayList<>()).add(null); - log.debug("Duration: unreachable"); + log.trace("Duration: unreachable"); continue; } @@ -146,7 +150,7 @@ private void profileSingleStep(CommandAPDU triggerAPDU) throws CardException { final long diff = currentTransmitDuration - prevTransmitDuration; prevTransmitDuration = currentTransmitDuration; - log.debug("Duration: {} ns", diff); + log.trace("Duration: {} ns", diff); // store the difference measurements.computeIfAbsent(getTrapName(trapID), k -> new ArrayList<>()).add(diff); diff --git a/src/main/java/jcprofiler/util/JCProfilerUtil.java b/src/main/java/jcprofiler/util/JCProfilerUtil.java index 0d36e0a2..2f6e4c15 100644 --- a/src/main/java/jcprofiler/util/JCProfilerUtil.java +++ b/src/main/java/jcprofiler/util/JCProfilerUtil.java @@ -671,7 +671,7 @@ public static void setupSpoon(final SpoonAPI spoon, final Args args) { * @return a {@link SpoonAPI} instance */ public static SpoonAPI getInstrumentedSpoon(final Args args) { - log.info("Validating Spoon model."); + log.debug("Validating Spoon model."); final Launcher spoon = new Launcher(); setupSpoon(spoon, args); diff --git a/src/main/java/jcprofiler/visualisation/AbstractVisualiser.java b/src/main/java/jcprofiler/visualisation/AbstractVisualiser.java index 14d7c2a5..fa3a4e68 100644 --- a/src/main/java/jcprofiler/visualisation/AbstractVisualiser.java +++ b/src/main/java/jcprofiler/visualisation/AbstractVisualiser.java @@ -146,7 +146,7 @@ public void loadAndProcessMeasurements() { */ private void loadCSV() { final Path csv = JCProfilerUtil.checkFile(args.workDir.resolve("measurements.csv"), Stage.profiling); - log.info("Loading measurements from {}.", csv); + log.debug("Loading measurements from {}.", csv); try (final CSVParser parser = CSVParser.parse(csv, Charset.defaultCharset(), JCProfilerUtil.getCSVFormat())) { final Iterator it = parser.iterator(); @@ -218,7 +218,7 @@ public void insertMeasurementsToSources() { final Path outputDir = JCProfilerUtil.getPerfOutputDirectory(args.workDir); JCProfilerUtil.recreateDirectory(outputDir); - log.info("Inserting measurements into sources."); + log.debug("Inserting measurements into sources."); final SpoonAPI spoon = JCProfilerUtil.getInstrumentedSpoon(args); spoon.setSourceOutputDirectory(outputDir.toFile()); spoon.addProcessor(getInsertMeasurementsProcessor()); @@ -237,7 +237,7 @@ public void insertMeasurementsToSources() { * Generates the HTML page with interactive visualisation. */ public void generateHTML() { - log.info("Initializing Apache Velocity."); + log.debug("Initializing Apache Velocity."); final Properties props = new Properties(); props.put(RuntimeConstants.EVENTHANDLER_INCLUDE, IncludeRelativePath.class.getName()); props.put(RuntimeConstants.RUNTIME_REFERENCES_STRICT, true); @@ -268,7 +268,7 @@ public void generateHTML() { prepareVelocityContext(context); final Path output = args.workDir.resolve("measurements.html"); - log.info("Generating {}.", output); + log.debug("Generating {}.", output); try (final Writer writer = new FileWriter(output.toFile())) { final Template template = velocityEngine.getTemplate("jcprofiler/visualisation/template.html.vm"); diff --git a/src/main/java/jcprofiler/visualisation/TimeVisualiser.java b/src/main/java/jcprofiler/visualisation/TimeVisualiser.java index 55c16352..1fcc0336 100644 --- a/src/main/java/jcprofiler/visualisation/TimeVisualiser.java +++ b/src/main/java/jcprofiler/visualisation/TimeVisualiser.java @@ -57,7 +57,7 @@ public void loadAndProcessMeasurements() { * Filters obvious outliers from the input measurements. */ private void filterOutliers() { - log.info("Filtering outliers from the loaded measurements."); + log.debug("Filtering outliers from the loaded measurements."); measurements.forEach((k, v) -> { final DescriptiveStatistics ds = new DescriptiveStatistics(); v.stream().filter(Objects::nonNull).map(Long::doubleValue).forEach(ds::addValue);