Пример #1
0
    def test_to_proto(self):
        dist = distribution.Distribution(distribution.LinearBucketer(10))

        dist.add_value(0)
        dist.add_value(1)
        dist.add_value(9)
        dist.add_value(10)
        dist.add_value(101)

        dist_proto = result_pb2.DistributionProto()
        bucket = result_pb2.BucketProto()
        bucket.end = 10
        bucket.count = 3
        dist_proto.buckets.append(bucket)
        bucket = result_pb2.BucketProto()
        bucket.end = 20
        bucket.count = 1
        dist_proto.buckets.append(bucket)

        bucket = result_pb2.BucketProto()
        bucket.end = 100
        bucket.count = 0
        dist_proto.buckets.append(bucket)
        bucket = result_pb2.BucketProto()
        bucket.end = 110
        bucket.count = 1
        dist_proto.buckets.append(bucket)

        self.assertEqual(dist.to_proto(), dist_proto)
Пример #2
0
def to_network_result_proto(network_model_name, totals, cost_function):  # pylint: disable=too-many-locals
    """Convert totals from the simulation into a NetworkResultProto."""
    network_result_proto = result_pb2.NetworkResultProto()
    network_result_proto.network_model_name = network_model_name

    request_bytes_per_page_view = distribution.Distribution(
        distribution.LinearBucketer(5))
    response_bytes_per_page_view = distribution.Distribution(
        distribution.LinearBucketer(5))
    latency_distribution = distribution.Distribution(
        distribution.LinearBucketer(5))
    cost_per_page_view = distribution.Distribution(
        distribution.LinearBucketer(5))

    total_request_count = 0
    total_request_bytes = 0
    total_response_bytes = 0
    total_wait_time_ms = 0
    total_cost = 0
    for seq_totals in totals:
        for total in seq_totals.totals:
            the_cost = cost_function(total.total_time)
            request_bytes_per_page_view.add_value(total.request_bytes)
            response_bytes_per_page_view.add_value(total.response_bytes)
            latency_distribution.add_value(total.total_time)
            cost_per_page_view.add_value(the_cost)
            total_request_count += total.num_requests
            total_request_bytes += total.request_bytes
            total_response_bytes += total.response_bytes
            total_wait_time_ms += total.total_time
            total_cost += the_cost

    network_result_proto.request_bytes_per_page_view.CopyFrom(
        request_bytes_per_page_view.to_proto())
    network_result_proto.response_bytes_per_page_view.CopyFrom(
        response_bytes_per_page_view.to_proto())
    network_result_proto.wait_per_page_view_ms.CopyFrom(
        latency_distribution.to_proto())
    network_result_proto.cost_per_page_view.CopyFrom(
        cost_per_page_view.to_proto())
    network_result_proto.total_cost = total_cost
    network_result_proto.total_wait_time_ms = total_wait_time_ms
    network_result_proto.total_request_bytes = total_request_bytes
    network_result_proto.total_response_bytes = total_response_bytes
    network_result_proto.total_request_count = total_request_count

    return network_result_proto
Пример #3
0
def to_network_result_proto(network_model_name, totals, cost_function):
  network_result_proto = result_pb2.NetworkResultProto()
  network_result_proto.network_model_name = network_model_name

  request_bytes_per_page_view = distribution.Distribution(
      distribution.LinearBucketer(5))
  response_bytes_per_page_view = distribution.Distribution(
      distribution.LinearBucketer(5))
  latency_distribution = distribution.Distribution(
        distribution.LinearBucketer(5))
  cost_per_page_view = distribution.Distribution(
        distribution.LinearBucketer(5))

  result_by_network = dict()
  total_request_count = 0
  total_request_bytes = 0
  total_response_bytes = 0
  total_wait_time_ms = 0
  total_cost = 0
  for total in totals:
    cost = cost_function(total.total_time)
    request_bytes_per_page_view.add_value(total.request_bytes)
    response_bytes_per_page_view.add_value(total.response_bytes)
    latency_distribution.add_value(total.total_time)
    cost_per_page_view.add_value(cost)
    total_request_count += total.num_requests
    total_request_bytes += total.request_bytes
    total_response_bytes += total.response_bytes
    total_wait_time_ms += total.total_time
    total_cost += cost

  network_result_proto.request_bytes_per_page_view.CopyFrom(
      request_bytes_per_page_view.to_proto())
  network_result_proto.response_bytes_per_page_view.CopyFrom(
      response_bytes_per_page_view.to_proto())
  network_result_proto.wait_per_page_view_ms.CopyFrom(
      latency_distribution.to_proto())
  network_result_proto.cost_per_page_view.CopyFrom(
      cost_per_page_view.to_proto())
  network_result_proto.total_cost = total_cost
  network_result_proto.total_wait_time_ms = total_wait_time_ms
  network_result_proto.total_request_bytes = total_request_bytes
  network_result_proto.total_response_bytes = total_response_bytes
  network_result_proto.total_request_count = total_request_count

  return network_result_proto
Пример #4
0
    def test_add_value(self):
        dist = distribution.Distribution(distribution.LinearBucketer(10))

        dist.add_value(0)
        dist.add_value(1)
        dist.add_value(9)
        dist.add_value(10)
        dist.add_value(101)

        self.assertEqual(dist.buckets, {10: 3, 20: 1, 110: 1})
Пример #5
0
    def test_to_proto_with_starting_gap(self):
        dist = distribution.Distribution(distribution.LinearBucketer(10))

        dist.add_value(21)

        dist_proto = result_pb2.DistributionProto()
        bucket = result_pb2.BucketProto()
        bucket.end = 20
        bucket.count = 0
        dist_proto.buckets.append(bucket)
        bucket = result_pb2.BucketProto()
        bucket.end = 30
        bucket.count = 1
        dist_proto.buckets.append(bucket)

        self.assertEqual(dist.to_proto(), dist_proto)