summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/logging-tracing-and-timing-in-tuscany.html
blob: 0e83d2b5eee281ca39730d3a087c2675a1995949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE- 2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
    <HEAD>
		<!-- generateKeywords macro -->
	    <META name="description" content="Apache Tuscany">
        <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture,  sca, service component architecture, das, sdo, csa, ruby, opensource">
		<!-- generateKeywords macro end -->
		
        <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css">
        <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico">   
        <TITLE>Apache Tuscany : Logging, Tracing, and Timing in Tuscany</TITLE>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
    
    <BODY onload="init()">
        <!-- topNav macro -->
		<TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg">
			<TR>
				<TD valing="top" align="left">
					<A href="https://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A>
				</TD>
				<TD>
					<A href="http://tuscany.apache.org/"><IMG src="http://tuscany.apache.org/images/TuscanyLogo.jpg" border="0"></A>
				</TD>
				
				<TD width="100%">
					&nbsp;
				</TD>

				<!-- Adds the edit page link to the top banner-->
				<TD valign="bottom">
					<DIV style="padding: 2px 10px; margin: 0px;">
						<A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=100038">
						<IMG src="http://tuscany.apache.org/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
					</DIV>
				</TD>

			</TR>
		</TABLE>
        <!-- topNav macro end -->

		<!-- breadCrumbs macro -->
		<TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
			<TR class="topBar">
				<TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
					&nbsp;<A href="home.html" title="Apache Tuscany">Apache Tuscany</A>&nbsp;&gt;&nbsp;<A href="home.html" title="Home">Home</A>&nbsp;&gt;&nbsp;<A href="sca-overview.html" title="SCA Overview">SCA Overview</A>&nbsp;&gt;&nbsp;<A href="sca-java.html" title="SCA Java">SCA Java</A>&nbsp;&gt;&nbsp;<A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Java SCA Documentation Menu</A>&nbsp;&gt;&nbsp;<A href="sca-java-development-guide.html" title="SCA Java Development Guide">SCA Java Development Guide</A>&nbsp;&gt;&nbsp;<A href="" title="Logging, Tracing, and Timing in Tuscany">Logging, Tracing, and Timing in Tuscany</A>
				</TD>
				
				<TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
				<A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>&nbsp;&nbsp;
				</TD>
			</TR>
		</TABLE>
		<!-- breadCrumbs macro end -->


        <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
            <TR>
                <TD align="left" valign="top">

					<!-- pageContent macro -->
					<DIV id="PageContent">
												
						<DIV class="pagecontent">
							<DIV class="wiki-content">
								<H1><A name="Logging%2CTracing%2CandTiminginTuscany-TuscanyLogging%2CTracing%2CTimingInformation"></A>Tuscany Logging, Tracing, Timing Information</H1>

<P>This page describes the logging, tracing, and timing features of Tuscany. These features can be used to debug problems with the Tuscany runtime, understand code flow, and provide timing metrics for competitive analysis or performance claims.</P>

<H2><A name="Logging%2CTracing%2CandTiminginTuscany-JavaLoggingversusAspectOrientedProgramming%28AOP%29Approach"></A>Java Logging versus Aspect Oriented Programming (AOP) Approach</H2>

<P>There are two types of logging embeded in the Tuscany runtime: explicit and implicit. The explicit logging is implemented by the Java 2 SE core logging facilities such as java.util.logging.Logger. This is the logging that many Java programmers are familiar with, and the logging requires calls to the Logger programming interface. Throughout the Tuscany code base you see calls to this facility such as this call in Tuscany org.apache.tuscany.sca.node.launcher.NodeLauncher.</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Java Logging in Tuscany</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">        logger.info(<SPAN class="code-quote">&quot;Apache Tuscany SCA Node is starting...&quot;</SPAN>);
</PRE>
</DIV></DIV>
<P>Calls to this facility by default go to the standard output of the program. This is the typical result that one sees in the console:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Java Logging Output</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">INFO: Apache Tuscany SCA Node is starting...
</PRE>
</DIV></DIV>
<P>The Java SE core logging works well as a general purpose logger and gives a general idea of the important phases in the Tuscany runtime. However, one drawback is that this logging system only publishes predetermined messages created by the developers. If you wish to change the logging points, you must change the Tuscany source code, build, and run again with your private code base.</P>

