From 7672ace1a98aaeb2d1890653fe92862b165ecea5 Mon Sep 17 00:00:00 2001 From: "patrick.pdb" Date: Fri, 19 Jan 2024 09:43:17 -0300 Subject: [PATCH] '#43 Add new metadata to identify if item is a plugin item and add log execution time info. --- .../task/leappbridge/LeappBridgeTask.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/iped-engine/src/main/java/iped/engine/task/leappbridge/LeappBridgeTask.java b/iped-engine/src/main/java/iped/engine/task/leappbridge/LeappBridgeTask.java index 80bea30835..ec546321f8 100644 --- a/iped-engine/src/main/java/iped/engine/task/leappbridge/LeappBridgeTask.java +++ b/iped-engine/src/main/java/iped/engine/task/leappbridge/LeappBridgeTask.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -50,6 +51,8 @@ public class LeappBridgeTask extends AbstractPythonTask { + AtomicInteger pluginTimeCounter = new AtomicInteger(0); + public static Logger logger = LoggerFactory.getLogger(LeappBridgeTask.class); public static MediaType DEVICEDETAILS = MediaType.application("x-leapp-devicedetails"); @@ -57,6 +60,7 @@ public class LeappBridgeTask extends AbstractPythonTask { private static final String DEVICE_DETAILS_HTML = "DeviceDetails.html"; public static final String ALEAPP_METADATA_PREFIX = "ALEAPP"; + public static final String ALEAPP_ISPLUGIN = ALEAPP_METADATA_PREFIX + ":isPlugin"; public static final String ALEAPP_PLUGIN = ALEAPP_METADATA_PREFIX + ":PLUGIN"; static final String REPORT_EVIDENCE_NAME = "LEAPP_Reports"; @@ -66,7 +70,7 @@ public class LeappBridgeTask extends AbstractPythonTask { private static final String PLUGIN_EXECUTION_MESSAGE = "ALeapp plugin execution"; - static AtomicInteger count = new AtomicInteger(0); + static AtomicInteger taskCount = new AtomicInteger(0); HashMap mappedEvidences = new HashMap(); @@ -90,13 +94,6 @@ public LeappBridgeTask() { static private int START_QUEUE_PRIORITY = 3; - @Override - public List> getConfigurables() { - ArrayList> c = new ArrayList>(); - c.add(new ALeappConfig()); - return c; - } - public static void logfunc(String message) { logger.info(message); } @@ -139,12 +136,13 @@ public static Object open(Collection args, Map kargs) { @Override public void init(ConfigurationManager configurationManager) throws Exception { - int incremented = count.incrementAndGet(); + int incremented = taskCount.incrementAndGet(); + moduleName = "JLeapp"; if (incremented == 1) { super.init(configurationManager); } - + Jep jep = super.getJep(); File aleappPath = getAleappScriptsDir(); @@ -177,10 +175,15 @@ public void init(ConfigurationManager configurationManager) throws Exception { @Override public void finish() throws Exception { + int decremented = taskCount.decrementAndGet(); + if (decremented == 0) { + logger.warn("ALeapp total plugin execution time:" + pluginTimeCounter.get()); + } } public void executePlugin(IItem evidence, LeapArtifactsPlugin p, List filesFound, File reportDumpPath) { Jep jep = getJep(); + Date plugginStart = new Date(); try { // some plugins depend on a sorted list Collections.sort(filesFound); @@ -239,6 +242,11 @@ public void executePlugin(IItem evidence, LeapArtifactsPlugin p, List fi } } finally { + Date plugginEnd = new Date(); + long delta = plugginEnd.getTime() - plugginStart.getTime(); + pluginTimeCounter.addAndGet((int) delta); + logger.warn("ALeapp plugin "+p.getName()+" execution time:"+delta); + // jep.close(); } } @@ -289,7 +297,7 @@ public void process(IItem evidence) throws Exception { subItem.setExtraAttribute(ExtraProperties.DECODED_DATA, true); worker.processNewItem(subItem); - // creates on subitem for each plugin execution + // creates one subitem for each plugin execution for (LeapArtifactsPlugin p : pluginsManager.getPlugins()) { Item psubItem = (Item) subItem.createChildItem(); ParentInfo pparentInfo = new ParentInfo(subItem); @@ -300,6 +308,7 @@ public void process(IItem evidence) throws Exception { psubItem.setSubItem(true); psubItem.setSubitemId(1); psubItem.getMetadata().set(ALEAPP_PLUGIN, moduleName); + psubItem.getMetadata().set(ALEAPP_ISPLUGIN, "true"); psubItem.setExtraAttribute(ExtraProperties.DECODED_DATA, true); worker.processNewItem(psubItem); } @@ -316,13 +325,14 @@ public void process(IItem evidence) throws Exception { worker.processNewItem(devDetailsSubItem); } - String pluginName = evidence.getMetadata().get(ALEAPP_PLUGIN); - if (pluginName != null) { + String isPlugin = evidence.getMetadata().get(ALEAPP_ISPLUGIN); + if (isPlugin != null && isPlugin.equals("true")) { int priority = worker.manager.getProcessingQueues().getCurrentQueuePriority(); if (priority < START_QUEUE_PRIORITY) { reEnqueueItem(evidence, START_QUEUE_PRIORITY); throw new ItemReEnqueuedException(); } else { + String pluginName = evidence.getMetadata().get(ALEAPP_PLUGIN); LeapArtifactsPlugin p = pluginsManager.getPlugin(pluginName); processEvidence(evidence, p); } @@ -582,4 +592,11 @@ protected void loadScript(Jep jep, boolean init) throws JepException { jep.eval("import sys"); } + @Override + public List> getConfigurables() { + ArrayList> c = new ArrayList>(); + c.add(new ALeappConfig()); + return c; + } + } \ No newline at end of file