Import lttng.kernel.core plugins from Scope
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / core / activator / internal / LttngAnalysesLoader.java
CommitLineData
af3275f8
AM
1/*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Philippe Proulx
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10package org.lttng.scope.lttng.kernel.core.activator.internal;
11
12import java.io.IOException;
13import java.io.InputStream;
14import java.util.Properties;
15
16import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisManager;
17import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
18import org.lttng.scope.lami.core.module.LamiAnalysis;
19import org.lttng.scope.lami.core.module.LamiAnalysisFactoryException;
20import org.lttng.scope.lami.core.module.LamiAnalysisFactoryFromConfigFile;
21import org.lttng.scope.lttng.kernel.core.trace.LttngKernelTrace;
22import org.lttng.scope.lttng.kernel.core.trace.layout.ILttngKernelEventLayout;
23import org.lttng.scope.lttng.kernel.core.trace.layout.internal.Lttng27EventLayout;
24
25/**
26 * Loader of LTTng analyses.
27 *
28 * @author Philippe Proulx
29 */
30final class LttngAnalysesLoader {
31
32 private static final String CONFIG_DIR_NAME = "lttng-analyses-configs"; //$NON-NLS-1$
33
34 private LttngAnalysesLoader() {
35 }
36
37 private static boolean appliesTo(ITmfTrace trace) {
38 /* LTTng-Analysis is supported only on LTTng >= 2.7 kernel traces */
39 if (trace instanceof LttngKernelTrace) {
40 final LttngKernelTrace kernelTrace = (LttngKernelTrace) trace;
41 final ILttngKernelEventLayout layout = kernelTrace.getKernelEventLayout();
42
43 if (layout instanceof Lttng27EventLayout) {
44 return true;
45 }
46 }
47
48 return false;
49 }
50
51 private static String[] getAnalysisNames() throws IOException {
52 final ClassLoader loader = LttngAnalysesLoader.class.getClassLoader();
53 final String path = "/" + CONFIG_DIR_NAME + "/index.properties"; //$NON-NLS-1$ //$NON-NLS-2$
54 final String[] names = new String[0];
55 final Properties indexProps = new Properties();
56
57 try (final InputStream in = loader.getResourceAsStream(path)) {
58 if (in == null) {
59 return names;
60 }
61
62 indexProps.load(in);
63 }
64
65 String analyses = indexProps.getProperty("analyses"); //$NON-NLS-1$
66
67 if (analyses == null) {
68 return names;
69 }
70
71 analyses = analyses.trim();
72 return analyses.split("\\s+"); //$NON-NLS-1$
73 }
74
75 public static void load() throws LamiAnalysisFactoryException, IOException {
76 final String[] names = getAnalysisNames();
77 final ClassLoader loader = LttngAnalysesLoader.class.getClassLoader();
78
79 for (final String name : names) {
80 final String path = String.format("/%s/%s.properties", CONFIG_DIR_NAME, name); //$NON-NLS-1$
81
82 try (final InputStream in = loader.getResourceAsStream(path)) {
83 if (in == null) {
84 continue;
85 }
86
87 final LamiAnalysis analysis = LamiAnalysisFactoryFromConfigFile.buildFromInputStream(in, false, LttngAnalysesLoader::appliesTo);
88 OnDemandAnalysisManager.getInstance().registerAnalysis(analysis);
89 }
90 }
91 }
92
93}
This page took 0.027073 seconds and 5 git commands to generate.