<P>Another logging and tracing facility is available in Tuscany that gives the user a bit of flexibility in what gets logged and requires no source code modifications to run. This is an Aspect Oriented Programming (AOP) approach that runs via a Java agent at runtime. Just like a debugger can start and stop and inspect a Tuscany Java program, so too can an AOP agent inspect and report on a Tuscany Java program. Tuscany employs the AspectJ implementation, and its runtime agent is contained in the aspectjweaver.jar file. The AOP agent is specified from a command line option or runtime options:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Java AOP Agent</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">java -javaagent:<SPAN class="code-quote">&quot;&lt;path to aspectjweaver.jar&gt;&quot;</SPAN> calculator.CalculatorClient
</PRE>
</DIV></DIV>
<P>The AOP logging and tracing agent can be run with any Tuscany program. No additional calls or log statements need be added to the Tuscany code. The results of running a timing for example, look like this:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany AOP Output</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">Running org.apache.tuscany.sca.aspectj.TracingTestCase
Timing Around timedSection jp=call(void java.util.logging.Logger.info(<SPAN class="code-object">String</SPAN>))
Oct 21, 2008 9:26:36 AM org.apache.tuscany.sca.aspectj.TracingTestCase info_aroundBody0
Timing Around timedSection Roundtrip is 32ms <SPAN class="code-keyword">for</SPAN> jp.getSignature=void java.util.logging.Logger.info(<SPAN class="code-object">String</SPAN>)
</PRE>
</DIV></DIV>
<P>Full documentation on AspectJ is available at the <A href="http://www.eclipse.org/aspectj/doc/released" class="external-link" rel="nofollow">AspectJ web site</A>. Tuscany provides example usage in the module tracing-aspectj in the build tree and the released code.</P>

<H2><A name="Logging%2CTracing%2CandTiminginTuscany-BriefApectOrientedProgrammingIntroduction"></A>Brief Apect Oriented Programming Introduction</H2>

<P>In order to understand the aspect oriented approach to logging in Tuscany, one must understand a few basic concepts.</P>

<P>A <EM>join point</EM> is well defined point in the program flow. An example join point is the entry to a Java method. Another is after an exception is thrown. These join points contain useful information when running a program such as the argument list, the call stack, and the signature of the point that is executing.</P>

<P>A <EM>point cut</EM> is a subset of all the program join points. For instance, a point cut might be only the join points from exceptions thrown by the Tuscany runtime. Or only the set of calls to a Tuscany API org.apache.tuscany.sca.node.launcher.NodeLauncher.</P>

<P><EM>Advice</EM> is the code that is run when a point cut is reached. For instance, your advice might want to print out all the arguments when entering a given method. Or your advice might show the call stack of an exception and print the original cause of the exception.</P>

<P>Finally, an <EM>aspect</EM> is a module that bundles up a particular set of point cuts and advice. Here is an example aspect that is marked with Java 5 annotations. The name of the aspect is <EM>LoggingAspect</EM>, there is a point cut defined at Tuscany calls to org.apache.tuscany.sca.&#42; classes (but not inside of Aspect classes), and when the point cut is run, the advice for this point cut prints out the join point signature.</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Example Aspect</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">@Aspect
<SPAN class="code-keyword">public</SPAN> class LoggingAspect {
    @Pointcut(<SPAN class="code-quote">&quot;call(* org.apache.tuscany.sca..*(..)) &amp;&amp; (!within(org.apache.tuscany.sca.aspectj.*Aspect))&quot;</SPAN>)
    <SPAN class="code-keyword">public</SPAN> void anyMethodCall() {
    }

    @Before(<SPAN class="code-quote">&quot;anyMethodCall()&quot;</SPAN>)
    <SPAN class="code-keyword">public</SPAN> void before(JoinPoint jp) {
        <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;Logging Before anyMethodCall jp.getSignature=&quot;</SPAN> + jp.getSignature());
    }
}
</PRE>
</DIV></DIV>
<P>Full explanation of these concepts are in the AspectJ documents. The purpose here is to provide enough information to allow a user to run or modify the Tuscany aspects to one's liking.</P>

