| Index: third_party/grpc/src/csharp/Grpc.Core.Tests/PerformanceTest.cs
|
| diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs b/third_party/grpc/src/csharp/Grpc.Core.Tests/PerformanceTest.cs
|
| similarity index 51%
|
| copy from third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
|
| copy to third_party/grpc/src/csharp/Grpc.Core.Tests/PerformanceTest.cs
|
| index e8a6073e2bcb6b6f47dafb1f67f31de9b4a8671a..68158399921ccc05df412eb27708050082be5ef6 100644
|
| --- a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
|
| +++ b/third_party/grpc/src/csharp/Grpc.Core.Tests/PerformanceTest.cs
|
| @@ -1,7 +1,7 @@
|
| #region Copyright notice and license
|
| -// Protocol Buffers - Google's data interchange format
|
| -// Copyright 2008 Google Inc. All rights reserved.
|
| -// https://developers.google.com/protocol-buffers/
|
| +
|
| +// Copyright 2015, Google Inc.
|
| +// All rights reserved.
|
| //
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| @@ -28,45 +28,72 @@
|
| // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| #endregion
|
|
|
| using System;
|
| -using System.IO;
|
| +using System.Diagnostics;
|
| +using System.Linq;
|
| +using System.Threading;
|
| +using System.Threading.Tasks;
|
| +using Grpc.Core;
|
| +using Grpc.Core.Internal;
|
| +using Grpc.Core.Profiling;
|
| +using Grpc.Core.Utils;
|
| +using NUnit.Framework;
|
|
|
| -namespace Google.Protobuf.ProtoDump
|
| +namespace Grpc.Core.Tests
|
| {
|
| - /// <summary>
|
| - /// Small utility to load a binary message and dump it in JSON format.
|
| - /// </summary>
|
| - internal class Program
|
| + public class PerformanceTest
|
| {
|
| - private static int Main(string[] args)
|
| + const string Host = "127.0.0.1";
|
| +
|
| + MockServiceHelper helper;
|
| + Server server;
|
| + Channel channel;
|
| +
|
| + [SetUp]
|
| + public void Init()
|
| {
|
| - if (args.Length != 2)
|
| - {
|
| - Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descriptor type name> <input data>");
|
| - Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,");
|
| - Console.Error.WriteLine("including assembly e.g. ProjectNamespace.Message,Company.Project");
|
| - return 1;
|
| - }
|
| - Type type = Type.GetType(args[0]);
|
| - if (type == null)
|
| + helper = new MockServiceHelper(Host);
|
| + server = helper.GetServer();
|
| + server.Start();
|
| + channel = helper.GetChannel();
|
| + }
|
| +
|
| + [TearDown]
|
| + public void Cleanup()
|
| + {
|
| + channel.ShutdownAsync().Wait();
|
| + server.ShutdownAsync().Wait();
|
| + }
|
| +
|
| + [Test]
|
| + [Category("Performance")]
|
| + [Ignore("Prevent running on Jenkins")]
|
| + public void UnaryCallPerformance()
|
| + {
|
| + var profiler = new BasicProfiler();
|
| + Profilers.SetForCurrentThread(profiler);
|
| +
|
| + helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
|
| {
|
| - Console.Error.WriteLine("Unable to load type {0}.", args[0]);
|
| - return 1;
|
| - }
|
| - if (!typeof(IMessage).IsAssignableFrom(type))
|
| + return request;
|
| + });
|
| +
|
| + var callDetails = helper.CreateUnaryCall();
|
| + for(int i = 0; i < 3000; i++)
|
| {
|
| - Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]);
|
| - return 1;
|
| + Calls.BlockingUnaryCall(callDetails, "ABC");
|
| }
|
| - IMessage message = (IMessage) Activator.CreateInstance(type);
|
| - using (var input = File.OpenRead(args[1]))
|
| +
|
| + profiler.Reset();
|
| +
|
| + for(int i = 0; i < 3000; i++)
|
| {
|
| - message.MergeFrom(input);
|
| + Calls.BlockingUnaryCall(callDetails, "ABC");
|
| }
|
| - Console.WriteLine(message);
|
| - return 0;
|
| + profiler.Dump("latency_trace_csharp.txt");
|
| }
|
| }
|
| -}
|
| +}
|
|
|