lttng: Add configuration files to call LTTng-Analyses scripts
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / LttngAnalysesLoader.java
CommitLineData
83d1b60e
PP
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.eclipse.tracecompass.internal.lttng2.kernel.core;
11
12import java.io.IOException;
13import java.io.InputStream;
14import java.util.Properties;
15
16import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
17import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.Lttng27EventLayout;
18import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.ConfigFileLamiAnalysisFactory;
19import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.ConfigFileLamiAnalysisFactory.ConfigFileLamiAnalysisFactoryException;
20import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis;
21import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
22import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisManager;
23import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
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 LttngKernelTrace kernelTrace = (LttngKernelTrace) trace;
41 IKernelAnalysisEventLayout 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 ClassLoader loader = LttngAnalysesLoader.class.getClassLoader();
53 String path = "/" + CONFIG_DIR_NAME + "/index.properties"; //$NON-NLS-1$ //$NON-NLS-2$
54 String[] names = new String[0];
55 Properties indexProps = new Properties();
56
57 try (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 String[] splitNames = analyses.split("\\s+"); //$NON-NLS-1$
73
74 return splitNames;
75 }
76
77 public static void load() throws ConfigFileLamiAnalysisFactoryException, IOException {
78 String[] names = getAnalysisNames();
79 ClassLoader loader = LttngAnalysesLoader.class.getClassLoader();
80
81 for (String name : names) {
82 String path = String.format("/%s/%s.properties", CONFIG_DIR_NAME, name); //$NON-NLS-1$
83
84 try (InputStream in = loader.getResourceAsStream(path)) {
85 if (in == null) {
86 continue;
87 }
88
89 LamiAnalysis analysis = ConfigFileLamiAnalysisFactory.buildFromInputStream(in, false, LttngAnalysesLoader::appliesTo);
90 OnDemandAnalysisManager.getInstance().registerAnalysis(analysis);
91 }
92 }
93 }
94
95}
This page took 0.029077 seconds and 5 git commands to generate.