<H2><A name="Logging%2CTracing%2CandTiminginTuscany-LoggingandTracinginTuscany"></A>Logging and Tracing in Tuscany</H2>

<P>Following the approach of AspectJ, Tuscany provides two concrete aspects for logging and tracing. org.apache.tuscany.sca.aspectj.LoggingAspect provides logging for methods, constructors, and static initializers in Tuscany. org.apache.tuscany.sca.aspectj.SimpleTracingAspect provide tracing into user methods, constructors, and static initializers. Both provide detailed information when an Exception or Throwable is thrown by the Tuscany runtime or user SCA program.</P>

<P>Both LoggingAspect and SimpleTracingAspect are run by naming the AspectJ runtime agent aspectjweaver.jar at launch. This is shown in the command line example above, and an example is provided in launcher.bat in the tracing-aspectj module.</P>

<P>The runtime configuration file aop.xml has references to these aspects. Uncomment one or both of these in aop.xml to run with this logging enabled.  Following is an example logging run with the verbose weaver option specified. Note the verbose output of class names, build times, etc. The logging statements too are quite verbose stating the name of the join point, the point cut, and various signatures and arguments.</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Example Logging in Tuscany</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">[INFO] Configured Artifact: org.aspectj:aspectjweaver:1.6.1:jar
[INFO] Copying aspectjweaver-1.6.1.jar to E:\t\java\sca\modules\tracing-aspectj\target\dependency\aspectjweaver-1.6.1.jar
[AppClassLoader@92e78c] info AspectJ Weaver Version 1.6.1 built on Thursday Jul 3, 2008 at 18:35:41 GMT
[AppClassLoader@92e78c] info register classloader sun.misc.Launcher$AppClassLoader@92e78c
[AppClassLoader@92e78c] info using configuration /E:/t/java/sca/modules/tracing-aspectj/target/classes/META-INF/aop.xml
[AppClassLoader@92e78c] info register aspect org.apache.tuscany.sca.aspectj.LoggingAspect
[AppClassLoader@92e78c] info define aspect org.apache.tuscany.sca.aspectj.UserTimingAspect

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Logging Before anyMethodCall jp.getSignature=SCANodeFactory org.apache.tuscany.sca.node.SCANodeFactory.newInstance()
Logging Before anyConstructor jp.getSignature=org.apache.tuscany.sca.extensibility.ServiceDiscovery()
Logging Before anyConstructor jp.getSignature=org.apache.tuscany.sca.extensibility.ServiceDiscovery.1(ServiceDiscovery, <SPAN class="code-object">Class</SPAN>)
Logging Before anyConstructor jp.getArgs=[org.apache.tuscany.sca.extensibility.ServiceDiscovery@ceb6dd,
   class org.apache.tuscany.sca.node.SCANodeFactory]
Logging Before anyMethodCall jp.getSignature=ServiceDiscoverer org.apache.tuscany.sca.extensibility.ServiceDiscovery.getServiceDiscoverer()
Logging Before anyConstructor jp.getSignature=org.apache.tuscany.sca.extensibility.ContextClassLoaderServiceDiscoverer()
Logging AfterReturning anyMethodCall jp=call(ServiceDiscoverer org.apache.tuscany.sca.extensibility.ServiceDiscovery.getServiceDiscoverer()),
   result=org.apache.tuscany.sca.extensibility.ContextClassLoaderServiceDiscoverer@17574b9
Logging Before anyMethodCall jp.getSignature=Set org.apache.tuscany.sca.extensibility.ServiceDiscoverer.discover(<SPAN class="code-object">String</SPAN>, <SPAN class="code-object">boolean</SPAN>)
Logging Before anyMethodCall jp.getArgs=[org.apache.tuscany.sca.node.SCANodeFactory, <SPAN class="code-keyword">true</SPAN>]
</PRE>
</DIV></DIV>
<P>These aspects provide static point cuts and advice. That is, the various methods, constructors, and exception points are constrained by the source code of the aspects. You can change these items via editing LoggingAspect or SimpleTracingAspect and rerunning the application.</P>

