1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Philippe Proulx
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 *******************************************************************************/
10 package org
.lttng
.scope
.lttng
.kernel
.core
.activator
.internal
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
14 import java
.util
.Properties
;
16 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.ondemand
.OnDemandAnalysisManager
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
18 import org
.lttng
.scope
.lami
.core
.module
.LamiAnalysis
;
19 import org
.lttng
.scope
.lami
.core
.module
.LamiAnalysisFactoryException
;
20 import org
.lttng
.scope
.lami
.core
.module
.LamiAnalysisFactoryFromConfigFile
;
21 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.LttngKernelTrace
;
22 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.ILttngKernelEventLayout
;
23 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.internal
.Lttng27EventLayout
;
26 * Loader of LTTng analyses.
28 * @author Philippe Proulx
30 final class LttngAnalysesLoader
{
32 private static final String CONFIG_DIR_NAME
= "lttng-analyses-configs"; //$NON-NLS-1$
34 private LttngAnalysesLoader() {
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();
43 if (layout
instanceof Lttng27EventLayout
) {
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();
57 try (final InputStream in
= loader
.getResourceAsStream(path
)) {
65 String analyses
= indexProps
.getProperty("analyses"); //$NON-NLS-1$
67 if (analyses
== null) {
71 analyses
= analyses
.trim();
72 return analyses
.split("\\s+"); //$NON-NLS-1$
75 public static void load() throws LamiAnalysisFactoryException
, IOException
{
76 final String
[] names
= getAnalysisNames();
77 final ClassLoader loader
= LttngAnalysesLoader
.class.getClassLoader();
79 for (final String name
: names
) {
80 final String path
= String
.format("/%s/%s.properties", CONFIG_DIR_NAME
, name
); //$NON-NLS-1$
82 try (final InputStream in
= loader
.getResourceAsStream(path
)) {
87 final LamiAnalysis analysis
= LamiAnalysisFactoryFromConfigFile
.buildFromInputStream(in
, false, LttngAnalysesLoader
::appliesTo
);
88 OnDemandAnalysisManager
.getInstance().registerAnalysis(analysis
);