Commit da6a3f0a authored by Nicolas Dolet's avatar Nicolas Dolet

Add a bench intent module

parent 180733dc
<?xml version="1.0"?>
<!--
* OW2 FraSCAti - Bench Intent.
*
* Copyright (c) 2008-2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ow2.frascati.intent</groupId>
<artifactId>frascati-bench</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Bench intent</name>
<parent>
<groupId>org.ow2.frascati.intent</groupId>
<artifactId>parent</artifactId>
<version>0.2-SNAPSHOT</version>
</parent>
<build>
<plugins>
<!-- To compile Java 5.0 source code. -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.ow2.frascati.factory</groupId>
<artifactId>frascati-factory-plugin</artifactId>
<version>0.6-SNAPSHOT</version>
<executions>
<execution>
<id>generate-factory</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<factory>GenerateFactory</factory>
<srcs>
<src>src/main/java</src>
<src>src/main/resources</src>
</srcs>
<composite>frascati.bench.composite</composite>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-runtime</artifactId>
<version>0.4.5-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Bench intent
* Copyright (C) 2008-2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Nicolas Dolet
*/
package org.ow2.frascati.intent.bench;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.util.Fractal;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.ow2.frascati.tinfi.control.intent.IntentJoinPoint;
/**
* {@link IntentHandler} implementation for a simple bench
*
* @author <a href="mailto:nicolas.dolet@inria.fr">Nicolas Dolet</a>
* @version $Revision$
*/
@Scope("COMPOSITE")
public class BenchIntentHandler
implements IntentHandler {
/**
* Bench intents to manage
*/
protected static Map<Component,Long> components = new HashMap<Component,Long>();
/**
* Print the benchmark
* @throws Throwable
*/
public static void printBench() {
System.out.println("#====================================================");
System.out.println("# BENCHMARK REPORT");
for(Component c : components.keySet()) {
Long bench = components.get(c);
String name;
try {
name = Fractal.getNameController(c).getFcName();
} catch (NoSuchInterfaceException e) {
// TODO Auto-generated catch block
name = " ## WARNING # can't get component name ##";
}
System.out.println("#=======");
System.out.println("| component: " + name);
System.out.println("| has run \t" + bench + " milliseconds.");
System.out.println("#=======");
}
}
// --------------------------------------------------------------------------
// Implementation of the IntentHandler interface
// --------------------------------------------------------------------------
/**
* @see org.ow2.frascati.tinfi.control.intent.IntentHandler#invoke(IntentJoinPoint)
*/
public Object invoke(IntentJoinPoint ijp) throws Throwable {
Object ret;
Component c = ((Interface) ijp.getComponentContext()).getFcItfOwner();
if(components.get(c) == null) {
components.put(c, new Long(0));
}
// Get time before proceed
long before = GregorianCalendar.getInstance().getTimeInMillis();
ret = ijp.proceed();
// Get time after proceed
long after = GregorianCalendar.getInstance().getTimeInMillis();
// increment elapsed time
long elapsed = after - before;
Long newBench = components.get(c) + Long.valueOf(elapsed);
components.put(c, newBench);
return ret;
}
}
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Bench Intent -->
<!-- Copyright (C) 2009 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Nicolas Dolet -->
<!-- -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:hw="http://bench-intent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="frascati.bench">
<service name="intent" promote="benchIntentHandler/bench">
<interface.java interface="org.ow2.frascati.tinfi.control.intent.IntentHandler"/>
</service>
<component name="benchIntentHandler">
<service name="bench">
<interface.java interface="org.ow2.frascati.tinfi.control.intent.IntentHandler"/>
</service>
<implementation.java class="org.ow2.frascati.intent.bench.BenchIntentHandler"/>
</component>
</composite>
......@@ -31,6 +31,7 @@
<version>0.2-SNAPSHOT</version>
<modules>
<module>debug</module>
<module>bench</module>
</modules>
<distributionManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment