mirror of https://github.com/grpc/grpc.git
commit
9a434371e2
69 changed files with 1168 additions and 827 deletions
@ -1,64 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_HISTOGRAM_H |
||||
#define GRPC_SUPPORT_HISTOGRAM_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
#include <stddef.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef struct gpr_histogram gpr_histogram; |
||||
|
||||
GPRAPI gpr_histogram* gpr_histogram_create(double resolution, |
||||
double max_bucket_start); |
||||
GPRAPI void gpr_histogram_destroy(gpr_histogram* h); |
||||
GPRAPI void gpr_histogram_add(gpr_histogram* h, double x); |
||||
|
||||
/** The following merges the second histogram into the first. It only works
|
||||
if they have the same buckets and resolution. Returns 0 on failure, 1 |
||||
on success */ |
||||
GPRAPI int gpr_histogram_merge(gpr_histogram* dst, const gpr_histogram* src); |
||||
|
||||
GPRAPI double gpr_histogram_percentile(gpr_histogram* histogram, |
||||
double percentile); |
||||
GPRAPI double gpr_histogram_mean(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_stddev(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_variance(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_maximum(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_minimum(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_count(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_sum(gpr_histogram* histogram); |
||||
GPRAPI double gpr_histogram_sum_of_squares(gpr_histogram* histogram); |
||||
|
||||
GPRAPI const uint32_t* gpr_histogram_get_contents(gpr_histogram* histogram, |
||||
size_t* count); |
||||
GPRAPI void gpr_histogram_merge_contents(gpr_histogram* histogram, |
||||
const uint32_t* data, |
||||
size_t data_count, double min_seen, |
||||
double max_seen, double sum, |
||||
double sum_of_squares, double count); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_SUPPORT_HISTOGRAM_H */ |
@ -0,0 +1,90 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015 gRPC authors. |
||||
// |
||||
// Licensed 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using Google.Protobuf; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
using Grpc.Testing; |
||||
|
||||
namespace Grpc.IntegrationTesting |
||||
{ |
||||
/// <summary> |
||||
/// Snapshottable time statistics. |
||||
/// </summary> |
||||
public class TimeStats |
||||
{ |
||||
readonly object myLock = new object(); |
||||
DateTime lastWallClock; |
||||
TimeSpan lastUserTime; |
||||
TimeSpan lastPrivilegedTime; |
||||
|
||||
public TimeStats() |
||||
{ |
||||
lastWallClock = DateTime.UtcNow; |
||||
lastUserTime = Process.GetCurrentProcess().UserProcessorTime; |
||||
lastPrivilegedTime = Process.GetCurrentProcess().PrivilegedProcessorTime; |
||||
} |
||||
|
||||
public Snapshot GetSnapshot(bool reset) |
||||
{ |
||||
lock (myLock) |
||||
{ |
||||
var wallClock = DateTime.UtcNow; |
||||
var userTime = Process.GetCurrentProcess().UserProcessorTime; |
||||
var privilegedTime = Process.GetCurrentProcess().PrivilegedProcessorTime; |
||||
var snapshot = new Snapshot(wallClock - lastWallClock, userTime - lastUserTime, privilegedTime - lastPrivilegedTime); |
||||
|
||||
if (reset) |
||||
{ |
||||
lastWallClock = wallClock; |
||||
lastUserTime = userTime; |
||||
lastPrivilegedTime = privilegedTime; |
||||
} |
||||
return snapshot; |
||||
} |
||||
} |
||||
|
||||
public class Snapshot |
||||
{ |
||||
public TimeSpan WallClockTime { get; } |
||||
public TimeSpan UserProcessorTime { get; } |
||||
public TimeSpan PrivilegedProcessorTime { get; } |
||||
|
||||
public Snapshot(TimeSpan wallClockTime, TimeSpan userProcessorTime, TimeSpan privilegedProcessorTime) |
||||
{ |
||||
this.WallClockTime = wallClockTime; |
||||
this.UserProcessorTime = userProcessorTime; |
||||
this.PrivilegedProcessorTime = privilegedProcessorTime; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[TimeStats.Snapshot: wallClock {0}, userProcessor {1}, privilegedProcessor {2}]", WallClockTime, UserProcessorTime, PrivilegedProcessorTime); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,63 +0,0 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015 gRPC authors. |
||||
// |
||||
// Licensed 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using Google.Protobuf; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
using Grpc.Testing; |
||||
|
||||
namespace Grpc.IntegrationTesting |
||||
{ |
||||
/// <summary> |
||||
/// Snapshottable wall clock stopwatch. |
||||
/// </summary> |
||||
public class WallClockStopwatch |
||||
{ |
||||
long startTicks; |
||||
|
||||
public WallClockStopwatch() |
||||
{ |
||||
this.startTicks = DateTime.UtcNow.Ticks; |
||||
} |
||||
|
||||
public TimeSpan GetElapsedSnapshot(bool reset) |
||||
{ |
||||
var utcNow = DateTime.UtcNow; |
||||
|
||||
long oldStartTicks; |
||||
if (reset) |
||||
{ |
||||
oldStartTicks = Interlocked.Exchange(ref this.startTicks, utcNow.Ticks); |
||||
} |
||||
else |
||||
{ |
||||
oldStartTicks = this.startTicks; |
||||
} |
||||
return utcNow - new DateTime(oldStartTicks, DateTimeKind.Utc); |
||||
} |
||||
} |
||||
} |
@ -1,163 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/histogram.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x); |
||||
|
||||
static void test_no_op(void) { |
||||
gpr_histogram_destroy(gpr_histogram_create(0.01, 60e9)); |
||||
} |
||||
|
||||
static void expect_percentile(gpr_histogram* h, double percentile, |
||||
double min_expect, double max_expect) { |
||||
double got = gpr_histogram_percentile(h, percentile); |
||||
gpr_log(GPR_INFO, "@%f%%, expect %f <= %f <= %f", percentile, min_expect, got, |
||||
max_expect); |
||||
GPR_ASSERT(min_expect <= got); |
||||
GPR_ASSERT(got <= max_expect); |
||||
} |
||||
|
||||
static void test_simple(void) { |
||||
gpr_histogram* h; |
||||
|
||||
LOG_TEST("test_simple"); |
||||
|
||||
h = gpr_histogram_create(0.01, 60e9); |
||||
gpr_histogram_add(h, 10000); |
||||
gpr_histogram_add(h, 10000); |
||||
gpr_histogram_add(h, 11000); |
||||
gpr_histogram_add(h, 11000); |
||||
|
||||
expect_percentile(h, 50, 10001, 10999); |
||||
GPR_ASSERT(gpr_histogram_mean(h) == 10500); |
||||
|
||||
gpr_histogram_destroy(h); |
||||
} |
||||
|
||||
static void test_percentile(void) { |
||||
gpr_histogram* h; |
||||
double last; |
||||
double i; |
||||
double cur; |
||||
|
||||
LOG_TEST("test_percentile"); |
||||
|
||||
h = gpr_histogram_create(0.05, 1e9); |
||||
gpr_histogram_add(h, 2.5); |
||||
gpr_histogram_add(h, 2.5); |
||||
gpr_histogram_add(h, 8); |
||||
gpr_histogram_add(h, 4); |
||||
|
||||
GPR_ASSERT(gpr_histogram_count(h) == 4); |
||||
GPR_ASSERT(gpr_histogram_minimum(h) == 2.5); |
||||
GPR_ASSERT(gpr_histogram_maximum(h) == 8); |
||||
GPR_ASSERT(gpr_histogram_sum(h) == 17); |
||||
GPR_ASSERT(gpr_histogram_sum_of_squares(h) == 92.5); |
||||
GPR_ASSERT(gpr_histogram_mean(h) == 4.25); |
||||
GPR_ASSERT(gpr_histogram_variance(h) == 5.0625); |
||||
GPR_ASSERT(gpr_histogram_stddev(h) == 2.25); |
||||
|
||||
expect_percentile(h, -10, 2.5, 2.5); |
||||
expect_percentile(h, 0, 2.5, 2.5); |
||||
expect_percentile(h, 12.5, 2.5, 2.5); |
||||
expect_percentile(h, 25, 2.5, 2.5); |
||||
expect_percentile(h, 37.5, 2.5, 2.8); |
||||
expect_percentile(h, 50, 3.0, 3.5); |
||||
expect_percentile(h, 62.5, 3.5, 4.5); |
||||
expect_percentile(h, 75, 5, 7.9); |
||||
expect_percentile(h, 100, 8, 8); |
||||
expect_percentile(h, 110, 8, 8); |
||||
|
||||
/* test monotonicity */ |
||||
last = 0.0; |
||||
for (i = 0; i < 100.0; i += 0.01) { |
||||
cur = gpr_histogram_percentile(h, i); |
||||
GPR_ASSERT(cur >= last); |
||||
last = cur; |
||||
} |
||||
|
||||
gpr_histogram_destroy(h); |
||||
} |
||||
|
||||
static void test_merge(void) { |
||||
gpr_histogram *h1, *h2; |
||||
double last; |
||||
double i; |
||||
double cur; |
||||
|
||||
LOG_TEST("test_merge"); |
||||
|
||||
h1 = gpr_histogram_create(0.05, 1e9); |
||||
gpr_histogram_add(h1, 2.5); |
||||
gpr_histogram_add(h1, 2.5); |
||||
gpr_histogram_add(h1, 8); |
||||
gpr_histogram_add(h1, 4); |
||||
|
||||
h2 = gpr_histogram_create(0.01, 1e9); |
||||
GPR_ASSERT(gpr_histogram_merge(h1, h2) == 0); |
||||
gpr_histogram_destroy(h2); |
||||
|
||||
h2 = gpr_histogram_create(0.05, 1e10); |
||||
GPR_ASSERT(gpr_histogram_merge(h1, h2) == 0); |
||||
gpr_histogram_destroy(h2); |
||||
|
||||
h2 = gpr_histogram_create(0.05, 1e9); |
||||
GPR_ASSERT(gpr_histogram_merge(h1, h2) == 1); |
||||
GPR_ASSERT(gpr_histogram_count(h1) == 4); |
||||
GPR_ASSERT(gpr_histogram_minimum(h1) == 2.5); |
||||
GPR_ASSERT(gpr_histogram_maximum(h1) == 8); |
||||
GPR_ASSERT(gpr_histogram_sum(h1) == 17); |
||||
GPR_ASSERT(gpr_histogram_sum_of_squares(h1) == 92.5); |
||||
GPR_ASSERT(gpr_histogram_mean(h1) == 4.25); |
||||
GPR_ASSERT(gpr_histogram_variance(h1) == 5.0625); |
||||
GPR_ASSERT(gpr_histogram_stddev(h1) == 2.25); |
||||
gpr_histogram_destroy(h2); |
||||
|
||||
h2 = gpr_histogram_create(0.05, 1e9); |
||||
gpr_histogram_add(h2, 7.0); |
||||
gpr_histogram_add(h2, 17.0); |
||||
gpr_histogram_add(h2, 1.0); |
||||
GPR_ASSERT(gpr_histogram_merge(h1, h2) == 1); |
||||
GPR_ASSERT(gpr_histogram_count(h1) == 7); |
||||
GPR_ASSERT(gpr_histogram_minimum(h1) == 1.0); |
||||
GPR_ASSERT(gpr_histogram_maximum(h1) == 17.0); |
||||
GPR_ASSERT(gpr_histogram_sum(h1) == 42.0); |
||||
GPR_ASSERT(gpr_histogram_sum_of_squares(h1) == 431.5); |
||||
GPR_ASSERT(gpr_histogram_mean(h1) == 6.0); |
||||
|
||||
/* test monotonicity */ |
||||
last = 0.0; |
||||
for (i = 0; i < 100.0; i += 0.01) { |
||||
cur = gpr_histogram_percentile(h1, i); |
||||
GPR_ASSERT(cur >= last); |
||||
last = cur; |
||||
} |
||||
|
||||
gpr_histogram_destroy(h1); |
||||
gpr_histogram_destroy(h2); |
||||
} |
||||
|
||||
int main(void) { |
||||
test_no_op(); |
||||
test_simple(); |
||||
test_percentile(); |
||||
test_merge(); |
||||
return 0; |
||||
} |
@ -0,0 +1,62 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_HISTOGRAM_H |
||||
#define GRPC_SUPPORT_HISTOGRAM_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
#include <stddef.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef struct grpc_histogram grpc_histogram; |
||||
|
||||
grpc_histogram* grpc_histogram_create(double resolution, |
||||
double max_bucket_start); |
||||
void grpc_histogram_destroy(grpc_histogram* h); |
||||
void grpc_histogram_add(grpc_histogram* h, double x); |
||||
|
||||
/** The following merges the second histogram into the first. It only works
|
||||
if they have the same buckets and resolution. Returns 0 on failure, 1 |
||||
on success */ |
||||
int grpc_histogram_merge(grpc_histogram* dst, const grpc_histogram* src); |
||||
|
||||
double grpc_histogram_percentile(grpc_histogram* histogram, double percentile); |
||||
double grpc_histogram_mean(grpc_histogram* histogram); |
||||
double grpc_histogram_stddev(grpc_histogram* histogram); |
||||
double grpc_histogram_variance(grpc_histogram* histogram); |
||||
double grpc_histogram_maximum(grpc_histogram* histogram); |
||||
double grpc_histogram_minimum(grpc_histogram* histogram); |
||||
double grpc_histogram_count(grpc_histogram* histogram); |
||||
double grpc_histogram_sum(grpc_histogram* histogram); |
||||
double grpc_histogram_sum_of_squares(grpc_histogram* histogram); |
||||
|
||||
const uint32_t* grpc_histogram_get_contents(grpc_histogram* histogram, |
||||
size_t* count); |
||||
void grpc_histogram_merge_contents(grpc_histogram* histogram, |
||||
const uint32_t* data, size_t data_count, |
||||
double min_seen, double max_seen, double sum, |
||||
double sum_of_squares, double count); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_SUPPORT_HISTOGRAM_H */ |
@ -0,0 +1,163 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/core/util/histogram.h" |
||||
#include <grpc/support/log.h> |
||||
|
||||
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x); |
||||
|
||||
static void test_no_op(void) { |
||||
grpc_histogram_destroy(grpc_histogram_create(0.01, 60e9)); |
||||
} |
||||
|
||||
static void expect_percentile(grpc_histogram* h, double percentile, |
||||
double min_expect, double max_expect) { |
||||
double got = grpc_histogram_percentile(h, percentile); |
||||
gpr_log(GPR_INFO, "@%f%%, expect %f <= %f <= %f", percentile, min_expect, got, |
||||
max_expect); |
||||
GPR_ASSERT(min_expect <= got); |
||||
GPR_ASSERT(got <= max_expect); |
||||
} |
||||
|
||||
static void test_simple(void) { |
||||
grpc_histogram* h; |
||||
|
||||
LOG_TEST("test_simple"); |
||||
|
||||
h = grpc_histogram_create(0.01, 60e9); |
||||
grpc_histogram_add(h, 10000); |
||||
grpc_histogram_add(h, 10000); |
||||
grpc_histogram_add(h, 11000); |
||||
grpc_histogram_add(h, 11000); |
||||
|
||||
expect_percentile(h, 50, 10001, 10999); |
||||
GPR_ASSERT(grpc_histogram_mean(h) == 10500); |
||||
|
||||
grpc_histogram_destroy(h); |
||||
} |
||||
|
||||
static void test_percentile(void) { |
||||
grpc_histogram* h; |
||||
double last; |
||||
double i; |
||||
double cur; |
||||
|
||||
LOG_TEST("test_percentile"); |
||||
|
||||
h = grpc_histogram_create(0.05, 1e9); |
||||
grpc_histogram_add(h, 2.5); |
||||
grpc_histogram_add(h, 2.5); |
||||
grpc_histogram_add(h, 8); |
||||
grpc_histogram_add(h, 4); |
||||
|
||||
GPR_ASSERT(grpc_histogram_count(h) == 4); |
||||
GPR_ASSERT(grpc_histogram_minimum(h) == 2.5); |
||||
GPR_ASSERT(grpc_histogram_maximum(h) == 8); |
||||
GPR_ASSERT(grpc_histogram_sum(h) == 17); |
||||
GPR_ASSERT(grpc_histogram_sum_of_squares(h) == 92.5); |
||||
GPR_ASSERT(grpc_histogram_mean(h) == 4.25); |
||||
GPR_ASSERT(grpc_histogram_variance(h) == 5.0625); |
||||
GPR_ASSERT(grpc_histogram_stddev(h) == 2.25); |
||||
|
||||
expect_percentile(h, -10, 2.5, 2.5); |
||||
expect_percentile(h, 0, 2.5, 2.5); |
||||
expect_percentile(h, 12.5, 2.5, 2.5); |
||||
expect_percentile(h, 25, 2.5, 2.5); |
||||
expect_percentile(h, 37.5, 2.5, 2.8); |
||||
expect_percentile(h, 50, 3.0, 3.5); |
||||
expect_percentile(h, 62.5, 3.5, 4.5); |
||||
expect_percentile(h, 75, 5, 7.9); |
||||
expect_percentile(h, 100, 8, 8); |
||||
expect_percentile(h, 110, 8, 8); |
||||
|
||||
/* test monotonicity */ |
||||
last = 0.0; |
||||
for (i = 0; i < 100.0; i += 0.01) { |
||||
cur = grpc_histogram_percentile(h, i); |
||||
GPR_ASSERT(cur >= last); |
||||
last = cur; |
||||
} |
||||
|
||||
grpc_histogram_destroy(h); |
||||
} |
||||
|
||||
static void test_merge(void) { |
||||
grpc_histogram *h1, *h2; |
||||
double last; |
||||
double i; |
||||
double cur; |
||||
|
||||
LOG_TEST("test_merge"); |
||||
|
||||
h1 = grpc_histogram_create(0.05, 1e9); |
||||
grpc_histogram_add(h1, 2.5); |
||||
grpc_histogram_add(h1, 2.5); |
||||
grpc_histogram_add(h1, 8); |
||||
grpc_histogram_add(h1, 4); |
||||
|
||||
h2 = grpc_histogram_create(0.01, 1e9); |
||||
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 0); |
||||
grpc_histogram_destroy(h2); |
||||
|
||||
h2 = grpc_histogram_create(0.05, 1e10); |
||||
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 0); |
||||
grpc_histogram_destroy(h2); |
||||
|
||||
h2 = grpc_histogram_create(0.05, 1e9); |
||||
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 1); |
||||
GPR_ASSERT(grpc_histogram_count(h1) == 4); |
||||
GPR_ASSERT(grpc_histogram_minimum(h1) == 2.5); |
||||
GPR_ASSERT(grpc_histogram_maximum(h1) == 8); |
||||
GPR_ASSERT(grpc_histogram_sum(h1) == 17); |
||||
GPR_ASSERT(grpc_histogram_sum_of_squares(h1) == 92.5); |
||||
GPR_ASSERT(grpc_histogram_mean(h1) == 4.25); |
||||
GPR_ASSERT(grpc_histogram_variance(h1) == 5.0625); |
||||
GPR_ASSERT(grpc_histogram_stddev(h1) == 2.25); |
||||
grpc_histogram_destroy(h2); |
||||
|
||||
h2 = grpc_histogram_create(0.05, 1e9); |
||||
grpc_histogram_add(h2, 7.0); |
||||
grpc_histogram_add(h2, 17.0); |
||||
grpc_histogram_add(h2, 1.0); |
||||
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 1); |
||||
GPR_ASSERT(grpc_histogram_count(h1) == 7); |
||||
GPR_ASSERT(grpc_histogram_minimum(h1) == 1.0); |
||||
GPR_ASSERT(grpc_histogram_maximum(h1) == 17.0); |
||||
GPR_ASSERT(grpc_histogram_sum(h1) == 42.0); |
||||
GPR_ASSERT(grpc_histogram_sum_of_squares(h1) == 431.5); |
||||
GPR_ASSERT(grpc_histogram_mean(h1) == 6.0); |
||||
|
||||
/* test monotonicity */ |
||||
last = 0.0; |
||||
for (i = 0; i < 100.0; i += 0.01) { |
||||
cur = grpc_histogram_percentile(h1, i); |
||||
GPR_ASSERT(cur >= last); |
||||
last = cur; |
||||
} |
||||
|
||||
grpc_histogram_destroy(h1); |
||||
grpc_histogram_destroy(h2); |
||||
} |
||||
|
||||
int main(void) { |
||||
test_no_op(); |
||||
test_simple(); |
||||
test_percentile(); |
||||
test_merge(); |
||||
return 0; |
||||
} |
@ -0,0 +1,42 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
*/ |
||||
|
||||
/* When running tests on remote machines, the framework takes a round-robin pick
|
||||
* of a port within certain range. There is no need to recycle ports. |
||||
*/ |
||||
#include "src/core/lib/iomgr/port.h" |
||||
#include "test/core/util/test_config.h" |
||||
#if defined(GRPC_PORT_ISOLATED_RUNTIME) |
||||
|
||||
#include "test/core/util/port.h" |
||||
|
||||
#define LOWER_PORT 49152 |
||||
static int s_allocated_port = LOWER_PORT; |
||||
|
||||
int grpc_pick_unused_port_or_die(void) { |
||||
int allocated_port = s_allocated_port++; |
||||
if (s_allocated_port == 65536) { |
||||
s_allocated_port = LOWER_PORT; |
||||
} |
||||
|
||||
return allocated_port; |
||||
} |
||||
|
||||
void grpc_recycle_unused_port(int port) { (void)port; } |
||||
|
||||
#endif /* GRPC_PORT_ISOLATED_RUNTIME */ |
@ -0,0 +1,19 @@ |
||||
#!/bin/sh |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed 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. |
||||
|
||||
set -ex |
||||
export GRPC_POLL_STRATEGY=$1 |
||||
shift |
||||
$@ |
@ -0,0 +1,75 @@ |
||||
@rem Copyright 2016 gRPC authors. |
||||
@rem |
||||
@rem Licensed under the Apache License, Version 2.0 (the "License"); |
||||
@rem you may not use this file except in compliance with the License. |
||||
@rem You may obtain a copy of the License at |
||||
@rem |
||||
@rem http://www.apache.org/licenses/LICENSE-2.0 |
||||
@rem |
||||
@rem Unless required by applicable law or agreed to in writing, software |
||||
@rem distributed under the License is distributed on an "AS IS" BASIS, |
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
@rem See the License for the specific language governing permissions and |
||||
@rem limitations under the License. |
||||
|
||||
@rem enter this directory |
||||
cd /d %~dp0\..\..\.. |
||||
|
||||
@rem TODO(jtattermusch): Kokoro has pre-installed protoc.exe in C:\Program Files\ProtoC and that directory |
||||
@rem is on PATH. To avoid picking up the older version protoc.exe, we change the path to something non-existent. |
||||
set PATH=%PATH:ProtoC=DontPickupProtoC% |
||||
|
||||
@rem Install into ./testinstall, but use absolute path and foward slashes |
||||
set INSTALL_DIR=%cd:\=/%/testinstall |
||||
|
||||
@rem Download OpenSSL-Win32 originally installed from https://slproweb.com/products/Win32OpenSSL.html |
||||
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://storage.googleapis.com/grpc-testing.appspot.com/OpenSSL-Win32-1_1_0g.zip', 'OpenSSL-Win32.zip')" |
||||
powershell -Command "Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('OpenSSL-Win32.zip', '.');" |
||||
|
||||
@rem set absolute path to OpenSSL with forward slashes |
||||
set OPENSSL_DIR=%cd:\=/%/OpenSSL-Win32 |
||||
|
||||
cd third_party/zlib |
||||
mkdir cmake |
||||
cd cmake |
||||
cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% .. |
||||
cmake --build . --config Release --target install || goto :error |
||||
cd ../../.. |
||||
|
||||
cd third_party/protobuf/cmake |
||||
mkdir build |
||||
cd build |
||||
cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF .. |
||||
cmake --build . --config Release --target install || goto :error |
||||
cd ../../../.. |
||||
|
||||
cd third_party/cares/cares |
||||
mkdir cmake |
||||
cd cmake |
||||
cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% .. |
||||
cmake --build . --config Release --target install || goto :error |
||||
cd ../../../.. |
||||
|
||||
@rem OpenSSL-Win32 and OpenSSL-Win64 can be downloaded from https://slproweb.com/products/Win32OpenSSL.html |
||||
cd cmake |
||||
mkdir build |
||||
cd build |
||||
cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOPENSSL_INCLUDE_DIR=%OPENSSL_DIR%/include -DZLIB_LIBRARY=%INSTALL_DIR%/lib/zlibstatic.lib -DZLIB_INCLUDE_DIR=%INSTALL_DIR%/include -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. || goto :error |
||||
cmake --build . --config Release --target install || goto :error |
||||
cd ../.. |
||||
|
||||
# Build helloworld example using cmake |
||||
cd examples/cpp/helloworld |
||||
mkdir cmake |
||||
cd cmake |
||||
mkdir build |
||||
cd build |
||||
cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ../.. || goto :error |
||||
cmake --build . --config Release || goto :error |
||||
cd ../../../../.. |
||||
|
||||
goto :EOF |
||||
|
||||
:error |
||||
echo Failed! |
||||
exit /b %errorlevel% |
@ -0,0 +1,40 @@ |
||||
#!/bin/bash |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed 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. |
||||
|
||||
# Source this rc script to prepare the environment for linux perf builds |
||||
|
||||
# Need to increase open files limit and size for perf test |
||||
ulimit -n 32768 |
||||
ulimit -c unlimited |
||||
|
||||
# Download non-core gRPC repos |
||||
git clone --recursive https://github.com/grpc/grpc-go ./../grpc-go |
||||
git clone --recursive https://github.com/grpc/grpc-java ./../grpc-java |
||||
git clone --recursive https://github.com/grpc/grpc-node ./../grpc-node |
||||
|
||||
sudo pip install tabulate |
||||
|
||||
# Set up Ruby |
||||
export PATH="$HOME/.rbenv/bin:$PATH" |
||||
eval "$(rbenv init -)" |
||||
gem list bundler |
||||
gem install bundler --no-ri --no-rdoc |
||||
|
||||
# Allow SSH to Kokoro performance workers without explicit key verification |
||||
gsutil cp gs://grpc-testing-secrets/grpc_kokoro_performance_ssh_keys/id_rsa ~/.ssh |
||||
echo -e 'Host grpc-kokoro-performance*\n\tStrictHostKeyChecking no' >> ~/.ssh/config |
||||
chmod 600 ~/.ssh/id_rsa ~/.ssh/config |
||||
|
||||
git submodule update --init |
@ -0,0 +1,55 @@ |
||||
#!/usr/bin/env bash |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed 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. |
||||
|
||||
set -ex |
||||
|
||||
# A temporary solution to give Kokoro credentials. |
||||
# The file name 4321_grpc-testing-service needs to match auth_credential in |
||||
# the build config. |
||||
mkdir -p ${KOKORO_KEYSTORE_DIR} |
||||
cp ${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json ${KOKORO_KEYSTORE_DIR}/4321_grpc-testing-service |
||||
|
||||
mkdir -p /tmpfs/tmp/bazel-canary |
||||
ln -f "${KOKORO_GFILE_DIR}/bazel-canary" /tmpfs/tmp/bazel-canary/bazel |
||||
chmod 755 "${KOKORO_GFILE_DIR}/bazel-canary" |
||||
export PATH="/tmpfs/tmp/bazel-canary:${PATH}" |
||||
# This should show /tmpfs/tmp/bazel-canary/bazel |
||||
which bazel |
||||
chmod +x "${KOKORO_GFILE_DIR}/bazel_wrapper.py" |
||||
|
||||
# change to grpc repo root |
||||
cd $(dirname $0)/../../.. |
||||
|
||||
source tools/internal_ci/helper_scripts/prepare_build_linux_rc |
||||
|
||||
"${KOKORO_GFILE_DIR}/bazel_wrapper.py" \ |
||||
--host_jvm_args=-Dbazel.DigestFunction=SHA1 \ |
||||
test --jobs="50" \ |
||||
--test_timeout="300,450,1200,3600" \ |
||||
--test_output=errors \ |
||||
--verbose_failures=true \ |
||||
--keep_going \ |
||||
--remote_accept_cached=true \ |
||||
--spawn_strategy=remote \ |
||||
--remote_local_fallback=false \ |
||||
--remote_timeout=3600 \ |
||||
--strategy=Javac=remote \ |
||||
--strategy=Closure=remote \ |
||||
--genrule_strategy=remote \ |
||||
--experimental_strict_action_env=true \ |
||||
--experimental_remote_platform_override='properties:{name:"container-image" value:"docker://gcr.io/asci-toolchain/nosla-debian8-clang-fl@sha256:aa20628a902f06a11a015caa94b0432eb60690de2d2525bd046b9eea046f5d8a" }' \ |
||||
--crosstool_top=@bazel_toolchains//configs/debian8_clang/0.2.0/bazel_0.7.0:toolchain \ |
||||
--define GRPC_PORT_ISOLATED_RUNTIME=1 \ |
||||
-- //test/... |
@ -0,0 +1,25 @@ |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed 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. |
||||
|
||||
# Config file for the internal CI (in protobuf text format) |
||||
|
||||
# Location of the continuous shell script in repository. |
||||
build_file: "grpc/tools/internal_ci/linux/grpc_full_performance_master.sh" |
||||
timeout_mins: 600 |
||||
action { |
||||
define_artifacts { |
||||
regex: "**/*sponge_log.xml" |
||||
regex: "**/perf_reports/**" |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
#!/usr/bin/env bash |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed 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. |
||||
set -ex |
||||
|
||||
# Enter the gRPC repo root |
||||
cd $(dirname $0)/../../.. |
||||
|
||||
source tools/internal_ci/helper_scripts/prepare_build_linux_perf_multilang_rc |
||||
|
||||
# run 8core client vs 8core server |
||||
tools/run_tests/run_performance_tests.py \ |
||||
-l c++ csharp ruby java python go php7 php7_protobuf_c \ |
||||
--netperf \ |
||||
--category scalable \ |
||||
--remote_worker_host grpc-kokoro-performance-server-8core grpc-kokoro-performance-client-8core grpc-kokoro-performance-client2-8core \ |
||||
-u kbuilder \ |
||||
--bq_result_table performance_test.kokoro_performance_experiment \ |
||||
--xml_report reports/8core/sponge_log.xml \ |
||||
|| EXIT_CODE=1 |
||||
|
||||
# prevent pushing leftover build files to remote hosts in the next step. |
||||
git clean -fdxq -e reports |
||||
|
||||
# scalability with 32cores (and upload to a different BQ table) |
||||
tools/run_tests/run_performance_tests.py \ |
||||
-l c++ java csharp go \ |
||||
--netperf \ |
||||
--category scalable \ |
||||
--remote_worker_host grpc-kokoro-performance-server-32core grpc-kokoro-performance-client-32core grpc-kokoro-performance-client2-32core \ |
||||
-u kbuilder \ |
||||
--bq_result_table performance_test.kokoro_performance_experiment_32core \ |
||||
--xml_report reports/32core/sponge_log.xml \ |
||||
|| EXIT_CODE=1 |
||||
|
||||
# prevent pushing leftover build files to remote hosts in the next step. |
||||
git clean -fdxq -e reports |
||||
|
||||
# selected scenarios on Windows |
||||
tools/run_tests/run_performance_tests.py \ |
||||
-l csharp \ |
||||
--category scalable \ |
||||
--remote_worker_host grpc-kokoro-performance-windows1 grpc-kokoro-performance-windows2 \ |
||||
--bq_result_table performance_test.kokoro_performance_experiment_windows \ |
||||
--xml_report reports/windows/sponge_log.xml \ |
||||
|| EXIT_CODE=1 |
||||
|
||||
exit $EXIT_CODE |
Loading…
Reference in new issue