avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r980173 [4/4] - in /avro/trunk: ./ lang/java/ lang/java/src/java/org/apache/avro/ipc/stats/ lang/java/src/java/org/apache/avro/ipc/stats/static/ lang/java/src/java/org/apache/avro/ipc/stats/templates/ lang/java/src/test/java/org/apache/avro...
Date Wed, 28 Jul 2010 19:28:54 GMT
Added: avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.css
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.css?rev=980173&view=auto
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.css (added)
+++ avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.css Wed Jul 28 19:28:53
2010
@@ -0,0 +1,30 @@
+/*!
+ * The MIT License
+ * 
+ * Copyright (c) 2008 Jason Frame (jason@onehackoranother.com)
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+.tipsy { padding: 5px; font-size: 10px; opacity: 0.8; filter: alpha(opacity=80); background-repeat:
no-repeat;  background-image: url(../images/tipsy.gif); }
+  .tipsy-inner { padding: 5px 8px 4px 8px; background-color: black; color: white; max-width:
200px; text-align: center; }
+  .tipsy-inner { -moz-border-radius:3px; -webkit-border-radius:3px; }
+  .tipsy-north { background-position: top center; }
+  .tipsy-south { background-position: bottom center; }
+  .tipsy-east { background-position: right center; }
+  .tipsy-west { background-position: left center; }

Added: avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.js
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.js?rev=980173&view=auto
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.js (added)
+++ avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/static/tipsy.js Wed Jul 28 19:28:53
2010
@@ -0,0 +1,92 @@
+/*!
+ * The MIT License
+ * 
+ * Copyright (c) 2008 Jason Frame (jason@onehackoranother.com)
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+pv.Behavior.tipsy = function(opts) {
+  var tip;
+
+  /**
+   * @private When the mouse leaves the root panel, trigger a mouseleave event
+   * on the tooltip span. This is necessary for dimensionless marks (e.g.,
+   * lines) when the mouse isn't actually over the span.
+   */
+  function trigger() {
+    $(tip).tipsy("hide");
+  }
+
+  /**
+   * @private When the mouse leaves the tooltip, remove the tooltip span. This
+   * event handler is declared outside of the event handler such that duplicate
+   * registrations are ignored.
+   */
+  function cleanup() {
+    if (tip) {
+      tip.parentNode.removeChild(tip);
+      tip = null;
+    }
+  }
+
+  return function(d) {
+      /* Compute the transform to offset the tooltip position. */
+      var t = pv.Transform.identity, p = this.parent;
+      do {
+        t = t.translate(p.left(), p.top()).times(p.transform());
+      } while (p = p.parent);
+
+      /* Create and cache the tooltip span to be used by tipsy. */
+      if (!tip) {
+        var c = this.root.canvas();
+        c.style.position = "relative";
+        $(c).mouseleave(trigger);
+
+        tip = c.appendChild(document.createElement("div"));
+        tip.style.position = "absolute";
+        $(tip).tipsy(opts);
+      }
+
+      /* Propagate the tooltip text. */
+      tip.title = this.title() || this.text();
+
+      /*
+       * Compute bounding box. TODO support area, lines, wedges, stroke. Also
+       * note that CSS positioning does not support subpixels, and the current
+       * rounding implementation can be off by one pixel.
+       */
+      if (this.properties.width) {
+        tip.style.width = Math.ceil(this.width() * t.k) + 1 + "px";
+        tip.style.height = Math.ceil(this.height() * t.k) + 1 + "px";
+      } else if (this.properties.radius) {
+        var r = this.radius();
+        t.x -= r;
+        t.y -= r;
+        tip.style.height = tip.style.width = Math.ceil(2 * r * t.k) + "px";
+      }
+      tip.style.left = Math.floor(this.left() * t.k + t.x) + "px";
+      tip.style.top = Math.floor(this.top() * t.k + t.y) + "px";
+
+      /*
+       * Cleanup the tooltip span on mouseout. Immediately trigger the tooltip;
+       * this is necessary for dimensionless marks.
+       */
+      $(tip).mouseleave(cleanup).tipsy("show");
+    };
+};

