test/hotspot/gtest/jfr/test_networkUtilization.cpp
author glaubitz
Mon, 09 Sep 2019 15:14:16 +0200
changeset 58050 9fba708740d6
parent 53026 7d4397b43fa3
child 57360 5d043a159d5c
child 58863 c16ac7a2eba4
permissions -rw-r--r--
8230708: Hotspot fails to build on linux-sparc with gcc-9 Reviewed-by: dholmes, phh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     1
/*
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     4
 *
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     8
 *
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    13
 * accompanied this code).
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    14
 *
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    18
 *
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    21
 * questions.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    22
 *
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    23
 */
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    24
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    25
#include "precompiled.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    26
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    27
// This test performs mocking of certain JVM functionality. This works by
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    28
// including the source file under test inside an anonymous namespace (which
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    29
// prevents linking conflicts) with the mocked symbols redefined.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    30
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    31
// The include list should mirror the one found in the included source file -
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    32
// with the ones that should pick up the mocks removed. Those should be included
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    33
// later after the mocks have been defined.
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    34
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    35
#include "logging/log.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    36
#include "jfr/jfrEvents.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    37
#include "jfr/metadata/jfrSerializer.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    38
#include "jfr/periodic/jfrOSInterface.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    39
#include "jfr/utilities/jfrTime.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    40
#include "jfr/utilities/jfrTypes.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    41
#include "runtime/os_perf.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    42
#include "utilities/globalDefinitions.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    43
#include "utilities/growableArray.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    44
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    45
#include "unittest.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    46
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    47
#include <vector>
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    48
#include <list>
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    49
#include <map>
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    50
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    51
namespace {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    52
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    53
  class MockFastUnorderedElapsedCounterSource : public ::FastUnorderedElapsedCounterSource {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    54
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    55
    static jlong current_ticks;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    56
    static Type now() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    57
      return current_ticks;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    58
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    59
    static uint64_t nanoseconds(Type value) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    60
      return value;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    61
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    62
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    63
50894
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
    64
  typedef TimeInstant<CounterRepresentation, MockFastUnorderedElapsedCounterSource> MockJfrTicks;
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
    65
  typedef TimeInterval<CounterRepresentation, MockFastUnorderedElapsedCounterSource> MockJfrTickspan;
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    66
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    67
  class MockJfrCheckpointWriter {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    68
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    69
    traceid current;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    70
    std::map<traceid, std::string> ids;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    71
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    72
    const JfrCheckpointContext context() const {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    73
      return JfrCheckpointContext();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    74
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    75
    intptr_t reserve(size_t size) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    76
      return 0;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    77
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    78
    void write_key(traceid id) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    79
      current = id;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    80
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    81
    void write(const char* data) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    82
      ids[current] = data;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    83
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    84
    void set_context(const JfrCheckpointContext ctx) { }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    85
    void write_count(u4 nof_entries, jlong offset) { }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    86
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    87
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    88
  class MockJfrSerializer {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    89
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    90
    static MockJfrSerializer* current;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    91
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    92
    static bool register_serializer(JfrTypeId id, bool require_safepoint, bool permit_cache, MockJfrSerializer* serializer) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    93
      current = serializer;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    94
      return true;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    95
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    96
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    97
    virtual void serialize(MockJfrCheckpointWriter& writer) = 0;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    98
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
    99
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   100
  MockJfrSerializer* MockJfrSerializer::current;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   101
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   102
  class MockEventNetworkUtilization : public ::EventNetworkUtilization
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   103
  {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   104
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   105
    std::string iface;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   106
    s8 readRate;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   107
    s8 writeRate;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   108
    static std::vector<MockEventNetworkUtilization> committed;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   109
    MockJfrCheckpointWriter writer;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   110
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   111
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   112
    MockEventNetworkUtilization(EventStartTime timing=TIMED) :
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   113
    ::EventNetworkUtilization(timing) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   114
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   115
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   116
    void set_networkInterface(traceid new_value) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   117
      MockJfrSerializer::current->serialize(writer);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   118
      iface = writer.ids[new_value];
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   119
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   120
    void set_readRate(s8 new_value) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   121
      readRate = new_value;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   122
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   123
    void set_writeRate(s8 new_value) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   124
      writeRate = new_value;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   125
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   126
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   127
    void commit() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   128
      committed.push_back(*this);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   129
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   130
50894
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
   131
    void set_starttime(const MockJfrTicks& time) {}
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   132
50894
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
   133
    void set_endtime(const MockJfrTicks& time) {}
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   134
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   135
    static const MockEventNetworkUtilization& get_committed(const std::string& name) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   136
      static MockEventNetworkUtilization placeholder;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   137
      for (std::vector<MockEventNetworkUtilization>::const_iterator i = committed.begin();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   138
           i != committed.end();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   139
           ++i) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   140
        if (name == i->iface) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   141
          return *i;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   142
        }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   143
      }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   144
      return placeholder;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   145
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   146
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   147
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   148
  std::vector<MockEventNetworkUtilization> MockEventNetworkUtilization::committed;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   149
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   150
  jlong MockFastUnorderedElapsedCounterSource::current_ticks;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   151
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   152
  struct MockNetworkInterface {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   153
    std::string name;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   154
    uint64_t bytes_in;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   155
    uint64_t bytes_out;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   156
    MockNetworkInterface(std::string name, uint64_t bytes_in, uint64_t bytes_out)
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   157
    : name(name),
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   158
    bytes_in(bytes_in),
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   159
    bytes_out(bytes_out) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   160
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   161
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   162
    bool operator==(const MockNetworkInterface& rhs) const {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   163
      return name == rhs.name;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   164
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   165
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   166
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   167
  class NetworkInterface : public ::NetworkInterface {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   168
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   169
    NetworkInterface(const char* name, uint64_t bytes_in, uint64_t bytes_out, NetworkInterface* next)
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   170
    : ::NetworkInterface(name, bytes_in, bytes_out, next) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   171
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   172
    NetworkInterface* next(void) const {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   173
      return reinterpret_cast<NetworkInterface*>(::NetworkInterface::next());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   174
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   175
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   176
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   177
  class MockJfrOSInterface {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   178
    static std::list<MockNetworkInterface> _interfaces;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   179
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   180
  public:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   181
    MockJfrOSInterface() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   182
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   183
    static int network_utilization(NetworkInterface** network_interfaces) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   184
      *network_interfaces = NULL;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   185
      for (std::list<MockNetworkInterface>::const_iterator i = _interfaces.begin();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   186
           i != _interfaces.end();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   187
           ++i) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   188
        NetworkInterface* cur = new NetworkInterface(i->name.c_str(), i->bytes_in, i->bytes_out, *network_interfaces);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   189
        *network_interfaces = cur;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   190
      }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   191
      return OS_OK;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   192
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   193
    static MockNetworkInterface& add_interface(const std::string& name) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   194
      MockNetworkInterface iface(name, 0, 0);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   195
      _interfaces.push_back(iface);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   196
      return _interfaces.back();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   197
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   198
    static void remove_interface(const MockNetworkInterface& iface) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   199
      _interfaces.remove(iface);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   200
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   201
    static void clear_interfaces() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   202
      _interfaces.clear();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   203
    }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   204
  };
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   205
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   206
  std::list<MockNetworkInterface> MockJfrOSInterface::_interfaces;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   207
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   208
// Reincluding source files in the anonymous namespace unfortunately seems to
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   209
// behave strangely with precompiled headers (only when using gcc though)
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   210
#ifndef DONT_USE_PRECOMPILED_HEADER
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   211
#define DONT_USE_PRECOMPILED_HEADER
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   212
#endif
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   213
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   214
#define EventNetworkUtilization MockEventNetworkUtilization
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   215
#define FastUnorderedElapsedCounterSource MockFastUnorderedElapsedCounterSource
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   216
#define JfrOSInterface MockJfrOSInterface
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   217
#define JfrSerializer MockJfrSerializer
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   218
#define JfrCheckpointWriter MockJfrCheckpointWriter
50894
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
   219
#define JfrTicks MockJfrTicks
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
   220
#define JfrTickspan MockJfrTickspan
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   221
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   222
#include "jfr/periodic/jfrNetworkUtilization.hpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   223
#include "jfr/periodic/jfrNetworkUtilization.cpp"
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   224
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   225
#undef EventNetworkUtilization
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   226
#undef FastUnorderedElapsedCounterSource
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   227
#undef JfrOSInterface
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   228
#undef JfrSerializer
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   229
#undef JfrCheckpointWriter
50894
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
   230
#undef JfrTicks
e8d55141afd2 8206006: Build failed on Windows
jwilhelm
parents: 50879
diff changeset
   231
#undef JfrTickspan
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   232
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   233
} // anonymous namespace
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   234
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   235
class JfrTestNetworkUtilization : public ::testing::Test {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   236
protected:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   237
  void SetUp() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   238
    MockEventNetworkUtilization::committed.clear();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   239
    MockJfrOSInterface::clear_interfaces();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   240
    // Ensure that tests are separated in time
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   241
    MockFastUnorderedElapsedCounterSource::current_ticks += 1 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   242
  }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   243
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   244
  void TearDown() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   245
    JfrNetworkUtilization::destroy();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   246
  }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   247
};
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   248
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   249
TEST_VM_F(JfrTestNetworkUtilization, RequestFunctionBasic) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   250
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   251
  MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   252
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   253
  ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   254
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   255
  eth0.bytes_in += 10;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   256
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   257
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   258
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   259
  ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   260
  MockEventNetworkUtilization& e = MockEventNetworkUtilization::committed[0];
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   261
  EXPECT_EQ(40, e.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   262
  EXPECT_EQ(0, e.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   263
  EXPECT_STREQ("eth0", e.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   264
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   265
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   266
TEST_VM_F(JfrTestNetworkUtilization, RequestFunctionMultiple) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   267
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   268
  MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   269
  MockNetworkInterface& eth1 = MockJfrOSInterface::add_interface("eth1");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   270
  MockNetworkInterface& ppp0 = MockJfrOSInterface::add_interface("ppp0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   271
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   272
  ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   273
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   274
  eth0.bytes_in += 10;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   275
  eth1.bytes_in += 100;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   276
  ppp0.bytes_out += 50;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   277
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   278
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   279
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   280
  ASSERT_EQ(3u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   281
  const MockEventNetworkUtilization& eth0_event = MockEventNetworkUtilization::get_committed("eth0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   282
  const MockEventNetworkUtilization& eth1_event = MockEventNetworkUtilization::get_committed("eth1");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   283
  const MockEventNetworkUtilization& ppp0_event = MockEventNetworkUtilization::get_committed("ppp0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   284
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   285
  EXPECT_EQ(40, eth0_event.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   286
  EXPECT_EQ(0, eth0_event.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   287
  EXPECT_STREQ("eth0", eth0_event.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   288
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   289
  EXPECT_EQ(400, eth1_event.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   290
  EXPECT_EQ(0, eth1_event.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   291
  EXPECT_STREQ("eth1", eth1_event.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   292
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   293
  EXPECT_EQ(0, ppp0_event.readRate);
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   294
  EXPECT_EQ(200, ppp0_event.writeRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   295
  EXPECT_STREQ("ppp0", ppp0_event.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   296
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   297
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   298
TEST_VM_F(JfrTestNetworkUtilization, InterfaceRemoved) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   299
  MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   300
  MockNetworkInterface& eth1 = MockJfrOSInterface::add_interface("eth1");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   301
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   302
  ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   303
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   304
  eth0.bytes_in += 10;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   305
  eth1.bytes_in += 20;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   306
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   307
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   308
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   309
  ASSERT_EQ(2u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   310
  const MockEventNetworkUtilization& eth0_event = MockEventNetworkUtilization::get_committed("eth0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   311
  const MockEventNetworkUtilization& eth1_event = MockEventNetworkUtilization::get_committed("eth1");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   312
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   313
  EXPECT_EQ(40, eth0_event.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   314
  EXPECT_EQ(0, eth0_event.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   315
  EXPECT_STREQ("eth0", eth0_event.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   316
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   317
  EXPECT_EQ(80, eth1_event.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   318
  EXPECT_EQ(0, eth1_event.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   319
  EXPECT_STREQ("eth1", eth1_event.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   320
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   321
  MockJfrOSInterface::remove_interface(eth0);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   322
  MockEventNetworkUtilization::committed.clear();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   323
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   324
  eth1.bytes_in += 10;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   325
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   326
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   327
  ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   328
  const MockEventNetworkUtilization& eth1_event_v2 = MockEventNetworkUtilization::get_committed("eth1");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   329
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   330
  EXPECT_EQ(40, eth1_event_v2.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   331
  EXPECT_EQ(0, eth1_event_v2.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   332
  EXPECT_STREQ("eth1", eth1_event_v2.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   333
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   334
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   335
TEST_VM_F(JfrTestNetworkUtilization, InterfaceReset) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   336
  MockNetworkInterface& eth0 = MockJfrOSInterface::add_interface("eth0");
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   337
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   338
  ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   339
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   340
  eth0.bytes_in += 10;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   341
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   342
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   343
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   344
  ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   345
  const MockEventNetworkUtilization& event = MockEventNetworkUtilization::committed[0];
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   346
  EXPECT_EQ(40, event.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   347
  EXPECT_EQ(0, event.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   348
  EXPECT_STREQ("eth0", event.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   349
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   350
  eth0.bytes_in = 0;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   351
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   352
  MockEventNetworkUtilization::committed.clear();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   353
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   354
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   355
  ASSERT_EQ(0u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   356
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   357
  eth0.bytes_in = 10;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   358
  MockFastUnorderedElapsedCounterSource::current_ticks += 2 * NANOSECS_PER_SEC;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   359
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   360
  JfrNetworkUtilization::send_events();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   361
  ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   362
  const MockEventNetworkUtilization& event_v2 = MockEventNetworkUtilization::committed[0];
53026
7d4397b43fa3 8215362: JFR GTest JfrTestNetworkUtilization fails
egahlin
parents: 50894
diff changeset
   363
  EXPECT_EQ(40, event_v2.readRate);
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   364
  EXPECT_EQ(0, event_v2.writeRate);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   365
  EXPECT_STREQ("eth0", event_v2.iface.c_str());
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents:
diff changeset
   366
}