You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/10/13 20:45:32 UTC

[geode] branch develop updated (4b77b9f -> c44eb4c)

This is an automated email from the ASF dual-hosted git repository.

klund pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git.


    from 4b77b9f  GEODE-1568: delete useless broken test
     new 00da97d  GEODE-3716 - Adding steal time metrics to Geode.
     new 73f53bc  GEODE-3716 - Add an integration test for the Steal Time Stat.
     new c44eb4c  GEODE-3716 - Clarify the description of stat cpuSteal. Use the junit temp folder for temp files. Use the RestoreSystemProperties rule since the test is setting some properties. Remove setting a field in the test to null.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../statistics/platform/LinuxProcFsStatistics.java |  12 +-
 .../statistics/platform/LinuxSystemStats.java      |   6 +-
 .../internal/statistics/LinuxSystemStatsTest.java  | 199 +++++++++++++++++++++
 3 files changed, 211 insertions(+), 6 deletions(-)
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].

[geode] 03/03: GEODE-3716 - Clarify the description of stat cpuSteal. Use the junit temp folder for temp files. Use the RestoreSystemProperties rule since the test is setting some properties. Remove setting a field in the test to null.

Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit c44eb4c3e2d4b18108b43c565f7f03cb7f265e12
Author: Charlie Black <ch...@github.com>
AuthorDate: Thu Oct 12 22:28:33 2017 -0700

    GEODE-3716 - Clarify the description of stat cpuSteal.
    Use the junit temp folder for temp files.
    Use the RestoreSystemProperties rule since the test is setting some properties.
    Remove setting a field in the test to null.
---
 .../statistics/platform/LinuxSystemStats.java      |  2 +-
 .../internal/statistics/LinuxSystemStatsTest.java  | 62 +++++++++++++---------
 2 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