<H2><A name="Logging%2CTracing%2CandTiminginTuscany-Timing"></A>Timing</H2>

<P>Timing of various calls is also available via the AOP logging and tracing facility in Tuscany. The apsect UserTimingAspect is provided to time certain point cuts. As shown above, this AOP timing feature can be used for timing metrics for competitive analysis of performance gauges. The output of the timing is shown here, as a Logger.info method is called and timed.</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany AOP Timing Output</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">Running org.apache.tuscany.sca.aspectj.TracingTestCase
Timing Around timedSection jp=call(void java.util.logging.Logger.info(<SPAN class="code-object">String</SPAN>))
Oct 21, 2008 9:26:36 AM org.apache.tuscany.sca.aspectj.TracingTestCase info_aroundBody0
Timing Around timedSection Roundtrip is 32ms <SPAN class="code-keyword">for</SPAN> jp.getSignature=void java.util.logging.Logger.info(<SPAN class="code-object">String</SPAN>)
</PRE>
</DIV></DIV>
<P>Unlike LoggingAspect and SimpleTracingAspect, the pointcut for UserTimingAspect is settable at runtime via the aop.xml runtime configuration file. Look for the UserTimingAspect name, and note the expression in the pointcut element. You may change the name of expression to any valid AspectJ pointcut expression. Here calls to any Logger.info methods, regardless of arguments or return types are logged. For instance you may change this to &quot;call( * calculator.CalculatorServiceImpl.multiply(..))&quot; to time calls in your SCA application.</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Dynamic PointCut for UserTimingAspect</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">        &lt;concrete-aspect name=<SPAN class="code-quote">&quot;org.apache.tuscany.sca.aspectj.UserTimingAspect&quot;</SPAN>
           <SPAN class="code-keyword">extends</SPAN>=<SPAN class="code-quote">&quot;org.apache.tuscany.sca.aspectj.TimingAspect&quot;</SPAN>
           precedence=<SPAN class="code-quote">&quot;org.apache.tuscany.sca.aspectj.UserTimingAspect, *&quot;</SPAN>&gt;
           &lt;pointcut name=<SPAN class="code-quote">&quot;timedCall&quot;</SPAN>
              expression=<SPAN class="code-quote">&quot;call(* java.util.logging.Logger.info(..))&quot;</SPAN>/&gt;
        &lt;/concrete-aspect&gt;
</PRE>
</DIV></DIV>

<H2><A name="Logging%2CTracing%2CandTiminginTuscany-LoggingandTracinginAlternateContainers"></A>Logging and Tracing in Alternate Containers</H2>

<P>So far this article discussed logging and tracing for Tuscany applications. Often Tuscany applications are run standalone in a Java 2 SE environment. You can also turn on logging and tracing in various application servers that support Tuscany SCA applications.</P>

<H3><A name="Logging%2CTracing%2CandTiminginTuscany-ApacheTomcatExample"></A>Apache Tomcat Example</H3>

<P>Show Apache Tomcat J2EE application server plus Tuscany bundled SCA application.</P>

<H3><A name="Logging%2CTracing%2CandTiminginTuscany-WebSphereExample"></A>WebSphere Example</H3>

<P>Show WebSphere 7.0.0.1 plus SOA Feature Pack based on Tuscany output.</P>
							</DIV>
						</DIV>
					</DIV>	
		            <!-- pageContent macro end -->
					
                </TD>
            </TR>
        </TABLE>

		<!-- footer macro -->
				<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
		</SCRIPT>
		<SCRIPT type="text/javascript">
		   _uacct = "UA-1174707-5";
		   urchinTracker();
		</SCRIPT>
		
				<A href="http://www.statcounter.com/" target="_blank"><IMG src="http://c26.statcounter.com/counter.php?sc_project=2619156&java=0&security=94bd7e7d&invisible=0" alt="website stats" border="0"></A>    

		<DIV class="footer">
			Copyright � 2003-2012, The Apache Software Foundation&nbsp;&nbsp;</BR>
                        Apache Tuscany and the Apache Tuscany project logo are trademarks of The Apache Software Foundation.
		</DIV>
		<!-- footer macro end -->

    </BODY>
</HTML>