qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [06/10] qpid-proton git commit: PROTON-956: avoid overhead of creating frame and payload duplicate objects for logging or tracing if the logging is disabled and there is no tracer
Date Thu, 23 Jul 2015 12:06:09 GMT
PROTON-956: avoid overhead of creating frame and payload duplicate objects for logging or tracing
if the logging is disabled and there is no tracer


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/13682652
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/13682652
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/13682652

Branch: refs/heads/master
Commit: 13682652f635544e82c29aa16654fe5031a143db
Parents: b0f3a98
Author: Robert Gemmell <robbie@apache.org>
Authored: Thu Jul 23 12:56:41 2015 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Thu Jul 23 12:56:41 2015 +0100

----------------------------------------------------------------------
 .../qpid/proton/engine/impl/FrameWriter.java    | 35 +++++++++++---------
 .../qpid/proton/engine/impl/TransportImpl.java  |  7 +++-
 2 files changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13682652/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
index b23932a..4c2cc9d 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
@@ -154,23 +154,28 @@ class FrameWriter
         }
         int payloadSize = Math.min(payload == null ? 0 : payload.remaining(), capacity);
 
-        ByteBuffer originalPayload = null;
-        if( payload!=null )
+        ProtocolTracer tracer = _protocolTracer == null ? null : _protocolTracer.get();
+        if( tracer != null || _transport.isTraceFramesEnabled())
         {
-            originalPayload = payload.duplicate();
-            originalPayload.limit(payload.position() + payloadSize);
-        }
-
-        // XXX: this is a bit of a hack but it eliminates duplicate
-        // code, further refactor will fix this
-        if (_frameType == AMQP_FRAME_TYPE) {
-            TransportFrame frame = new TransportFrame(channel, (FrameBody) frameBody, Binary.create(originalPayload));
-            _transport.log(TransportImpl.OUTGOING, frame);
-
-            ProtocolTracer tracer = _protocolTracer.get();
-            if(tracer != null)
+            // XXX: this is a bit of a hack but it eliminates duplicate
+            // code, further refactor will fix this
+            if (_frameType == AMQP_FRAME_TYPE)
             {
-                tracer.sentFrame(frame);
+                ByteBuffer originalPayload = null;
+                if( payload!=null )
+                {
+                    originalPayload = payload.duplicate();
+                    originalPayload.limit(payload.position() + payloadSize);
+                }
+
+                Binary payloadBin = Binary.create(originalPayload);
+                TransportFrame frame = new TransportFrame(channel, (FrameBody) frameBody,
payloadBin);
+                _transport.log(TransportImpl.OUTGOING, frame);
+
+                if(tracer != null)
+                {
+                    tracer.sentFrame(frame);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13682652/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
index 95a811b..3c472b0 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
@@ -1589,7 +1589,7 @@ public class TransportImpl extends EndpointImpl
 
     void log(String event, TransportFrame frame)
     {
-        if ((_levels & TRACE_FRM) != 0) {
+        if (isTraceFramesEnabled()) {
             StringBuilder msg = new StringBuilder();
             msg.append("[").append(System.identityHashCode(this)).append(":")
                 .append(frame.getChannel()).append("]");
@@ -1605,6 +1605,11 @@ public class TransportImpl extends EndpointImpl
         }
     }
 
+    boolean isTraceFramesEnabled()
+    {
+        return (_levels & TRACE_FRM) != 0;
+    }
+
     @Override
     void localOpen() {}
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message