Search in sources :

Example 1 with CalledMethodLoader

use of de.dagere.peass.dependency.analysis.CalledMethodLoader in project peass by DaGeRe.

the class TestTraceMethodReader method testTraceLengthSimpleFor.

@Test
public void testTraceLengthSimpleFor() throws ParseException, IOException {
    System.out.println("Searching: " + SLF4J_API_JAR + " " + new File(SLF4J_API_JAR).exists());
    System.out.println("Searching: " + SLF4J_IMPL_JAR + " " + new File(SLF4J_IMPL_JAR).exists());
    String jarPath = getJarPath();
    String agentPath = getAgentPath();
    final ProcessBuilder builder = new ProcessBuilder("java", "-javaagent:" + agentPath, "-Dorg.aspectj.weaver.loadtime.configuration=file:src" + File.separator + "test" + File.separator + "resources" + File.separator + "aop.xml", "-cp", jarPath, "de.peass.example.CallerSimpleFor");
    System.out.println("Command: " + builder.command());
    final Process process = builder.start();
    StreamGobbler.showFullProcess(process);
    final File[] kiekerFolders = tmpFolder.listFiles((FileFilter) new WildcardFileFilter("kieker-*"));
    final File traceFolder = kiekerFolders[0];
    // 
    final TraceMethodReader reader = new TraceMethodReader(new CalledMethodLoader(traceFolder, ModuleClassMapping.SINGLE_MODULE_MAPPING, new KiekerConfig()).getShortTrace(""), new File("src" + File.separator + "test" + File.separator + "java"));
    final TraceWithMethods trace = reader.getTraceWithMethods();
    System.out.println(trace.getWholeTrace());
    /*
       * Trace: 20 Methodenaufrufe -> 10 sonstige -> 10 mal Schleife callMe2 -> müsste auf 1 Eintrag (callMe2, *10 Aufrufe) zusammenfasst werden -> Ziel: 11 Aufrufe
       */
    Assert.assertEquals(11, trace.getLength());
}
Also used : TraceWithMethods(de.dagere.peass.dependency.traces.TraceWithMethods) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) TraceMethodReader(de.dagere.peass.dependency.traces.TraceMethodReader) KiekerConfig(de.dagere.peass.config.KiekerConfig) CalledMethodLoader(de.dagere.peass.dependency.analysis.CalledMethodLoader) Test(org.junit.jupiter.api.Test)

Example 2 with CalledMethodLoader

use of de.dagere.peass.dependency.analysis.CalledMethodLoader in project peass by DaGeRe.

the class TraceGettingIT method executeReading.

public static void executeReading(final TestCase testcase, final File clazzDir, final Map<String, List<File>> traceFileMap, final String githash, final File kiekerResultFolder) throws ParseException, IOException {
    final ArrayList<TraceElement> shortTrace = new CalledMethodLoader(kiekerResultFolder, ModuleClassMapping.SINGLE_MODULE_MAPPING, new KiekerConfig()).getShortTrace("");
    LOG.debug("Short Trace: {}", shortTrace.size());
    final TraceMethodReader traceMethodReader = new TraceMethodReader(shortTrace, new File(TestConstants.CURRENT_FOLDER, "src/main/java"), new File(TestConstants.CURRENT_FOLDER, "src/java"), new File(TestConstants.CURRENT_FOLDER, "src/test/java"), new File(TestConstants.CURRENT_FOLDER, "src/test"));
    final TraceWithMethods trace = traceMethodReader.getTraceWithMethods();
    List<File> traceFile = traceFileMap.get(testcase.getMethod());
    if (traceFile == null) {
        traceFile = new LinkedList<>();
        traceFileMap.put(testcase.getMethod(), traceFile);
    }
    if (!clazzDir.exists()) {
        clazzDir.mkdirs();
    }
    final File currentTraceFile = new File(clazzDir, testcase.getMethod() + "_hash_" + githash);
    traceFile.add(currentTraceFile);
    try (final FileWriter fw = new FileWriter(currentTraceFile)) {
        fw.write(trace.getWholeTrace());
    }
    final File methodTrace = new File(clazzDir, testcase.getMethod() + "_hash_" + githash + "_method");
    try (final FileWriter fw = new FileWriter(methodTrace)) {
        LOG.debug("Methoden: " + trace.getTraceMethods().length());
        fw.write(trace.getTraceMethods());
    }
}
Also used : FileWriter(java.io.FileWriter) TraceElement(de.dagere.peass.dependency.analysis.data.TraceElement) TraceWithMethods(de.dagere.peass.dependency.traces.TraceWithMethods) KiekerConfig(de.dagere.peass.config.KiekerConfig) TraceMethodReader(de.dagere.peass.dependency.traces.TraceMethodReader) File(java.io.File) CalledMethodLoader(de.dagere.peass.dependency.analysis.CalledMethodLoader)

Example 3 with CalledMethodLoader

use of de.dagere.peass.dependency.analysis.CalledMethodLoader in project peass by DaGeRe.

the class OneTraceGenerator method generateTraceFiles.