Added: avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/templates/statsview.vm
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/templates/statsview.vm?rev=980173&view=auto
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/templates/statsview.vm (added)
+++ avro/trunk/lang/java/src/java/org/apache/avro/ipc/stats/templates/statsview.vm Wed Jul
28 19:28:53 2010
@@ -0,0 +1,98 @@
+##
+## 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.
+
+#macro( makeChart $attr_map )
+#if ($attr_map.type == "bar") 
+  <script>
+    makeBarChart($attr_map.labelStr, $attr_map.boundaryStr, $attr_map.dataStr);
+  </script>
+#end
+
+#if ($attr_map.type == "dot") 
+  <script>
+    makeDotChart($attr_map.dataStr);
+  </script>
+#end
+#end
+
+#macro( makeChartHeader $attr_map )
+#if ($attr_map.type == "bar") 
+  <p>
+    $attr_map.title <br>
+    Average: $attr_map.avg$attr_map.units<br>
+    Stdev: $attr_map.stdDev$attr_map.units
+  </p>
+#end
+
+#if ($attr_map.type == "dot") 
+  <p>
+    $attr_map.title <br>
+    Most recent calls
+  </p>
+#end
+#end
+
+<html>
+<head>
+<title>$title</title>
+<script type="text/javascript" src="static/protovis-r3.2.js"></script>
+<script type="text/javascript" src="static/tipsy.js"></script>
+<script src="static/jquery-1.4.2.min.js" type="text/javascript"></script>
+<script src="static/jquery.tipsy.js" type="text/javascript"></script>
+<script src="static/tipsy.js" type="text/javascript"></script>
+<link href="static/tipsy.css" type="text/css" rel="stylesheet"/>
+<script src="static/avro.js" type="text/javascript"></script>
+<link href="static/avro.css" type="text/css" rel="stylesheet"/>
+
+<script>
+
+</script>
+</head>
+<body>
+  <h1>$title</h1>
+  <p>
+    Running since: $startupTime<br>
+    Currently: $currTime
+  </p>
+  
+  #if ($inFlightRpcs.size() != 0) 
+  <h4>Active RPC's</h4>
+    <ol>
+    #foreach( $rpc in $inFlightRpcs ) 
+      <li>$rpc</li>
+    #end
+    </ol>
+  #end
+    #foreach ($message in $messages)
+    #set( $width = $message.charts.size() * 300 ) 
+    <table id="charts_table" width=$width>
+      <h3>$message.name ($message.numCalls calls)</h3>
+      <tr valign="top">
+      #foreach ($chart in $message.charts)
+        <td>#makeChartHeader($chart) </td>
+      #end
+      </tr>
+      <tr>
+      #foreach ($chart in $message.charts)
+        <td>#makeChart($chart) </td>
+      #end
+      </tr>
+    </table>
+    #end
+
+</body>
+</html>
\ No newline at end of file

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/stats/TestStatsPluginAndServlet.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/stats/TestStatsPluginAndServlet.java?rev=980173&r1=980172&r2=980173&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/stats/TestStatsPluginAndServlet.java
(original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/stats/TestStatsPluginAndServlet.java
Wed Jul 28 19:28:53 2010
@@ -22,6 +22,11 @@ import static org.junit.Assert.assertTru
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+import javax.servlet.UnavailableException;
 
 import org.apache.avro.Protocol;
 import org.apache.avro.Protocol.Message;
@@ -31,14 +36,12 @@ import org.apache.avro.generic.GenericRe
 import org.apache.avro.generic.GenericResponder;
 import org.apache.avro.ipc.AvroRemoteException;
 import org.apache.avro.ipc.HttpServer;
+import org.apache.avro.ipc.HttpTransceiver;
 import org.apache.avro.ipc.LocalTransceiver;
 import org.apache.avro.ipc.RPCContext;
 import org.apache.avro.ipc.Responder;
 import org.apache.avro.ipc.Transceiver;
 import org.junit.Test;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.log.Log;
 
 public class TestStatsPluginAndServlet {
@@ -53,9 +56,18 @@ public class TestStatsPluginAndServlet {
   /** Returns an HTML string. */
   private String generateServletResponse(StatsPlugin statsPlugin)
       throws IOException {
-    StatsServlet servlet = new StatsServlet(statsPlugin);
+    StatsServlet servlet;
+    try {
+      servlet = new StatsServlet(statsPlugin);
+    } catch (UnavailableException e1) {
+      throw new IOException();
+    }
     StringWriter w = new StringWriter();
-    servlet.writeStats(w);
+    try {
+      servlet.writeStats(w);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
     String o = w.toString();
     return o;
   }
@@ -95,13 +107,14 @@ public class TestStatsPluginAndServlet {
     }
 
     String o = generateServletResponse(statsPlugin);
-    assertTrue(o.contains("Number of calls: 10"));
+    assertTrue(o.contains("10 calls"));
   }
 
   @Test
   public void testMultipleRPCs() throws IOException {
     FakeTicks t = new FakeTicks();
-    StatsPlugin statsPlugin = new StatsPlugin(t, StatsPlugin.DEFAULT_SEGMENTER);
+    StatsPlugin statsPlugin = new StatsPlugin(t, StatsPlugin.LATENCY_SEGMENTER,
+        StatsPlugin.PAYLOAD_SEGMENTER);
     RPCContext context1 = makeContext();
     RPCContext context2 = makeContext();
     statsPlugin.serverReceiveRequest(context1);
@@ -114,11 +127,23 @@ public class TestStatsPluginAndServlet {
     statsPlugin.serverSendResponse(context1);
     t.passTime(900*MS); // second takes 900ms
     statsPlugin.serverSendResponse(context2);
-
     r = generateServletResponse(statsPlugin);
-    assertTrue(r.contains("Average Duration: 500ms"));
+    assertTrue(r.contains("Average: 500.0ms"));
   }
 
+  @Test
+  public void testPayloadSize() throws IOException {
+    Responder r = new TestResponder(protocol);
+    StatsPlugin statsPlugin = new StatsPlugin();
+    r.addRPCPlugin(statsPlugin);
+    Transceiver t = new LocalTransceiver(r);
+    makeRequest(t);
+    
+    String resp = generateServletResponse(statsPlugin);
+    assertTrue(resp.contains("Average: 2.0"));
+ 
+  }
+  
   private RPCContext makeContext() {
     RPCContext context = new RPCContext();
     context.setMessage(message);
@@ -144,7 +169,8 @@ public class TestStatsPluginAndServlet {
   }
 
   /**
-   * Demo program for using RPC stats.  Tool can be used (as below)
+   * Demo program for using RPC stats. This automatically generates
+   * client RPC requests. Alternatively a can be used (as below)
    * to trigger RPCs.
    * <pre>
    * java -jar build/avro-tools-*.jar rpcsend '{"protocol":"sleepy","namespace":null,"types":[],"messages":{"sleep":{"request":[{"name":"millis","type":"long"}],"response":"null"}}}'
sleep localhost 7002 '{"millis": 20000}'
@@ -158,7 +184,8 @@ public class TestStatsPluginAndServlet {
     }
     Protocol protocol = Protocol.parse("{\"protocol\": \"sleepy\", "
         + "\"messages\": { \"sleep\": {"
-        + "   \"request\": [{\"name\": \"millis\", \"type\": \"long\"}], "
+        + "   \"request\": [{\"name\": \"millis\", \"type\": \"long\"}," +
+          "{\"name\": \"data\", \"type\": \"bytes\"}], "
         + "   \"response\": \"null\"} } }");
     Log.info("Using protocol: " + protocol.toString());
     Responder r = new SleepyResponder(protocol);
@@ -169,11 +196,23 @@ public class TestStatsPluginAndServlet {
     HttpServer avroServer = new HttpServer(r, Integer.parseInt(args[0]));
     avroServer.start();
 
-    // Ideally we could use the same Jetty server
-    Server httpServer = new Server(Integer.parseInt(args[1]));
-    new Context(httpServer, "/").addServlet(
-        new ServletHolder(new StatsServlet(p)), "/*");
-    httpServer.start();
-    httpServer.join();
+    StatsServer ss = new StatsServer(p, 8080);
+    
+    HttpTransceiver trans = new HttpTransceiver(
+        new URL("http://localhost:" + Integer.parseInt(args[0])));
+    GenericRequestor req = new GenericRequestor(protocol, trans); 
+
+    while(true) {
+      Thread.sleep(1000);
+      GenericRecord params = new GenericData.Record(protocol.getMessages().get(
+        "sleep").getRequest());
+      Random rand = new Random();
+      params.put("millis", Math.abs(rand.nextLong()) % 1000);
+      int payloadSize = Math.abs(rand.nextInt()) % 10000;
+      byte[] payload = new byte[payloadSize];
+      rand.nextBytes(payload);
+      params.put("data", ByteBuffer.wrap(payload));
+      req.request("sleep", params);
+    }
   }
 }

Modified: avro/trunk/share/rat-excludes.txt
URL: http://svn.apache.org/viewvc/avro/trunk/share/rat-excludes.txt?rev=980173&r1=980172&r2=980173&view=diff
==============================================================================
--- avro/trunk/share/rat-excludes.txt (original)
+++ avro/trunk/share/rat-excludes.txt Wed Jul 28 19:28:53 2010
@@ -30,3 +30,5 @@ lang/c/jansson/**
 lang/c/src/queue.h
 lang/c/src/st.h
 lang/c/src/st.c
+lang/java/src/java/org/apache/avro/ipc/stats/static/*.js
+lang/java/src/java/org/apache/avro/ipc/stats/static/*.css



Mime
View raw message