index 8dbb2df..c3150b6 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
@@ -145,7 +145,7 @@ public class LinuxSystemStats {
                 "The percentage of total available time that has been used to execute non-user code.(includes system, iowait, irq, softirq etc.)",
                 "%"),
             f.createIntGauge("cpuSteal",
-                "Stolen time, which is the time spent in their operating systems when running in a virtualized environment.",
+                "Steal time is the amount of time the operating system wanted to execute, but was not allowed to by the hypervisor.",
                 "%"),
 
             f.createLongCounter("loopbackPackets",
diff --git a/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java b/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
index 009eefa..c7ef560 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
@@ -15,14 +15,23 @@
 
 package org.apache.geode.internal.statistics;
 
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.commons.io.IOUtils;
-import org.apache.geode.CancelCriterion;
-import org.apache.geode.Statistics;
-import org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics;
-import org.apache.geode.internal.statistics.platform.LinuxSystemStats;
-import org.apache.geode.test.junit.categories.IntegrationTest;
 import org.apache.tools.ant.filters.StringInputStream;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
@@ -33,15 +42,11 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.Statistics;
+import org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics;
+import org.apache.geode.internal.statistics.platform.LinuxSystemStats;
+import org.apache.geode.test.junit.categories.IntegrationTest;
 
 /**
  * Technically a linux only test - the file handling is all mocked up so the test can run on any
@@ -51,9 +56,10 @@ import static org.mockito.ArgumentMatchers.anyString;
 @RunWith(PowerMockRunner.class)
 @PowerMockIgnore("*.IntegrationTest")
 @PrepareForTest(LinuxProcFsStatistics.class)
-@Ignore
 public class LinuxSystemStatsTest extends StatSamplerTestCase {
   @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+  @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
   private int[] ints;
   private long[] longs;
@@ -83,7 +89,6 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
     StatisticsTypeFactoryImpl.clear();
     if (this.statisticsFactory != null) {
       this.statisticsFactory.close();
-      this.statisticsFactory = null;
     }
   }
 
@@ -130,7 +135,6 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
     Answer<FileInputStream> answer = new MyStealTimeAnswer(results);
     PowerMockito.whenNew(FileInputStream.class).withArguments(anyString()).thenAnswer(answer);
 
-
     LinuxProcFsStatistics.refreshSystem(ints, longs, doubles);
     LinuxProcFsStatistics.refreshSystem(ints, longs, doubles);
 
@@ -150,14 +154,19 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
     });
   }
 
-  private File writeStringToFile(String string) throws IOException {
-    File file = File.createTempFile("LinuxSystemStatsTest", ".test");
-    file.deleteOnExit();
-    StringInputStream sis = new StringInputStream(string);
-    FileOutputStream fos = new FileOutputStream(file);
-    IOUtils.copy(sis, fos);
-    IOUtils.closeQuietly(fos);
-    return file;
+  /**
+   * This method will allow junit to mock up how Linux reports the CPU information though a file
+   * called "/proc/stat". We need to create a new file for each call since each file could represent
+   * another phase in the mock test.
+   */
+  private File writeStringToFile(String mockProcStatFileContents) throws IOException {
+
+    File mockFile = temporaryFolder.newFile();
+    StringInputStream sis = new StringInputStream(mockProcStatFileContents);
+    FileOutputStream mockFileOutputStream = new FileOutputStream(mockFile);
+    IOUtils.copy(sis, mockFileOutputStream);
+    IOUtils.closeQuietly(mockFileOutputStream);
+    return mockFile;
   }
 
   @Override
@@ -180,6 +189,7 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
 
     @Override
     public FileInputStream answer(InvocationOnMock invocation) throws Throwable {
+      // Since we are mocking the test we can run this test on any OS.
       if ("/proc/stat".equals(invocation.getArgument(0))) {
         return results.remove(0);
       }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.

[geode] 02/03: GEODE-3716 - Add an integration test for the Steal Time Stat.

Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 73f53bc21c77b848072dd317f887663d1b3836d8
Author: Charlie Black <ch...@github.com>
AuthorDate: Tue Oct 10 14:34:06 2017 -0700

    GEODE-3716 - Add an integration test for the Steal Time Stat.
---
 .../internal/statistics/LinuxSystemStatsTest.java  | 189 +++++++++++++++++++++
 1 file changed, 189 insertions(+)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java b/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
new file mode 100644
index 0000000..009eefa
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.internal.statistics;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.Statistics;
+import org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics;
+import org.apache.geode.internal.statistics.platform.LinuxSystemStats;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.tools.ant.filters.StringInputStream;
+import org.junit.*;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+
+/**
+ * Technically a linux only test - the file handling is all mocked up so the test can run on any
+ * host os.
+ */
+@Category(IntegrationTest.class)
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("*.IntegrationTest")
+@PrepareForTest(LinuxProcFsStatistics.class)
+@Ignore
+public class LinuxSystemStatsTest extends StatSamplerTestCase {
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+  private int[] ints;
+  private long[] longs;
+  private double[] doubles;
+  private LocalStatisticsFactory statisticsFactory;
+  private File testDir;
+
+  @Before
+  public void setUp() throws Exception {
+    this.testDir = this.temporaryFolder.getRoot();
+    assertTrue(this.testDir.exists());
+    System.setProperty(SimpleStatSampler.ARCHIVE_FILE_NAME_PROPERTY, this.testDir.getAbsolutePath()
+        + File.separator + SimpleStatSampler.DEFAULT_ARCHIVE_FILE_NAME);
+    LinuxProcFsStatistics.init();
+    initStats();
+    StatisticsTypeImpl statisticsType = (StatisticsTypeImpl) LinuxSystemStats.getType();
+    LocalStatisticsImpl statistics = (LocalStatisticsImpl) getStatisticsManager()
+        .createStatistics(statisticsType, statisticsType.getName());
+
+    ints = statistics._getIntStorage();
+    longs = statistics._getLongStorage();
+    doubles = statistics._getDoubleStorage();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    StatisticsTypeFactoryImpl.clear();
+    if (this.statisticsFactory != null) {
+      this.statisticsFactory.close();
+      this.statisticsFactory = null;
+    }
+  }
+
+  @Test
+  public void testFlatStealTime() throws Exception {
+    String[] results = {"cpu  0 0 0 0 0 0 0 0 0 0",
+        // add on 4 clicks 4 idle 0 steal
+        "cpu  0 0 0 4 0 0 0 0 0 0"};
+
+    doTest(results, 0);
+  }
+
+  @Test
+  public void test25PercentStealTime() throws Exception {
+
+    String[] results = {"cpu  0 0 0 0 0 0 0 0 0 0",
+        // add on 4 clicks 3 idle 1 steal
+        "cpu  0 0 0 3 0 0 0 1 0 0"};
+
+    doTest(results, 25);
+  }
+
+  @Test
+  public void test66PercentStealTime() throws Exception {
+
+    String[] results = {"cpu  0 0 0 0 0 0 0 0 0 0",
+        // add on 3 clicks 1 idle 2 steal
+        "cpu  0 0 0 1 0 0 0 2 0 0"};
+
+    doTest(results, 66);
+  }
+
+  @Test
+  public void test100PercentStealTime() throws Exception {
+
+    String[] results = {"cpu  0 0 0 0 0 0 0 0 0 0",
+        // add on 1 clicks 0 idle 1 steal
+        "cpu  0 0 0 0 0 0 0 1 0 0"};
+    doTest(results, 100);
+  }
+
+  protected void doTest(String[] results, int expectedStatValue) throws Exception {
+
+    Answer<FileInputStream> answer = new MyStealTimeAnswer(results);
+    PowerMockito.whenNew(FileInputStream.class).withArguments(anyString()).thenAnswer(answer);
+
+
+    LinuxProcFsStatistics.refreshSystem(ints, longs, doubles);
+    LinuxProcFsStatistics.refreshSystem(ints, longs, doubles);
+
+    Statistics[] statistics = getStatisticsManager().findStatisticsByTextId("LinuxSystemStats");
+    waitForExpectedStatValue(statistics[0], "cpuSteal", expectedStatValue, 20000, 10);
+  }
+
+  protected void initStats() {
+    statisticsFactory = new LocalStatisticsFactory(new CancelCriterion() {
+      public String cancelInProgress() {
+        return null;
+      }
+
+      public RuntimeException generateCancelledException(Throwable e) {
+        return null;
+      }
+    });
+  }
+
+  private File writeStringToFile(String string) throws IOException {
+    File file = File.createTempFile("LinuxSystemStatsTest", ".test");
+    file.deleteOnExit();
+    StringInputStream sis = new StringInputStream(string);
+    FileOutputStream fos = new FileOutputStream(file);
+    IOUtils.copy(sis, fos);
+    IOUtils.closeQuietly(fos);
+    return file;
+  }
+
+  @Override
+  protected StatisticsManager getStatisticsManager() {
+    return this.statisticsFactory;
+  }
+
+
+  private class MyStealTimeAnswer implements Answer<FileInputStream> {
+
+    private List<FileInputStream> results = new ArrayList<>();
+    private FileInputStream bogus;
+
+    public MyStealTimeAnswer(String[] samples) throws IOException {
+      for (String item : samples) {
+        results.add(new FileInputStream(writeStringToFile(item)));
+      }
+      bogus = new FileInputStream(writeStringToFile(""));
+    }
+
+    @Override
+    public FileInputStream answer(InvocationOnMock invocation) throws Throwable {
+      if ("/proc/stat".equals(invocation.getArgument(0))) {
+        return results.remove(0);
+      }
+      return bogus;
+    }
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.

[geode] 01/03: GEODE-3716 - Adding steal time metrics to Geode.

Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 00da97d3451097cecbc2eb66243c195ca6d54a92
Author: Charlie Black <ch...@github.com>
AuthorDate: Fri Oct 6 00:47:43 2017 -0700

    GEODE-3716 - Adding steal time metrics to Geode.
---
 .../internal/statistics/platform/LinuxProcFsStatistics.java  | 12 +++++++-----
 .../geode/internal/statistics/platform/LinuxSystemStats.java |  6 +++++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxProcFsStatistics.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxProcFsStatistics.java
index 0b7ec0b..27eabf3 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxProcFsStatistics.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxProcFsStatistics.java
@@ -33,6 +33,7 @@ public class LinuxProcFsStatistics {
     IOWAIT,
     IRQ,
     SOFTIRQ,
+    STEAL,
     /** stands for aggregation of all columns not present in the enum list */
     OTHER
   }
@@ -150,6 +151,7 @@ public class LinuxProcFsStatistics {
             ints[LinuxSystemStats.cpuNiceINT] = cpuData[CPU.NICE.ordinal()];
             ints[LinuxSystemStats.cpuSystemINT] = cpuData[CPU.SYSTEM.ordinal()];
             ints[LinuxSystemStats.cpuUserINT] = cpuData[CPU.USER.ordinal()];
+            ints[LinuxSystemStats.cpuStealINT] = cpuData[CPU.STEAL.ordinal()];
             ints[LinuxSystemStats.iowaitINT] = cpuData[CPU.IOWAIT.ordinal()];
             ints[LinuxSystemStats.irqINT] = cpuData[CPU.IRQ.ordinal()];
             ints[LinuxSystemStats.softirqINT] = cpuData[CPU.SOFTIRQ.ordinal()];
@@ -637,12 +639,12 @@ public class LinuxProcFsStatistics {
       st.skipToken(); // cpu name
       final int MAX_CPU_STATS = CPU.values().length;
       /*
-       * newer kernels now have 8 columns for cpu in /proc/stat (up from 7). This number may
-       * increase even further, hence we now use List in place of long[]. We add up entries from all
-       * columns after 7 into CPU.OTHER
+       * newer kernels now have 10 columns for cpu in /proc/stat. This number may increase even
+       * further, hence we now use List in place of long[]. We add up entries from all columns after
+       * MAX_CPU_STATS into CPU.OTHER
        */
-      List<Long> newStats = new ArrayList<Long>(8);
-      List<Long> diffs = new ArrayList<Long>(8);
+      List<Long> newStats = new ArrayList<Long>(10);
+      List<Long> diffs = new ArrayList<Long>(10);
       long total_change = 0;
       int actualCpuStats = 0;
       long unaccountedCpuUtilization = 0;
diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
index f95a09d..8dbb2df 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
@@ -46,6 +46,7 @@ public class LinuxSystemStats {
   final static int cachedMemoryINT = 16;
   final static int dirtyMemoryINT = 17;
   final static int cpuNonUserINT = 18;
+  final static int cpuStealINT = 19;
 
   final static int loopbackPacketsLONG = 0;
   final static int loopbackBytesLONG = 1;
@@ -143,7 +144,9 @@ public class LinuxSystemStats {
             f.createIntGauge("cpuNonUser",
                 "The percentage of total available time that has been used to execute non-user code.(includes system, iowait, irq, softirq etc.)",
                 "%"),
-
+            f.createIntGauge("cpuSteal",
+                "Stolen time, which is the time spent in their operating systems when running in a virtualized environment.",
+                "%"),
 
             f.createLongCounter("loopbackPackets",
                 "The number of network packets sent (or received) on the loopback interface",
@@ -245,6 +248,7 @@ public class LinuxSystemStats {
     checkOffset("cachedMemory", cachedMemoryINT);
     checkOffset("dirtyMemory", dirtyMemoryINT);
     checkOffset("cpuNonUser", cpuNonUserINT);
+    checkOffset("cpuSteal", cpuStealINT);
 
     checkOffset("loopbackPackets", loopbackPacketsLONG);
     checkOffset("loopbackBytes", loopbackBytesLONG);

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.