private boolean generateTraceFiles(final String versionCurrent, final File[] kiekerResultFolders) throws FileNotFoundException, IOException, XmlPullParserException, com.github.javaparser.ParseException {
    boolean success = false;
    TraceWithMethods trace = null;
    TraceMethodReader traceMethodReader = null;
    int overallSizeInMb = 0;
    for (File kiekerResultFolder : kiekerResultFolders) {
        final long size = FileUtils.sizeOfDirectory(kiekerResultFolder);
        final long sizeInMB = size / (1024 * 1024);
        overallSizeInMb += sizeInMB;
        LOG.debug("Filesize: {} ({})", sizeInMB, size);
        if (sizeInMB < kiekerConfig.getTraceSizeInMb()) {
            CalledMethodLoader calledMethodLoader = new CalledMethodLoader(kiekerResultFolder, moduleClassMapping, kiekerConfig);
            final List<TraceElement> shortTrace = calledMethodLoader.getShortTrace("");
            if (shortTrace != null) {
                LOG.debug("Short Trace: {} Folder: {} Project: {}", shortTrace.size(), kiekerResultFolder.getAbsolutePath(), folders.getProjectFolder());
                if (shortTrace.size() > 0) {
                    traceMethodReader = new TraceMethodReader(shortTrace, classpathFolders.toArray(new File[0]));
                    if (trace == null) {
                        trace = traceMethodReader.getTraceWithMethods();
                    } else {
                        TraceWithMethods additionalTrace = traceMethodReader.getTraceWithMethods();
                        trace.append(additionalTrace);
                    }
                    success = true;
                } else {
                    LOG.error("Trace empty!");
                }
            }
        } else {
            LOG.error("File size exceeds {} MB", kiekerConfig.getTraceSizeInMb());
        }
    }
    if (success) {
        writeTrace(versionCurrent, overallSizeInMb, traceMethodReader, trace);
    }
    return success;
}
Also used : TraceElement(de.dagere.peass.dependency.analysis.data.TraceElement) File(java.io.File) CalledMethodLoader(de.dagere.peass.dependency.analysis.CalledMethodLoader)

Example 4 with CalledMethodLoader

use of de.dagere.peass.dependency.analysis.CalledMethodLoader in project peass by DaGeRe.

the class DependencyManager method getCalledMethods.

private Map<ChangedEntity, Set<String>> getCalledMethods(final ModuleClassMapping mapping, final File[] kiekerResultFolders) {
    final Map<ChangedEntity, Set<String>> allCalledClasses = new LinkedHashMap<ChangedEntity, Set<String>>();
    for (File kiekerResultFolder : kiekerResultFolders) {
        final long size = FileUtils.sizeOfDirectory(kiekerResultFolder);
        final long sizeInMB = size / (1024 * 1024);
        LOG.debug("Size: {} Folder: {}", sizeInMB, kiekerResultFolder);
        if (sizeInMB > fakeConfig.getKiekerConfig().getTraceSizeInMb()) {
            LOG.error("Trace too big!");
        } else {
            LOG.debug("Reading Kieker folder: {}", kiekerResultFolder.getAbsolutePath());
            CalledMethodLoader calledMethodLoader = new CalledMethodLoader(kiekerResultFolder, mapping, fakeConfig.getKiekerConfig());
            final Map<ChangedEntity, Set<String>> calledMethods = calledMethodLoader.getCalledMethods();
            for (Map.Entry<ChangedEntity, Set<String>> calledMethod : calledMethods.entrySet()) {
                if (!allCalledClasses.containsKey(calledMethod.getKey())) {
                    allCalledClasses.put(calledMethod.getKey(), calledMethod.getValue());
                } else {
                    Set<String> alreadyKnownCalledClasses = allCalledClasses.get(calledMethod.getKey());
                    alreadyKnownCalledClasses.addAll(calledMethod.getValue());
                }
            }
        }
    }
    return allCalledClasses;
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) TestSet(de.dagere.peass.dependency.analysis.data.TestSet) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) CalledMethodLoader(de.dagere.peass.dependency.analysis.CalledMethodLoader)

Example 5 with CalledMethodLoader

use of de.dagere.peass.dependency.analysis.CalledMethodLoader in project peass by DaGeRe.

the class TraceGeneratorStarter method writeTestcase.

private void writeTestcase(final String newestVersion, final PeassFolders folders, final KiekerResultManager resultsManager, final TestCase testcase) throws FileNotFoundException, IOException, XmlPullParserException, ViewNotFoundException {
    final File moduleResultFolder = KiekerFolderUtil.getModuleResultFolder(folders, testcase);
    final File kiekerResultFolder = KiekerFolderUtil.getClazzMethodFolder(testcase, moduleResultFolder)[0];
    final long size = FileUtils.sizeOfDirectory(kiekerResultFolder);
    final long sizeInMB = size / (1024 * 1024);
    if (sizeInMB < 100) {
        LOG.debug("Writing " + testcase);
        final List<TraceElement> shortTrace = new CalledMethodLoader(kiekerResultFolder, mapping, new KiekerConfig()).getShortTrace("");
        writeTrace(newestVersion, testcase, shortTrace);
    } else {
        LOG.info("Not writing " + testcase + " since size is " + sizeInMB + " mb");
    }
}
Also used : TraceElement(de.dagere.peass.dependency.analysis.data.TraceElement) File(java.io.File) KiekerConfig(de.dagere.peass.config.KiekerConfig) CalledMethodLoader(de.dagere.peass.dependency.analysis.CalledMethodLoader)

Aggregations

CalledMethodLoader (de.dagere.peass.dependency.analysis.CalledMethodLoader)7 File (java.io.File)7 KiekerConfig (de.dagere.peass.config.KiekerConfig)5 TraceElement (de.dagere.peass.dependency.analysis.data.TraceElement)4 TraceMethodReader (de.dagere.peass.dependency.traces.TraceMethodReader)3 TraceWithMethods (de.dagere.peass.dependency.traces.TraceWithMethods)3 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)2 Test (org.junit.jupiter.api.Test)2 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)1 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)1 PeassFolders (de.dagere.peass.folders.PeassFolders)1 FileWriter (java.io.FileWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1