Skip to content

Commit

Permalink
added tracing example
Browse files Browse the repository at this point in the history
- added system fragment
- added tracing demo project

Signed-off-by: Mark Hoffmann <m.hoffmann@data-in-motion.biz>
  • Loading branch information
maho7791 committed Sep 5, 2023
1 parent e2fd3fd commit ee5f774
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cnf/central.maven
Expand Up @@ -183,4 +183,9 @@ org.jline:jline-builtins:3.22.0
org.jline:jline-reader:3.22.0
org.jline:jline-console:3.22.0
org.jline:jline-terminal:3.22.0
org.eclipse.parsson:jakarta.json:1.1.2
org.eclipse.parsson:jakarta.json:1.1.2#

#
biz.aQute:biz.aQute.trace.gui:1.9.0
biz.aQute:biz.aQute.trace.runpath:1.9.0
biz.aQute:biz.aQute.trace.tester:1.9.0
11 changes: 11 additions & 0 deletions org.gecko.playground.tracing.fragment/.classpath
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
32 changes: 32 additions & 0 deletions org.gecko.playground.tracing.fragment/README.MD
@@ -0,0 +1,32 @@
# aQute Tracing System Fragment

[Github](https://github.com/aQute-os/biz.aQute.osgi.util/tree/master/biz.aQute.trace)
[Maven](https://repo1.maven.org/maven2/biz/aQute/biz.aQute.trace.runpath/)

This is a small tool that creates metrics for typical startup and teardown methods:

* Activator#start
* Activator#stop
* Component#activate
* Component#deactivate

This is an example how to repackage it and making it a framework fragment

## The Framework Fragment

The *org.gecko.playground.tracing.fragment* be placed in the application. This is a Framework fragment. This means a fragment for the system bundle.
Its activator should be called as well. So with this the tracer is started very early.

It is important to know, that this fragment does not import foreign packages, except `org.osgi.framework`. It is also not allowed to export something.


## Gogo Commands

Further, to get some Gogo commands, the bundle *biz.aQute.trace.gui* can also be placed in the application (startlevel is unimportant here) you can then use the commands:

* *tracer* - show table of the measurements in the console
* *dump (html | json | text)* - create a currensponding dump in the console

E.g. the HTML dump creates a HTML page with all results.

The *bndrun* shows, how to start it.
16 changes: 16 additions & 0 deletions org.gecko.playground.tracing.fragment/bnd.bnd
@@ -0,0 +1,16 @@
Fragment-Host: system.bundle
Bundle-Activator: biz.aQute.trace.runpath.impl.Activator

-buildpath: \
biz.aQute.trace.runpath,\
aQute.libg

-conditionalpackage: \
javassist.*,\
biz.*,\
aQute.*

Import-Package: \
sun.*;'resolution:'=optional,\
jdk.*;'resolution:'=optional,\
*
37 changes: 37 additions & 0 deletions org.gecko.playground.tracing.fragment/launch.bndrun
@@ -0,0 +1,37 @@
-runfw: org.eclipse.osgi;version=3.13
-runee: JavaSE-17
-runprovidedcapabilities: ${native_capability}

-resolve.effective: active

-runproperties: \
osgi.console.enable.builtin=false,\
osgi.console=

-runpath=biz.aQute.trace.runpath

-runrequires: \
bnd.identity;id='org.gecko.playground.tracing.fragment',\
bnd.identity;id='org.gecko.playground.tracing',\
bnd.identity;id='org.apache.felix.gogo.runtime',\
bnd.identity;id='org.apache.felix.gogo.command',\
bnd.identity;id='biz.aQute.trace.gui'

#-runbundles+: \
# biz.aQute.trace.runpath;startlevel=1,\
# *;startlevel=4
-runbundles: \
aQute.libg;version='[6.4.0,6.4.1)',\
org.apache.felix.scr;version='[2.2.6,2.2.7)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
slf4j.api;version='[1.7.30,1.7.31)',\
slf4j.simple;version='[1.7.30,1.7.31)',\
biz.aQute.trace.gui;version='[1.9.0,1.9.1)',\
org.gecko.playground.tracing;version=snapshot,\
org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',\
org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',\
org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)',\
org.apache.felix.inventory;version='[1.0.6,1.0.7)',\
org.gecko.playground.tracing.fragment;version=snapshot
11 changes: 11 additions & 0 deletions org.gecko.playground.tracing/.classpath
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
encoding/bnd.bnd=UTF-8
10 changes: 10 additions & 0 deletions org.gecko.playground.tracing/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
31 changes: 31 additions & 0 deletions org.gecko.playground.tracing/README.MD
@@ -0,0 +1,31 @@
# aQute Tracing

[Github](https://github.com/aQute-os/biz.aQute.osgi.util/tree/master/biz.aQute.trace)
[Maven](https://repo1.maven.org/maven2/biz/aQute/biz.aQute.trace.runpath/)

This is a small tool that creates metrics for typical startup and teardown methods:

* Activator#start
* Activator#stop
* Component#activate
* Component#deactivate

## In bndtools

Just follow the instruction on Github.

## Non bnd-Environment

In non-bnd environment there is the *org.gecko.playground.tracing.fragement*. It should be placed in the application. This is a Framework frageent, means a fragment for the system bundle.
Its activator should be called as well.

Refer to that project

## Gogo Commands

Further, to get some Gogo commands, the bundle *biz.aQute.trace.gui* can also be placed in the application (startlevel is unimportant here) you can then use the commands:

* *tracer* - show table of the measurements in the console
* *dump (html | json | text)* - create a currensponding dump in the console

E.g. the HTML dump creates a HTML page with all results.
1 change: 1 addition & 0 deletions org.gecko.playground.tracing/bnd.bnd
@@ -0,0 +1 @@
-buildpath: org.osgi.util.promise;version=latest
36 changes: 36 additions & 0 deletions org.gecko.playground.tracing/launch.bndrun
@@ -0,0 +1,36 @@
-runfw: org.eclipse.osgi;version=3.13
-runee: JavaSE-17
-runprovidedcapabilities: ${native_capability}

-resolve.effective: active

-runproperties: \
osgi.console.enable.builtin=false,\
osgi.console=

-runpath=biz.aQute.trace.runpath

-runrequires: \
bnd.identity;id='org.gecko.playground.tracing',\
bnd.identity;id='org.apache.felix.gogo.runtime',\
bnd.identity;id='org.apache.felix.gogo.command',\
bnd.identity;id='biz.aQute.trace.runpath',\
bnd.identity;id='biz.aQute.trace.gui'

#-runbundles+: \
# biz.aQute.trace.runpath;startlevel=1,\
# *;startlevel=4
-runbundles: \
aQute.libg;version='[6.4.0,6.4.1)',\
org.apache.felix.scr;version='[2.2.6,2.2.7)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
slf4j.api;version='[1.7.30,1.7.31)',\
slf4j.simple;version='[1.7.30,1.7.31)',\
biz.aQute.trace.gui;version='[1.9.0,1.9.1)',\
org.gecko.playground.tracing;version=snapshot,\
org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',\
org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',\
org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)',\
org.apache.felix.inventory;version='[1.0.6,1.0.7)'
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2012 - 2023 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package org.gecko.playground.tracing;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;

/**
*
* @author mark
* @since 05.09.2023
*/
@Component
public class LongActivationComponent {

@Activate
public void activate() {
try {
System.out.println("Activate long ...");
Thread.sleep(750);
System.out.println("Activated long");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Deactivate
public void deactivate() {
try {
System.out.println("De-activate long ...");
Thread.sleep(350);
System.out.println("De-activated long");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2012 - 2023 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package org.gecko.playground.tracing;

import java.util.concurrent.Executors;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.util.promise.PromiseFactory;

/**
*
* @author mark
* @since 05.09.2023
*/
@Component
public class LongPromiseActivationComponent {

private final PromiseFactory pf = new PromiseFactory(Executors.newCachedThreadPool());

@Activate
public void activate() {
pf.submit(()->{
System.out.println("Activate long promise ...");
Thread.sleep(750);
return null;
}).onResolve(()->System.out.println("Activated long promise"));
}

@Deactivate
public void deactivate() {
pf.submit(()->{
System.out.println("De-activate long promise ...");
Thread.sleep(350);
return null;
}).onResolve(()->System.out.println("De-activated long promise"));
}

}
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2012 - 2023 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package org.gecko.playground.tracing;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;

/**
*
* @author mark
* @since 05.09.2023
*/
@Component
public class NotSoLongActivationComponent {

@Activate
public void activate() {
try {
System.out.println("Activate not so long ...");
Thread.sleep(150);
System.out.println("Activated not so long");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Deactivate
public void deactivate() {
try {
System.out.println("De-activate not so long ...");
Thread.sleep(150);
System.out.println("De-activated not so long");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

0 comments on commit ee5f774

Please sign in to comment.