diff --git a/Zutil.jar b/Zutil.jar index 698715a..d9d0cb1 100644 Binary files a/Zutil.jar and b/Zutil.jar differ diff --git a/src/zutil/Timer.java b/src/zutil/Timer.java index 15b628e..0d3442a 100644 --- a/src/zutil/Timer.java +++ b/src/zutil/Timer.java @@ -40,9 +40,16 @@ public class Timer { reset(); } + /** + * Will start or restart the timer if it is already running + */ public void start(){ timestamp = System.currentTimeMillis(); } + + /** + * Will reset the timer so that {@link #hasTimedOut()} returns true + */ public void reset(){ timestamp = -1; } diff --git a/src/zutil/osal/HALLinuxImpl.java b/src/zutil/osal/HalLinuxImpl.java similarity index 90% rename from src/zutil/osal/HALLinuxImpl.java rename to src/zutil/osal/HalLinuxImpl.java index e032950..982d601 100644 --- a/src/zutil/osal/HALLinuxImpl.java +++ b/src/zutil/osal/HalLinuxImpl.java @@ -25,7 +25,7 @@ package zutil.osal; /** * Created by Ziver on 2015-04-07. */ -public class HALLinuxImpl implements HardwareAbstractionLayer{ +public class HalLinuxImpl implements HardwareAbstractionLayer{ - protected HALLinuxImpl(){} + protected HalLinuxImpl(){} } diff --git a/src/zutil/osal/OsalLinuxImpl.java b/src/zutil/osal/OsalLinuxImpl.java index cf0d268..9ff3a2d 100644 --- a/src/zutil/osal/OsalLinuxImpl.java +++ b/src/zutil/osal/OsalLinuxImpl.java @@ -28,7 +28,7 @@ import java.io.File; * User: Ziver */ public class OsalLinuxImpl extends OSAbstractionLayer { - private static HALLinuxImpl hal; + private static HalLinuxImpl hal; @Override public OSType getOSType() { @@ -78,7 +78,7 @@ public class OsalLinuxImpl extends OSAbstractionLayer { @Override public HardwareAbstractionLayer getHAL() { if(hal == null) - hal = new HALLinuxImpl(); + hal = new HalLinuxImpl(); return hal; } } diff --git a/src/zutil/osal/app/linux/ProcStat.java b/src/zutil/osal/app/linux/ProcStat.java index 36d9198..f1db713 100644 --- a/src/zutil/osal/app/linux/ProcStat.java +++ b/src/zutil/osal/app/linux/ProcStat.java @@ -23,6 +23,7 @@ package zutil.osal.app.linux; import zutil.log.LogUtil; +import zutil.Timer; import java.io.BufferedReader; import java.io.FileReader; @@ -46,13 +47,13 @@ public class ProcStat { private static ArrayList cpus = new ArrayList(); private static long uptime; private static long processes; - private static long updateTimestamp; + private static Timer updateTimer = new Timer(TTL); private synchronized static void update(){ - if(System.currentTimeMillis() - updateTimestamp < TTL) + if(updateTimer.hasTimedOut()) return; - updateTimestamp = System.currentTimeMillis(); + updateTimer.start(); try { BufferedReader in = new BufferedReader(new FileReader(PROC_PATH)); String line = null; diff --git a/src/zutil/osal/app/windows/TypePerf.java b/src/zutil/osal/app/windows/TypePerf.java new file mode 100644 index 0000000..1efbd58 --- /dev/null +++ b/src/zutil/osal/app/windows/TypePerf.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015 ezivkoc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.osal.app.windows; + +/** + * Created by ezivkoc on 2015-07-30. + */ +public class TypePerf { + // Only available Vista -> + //https://www.webperformance.com/support/suite/manual/Content/Locating_Server_Metric_Counters.htm + + /* + "(PDH-CSV 4.0)","\\SE00035694\processor(0)\% Processor Time","\\SE00035694\processor(0)\% User Time","\\SE00035694\processor(0)\% Privileged Time","\\SE00035694\processor(0)\Interrupts/sec","\\SE00035694\processor(0)\% DPC Time","\\SE00035694\processor(0)\% Interrupt Time","\\SE00035694\processor(0)\DPCs Queued/sec","\\SE00035694\processor(0)\DPC Rate","\\SE00035694\processor(0)\% Idle Time","\\SE00035694\processor(0)\% C1 Time","\\SE00035694\processor(0)\% C2 Time","\\SE00035694\processor(0)\% C3 Time","\\SE00035694\processor(0)\C1 Transitions/sec","\\SE00035694\processor(0)\C2 Transitions/sec","\\SE00035694\processor(0)\C3 Transitions/sec","\\SE00035694\processor(1)\% Processor Time","\\SE00035694\processor(1)\% User Time","\\SE00035694\processor(1)\% Privileged Time","\\SE00035694\processor(1)\Interrupts/sec","\\SE00035694\processor(1)\% DPC Time","\\SE00035694\processor(1)\% Interrupt Time","\\SE00035694\processor(1)\DPCs Queued/sec","\\SE00035694\processor(1)\DPC Rate","\\SE00035694\processor(1)\% Idle Time","\\SE00035694\processor(1)\% C1 Time","\\SE00035694\processor(1)\% C2 Time","\\SE00035694\processor(1)\% C3 Time","\\SE00035694\processor(1)\C1 Transitions/sec","\\SE00035694\processor(1)\C2 Transitions/sec","\\SE00035694\processor(1)\C3 Transitions/sec","\\SE00035694\processor(2)\% Processor Time","\\SE00035694\processor(2)\% User Time","\\SE00035694\processor(2)\% Privileged Time","\\SE00035694\processor(2)\Interrupts/sec","\\SE00035694\processor(2)\% DPC Time","\\SE00035694\processor(2)\% Interrupt Time","\\SE00035694\processor(2)\DPCs Queued/sec","\\SE00035694\processor(2)\DPC Rate","\\SE00035694\processor(2)\% Idle Time","\\SE00035694\processor(2)\% C1 Time","\\SE00035694\processor(2)\% C2 Time","\\SE00035694\processor(2)\% C3 Time","\\SE00035694\processor(2)\C1 Transitions/sec","\\SE00035694\processor(2)\C2 Transitions/sec","\\SE00035694\processor(2)\C3 Transitions/sec","\\SE00035694\processor(3)\% Processor Time","\\SE00035694\processor(3)\% User Time","\\SE00035694\processor(3)\% Privileged Time","\\SE00035694\processor(3)\Interrupts/sec","\\SE00035694\processor(3)\% DPC Time","\\SE00035694\processor(3)\% Interrupt Time","\\SE00035694\processor(3)\DPCs Queued/sec","\\SE00035694\processor(3)\DPC Rate","\\SE00035694\processor(3)\% Idle Time","\\SE00035694\processor(3)\% C1 Time","\\SE00035694\processor(3)\% C2 Time","\\SE00035694\processor(3)\% C3 Time","\\SE00035694\processor(3)\C1 Transitions/sec","\\SE00035694\processor(3)\C2 Transitions/sec","\\SE00035694\processor(3)\C3 Transitions/sec","\\SE00035694\processor(_Total)\% Processor Time","\\SE00035694\processor(_Total)\% User Time","\\SE00035694\processor(_Total)\% Privileged Time","\\SE00035694\processor(_Total)\Interrupts/sec","\\SE00035694\processor(_Total)\% DPC Time","\\SE00035694\processor(_Total)\% Interrupt Time","\\SE00035694\processor(_Total)\DPCs Queued/sec","\\SE00035694\processor(_Total)\DPC Rate","\\SE00035694\processor(_Total)\% Idle Time","\\SE00035694\processor(_Total)\% C1 Time","\\SE00035694\processor(_Total)\% C2 Time","\\SE00035694\processor(_Total)\% C3 Time","\\SE00035694\processor(_Total)\C1 Transitions/sec","\\SE00035694\processor(_Total)\C2 Transitions/sec","\\SE00035694\processor(_Total)\C3 Transitions/sec" + "07/30/2015 11:53:49.003","4.331731","4.629110","0.000000","1251.466768","0.000000","0.000000","58.368806","0.000000","95.668269","4.370950","3.882572","71.775440","219.624998","61.336711","1197.055170","4.331731","0.000000","1.543037","342.298420","1.543037","0.000000","147.405967","0.000000","98.754342","0.000000","0.000000","95.856588","0.000000","0.000000","341.309119","5.874768","6.172146","0.000000","1282.135124","0.000000","0.000000","23.743243","0.000000","94.125232","0.000000","0.000000","86.960208","0.000000","0.000000","1496.813613","4.331731","0.000000","0.000000","253.261259","0.000000","0.000000","19.786036","1.000000","100.297379","0.000000","0.000000","94.635420","0.000000","0.000000","265.132881","4.717488","2.700317","0.385757","3129.161571","0.385757","0.000000","249.304052","1.000000","97.211306","1.092740","0.970643","87.306914","219.624998","61.336711","3300.310781" + */ + private static final String PERF_CPU_PATH = "\\Processor(*)\\*"; + + /* + "(PDH-CSV 4.0)","\\SE00035694\Memory\Page Faults/sec","\\SE00035694\Memory\Available Bytes","\\SE00035694\Memory\Committed Bytes","\\SE00035694\Memory\Commit Limit","\\SE00035694\Memory\Write Copies/sec","\\SE00035694\Memory\Transition Faults/sec","\\SE00035694\Memory\Cache Faults/sec","\\SE00035694\Memory\Demand Zero Faults/sec","\\SE00035694\Memory\Pages/sec","\\SE00035694\Memory\Pages Input/sec","\\SE00035694\Memory\Page Reads/sec","\\SE00035694\Memory\Pages Output/sec","\\SE00035694\Memory\Pool Paged Bytes","\\SE00035694\Memory\Pool Nonpaged Bytes","\\SE00035694\Memory\Page Writes/sec","\\SE00035694\Memory\Pool Paged Allocs","\\SE00035694\Memory\Pool Nonpaged Allocs","\\SE00035694\Memory\Free System Page Table Entries","\\SE00035694\Memory\Cache Bytes","\\SE00035694\Memory\Cache Bytes Peak","\\SE00035694\Memory\Pool Paged Resident Bytes","\\SE00035694\Memory\System Code Total Bytes","\\SE00035694\Memory\System Code Resident Bytes","\\SE00035694\Memory\System Driver Total Bytes","\\SE00035694\Memory\System Driver Resident Bytes","\\SE00035694\Memory\System Cache Resident Bytes","\\SE00035694\Memory\% Committed Bytes In Use","\\SE00035694\Memory\Available KBytes","\\SE00035694\Memory\Available MBytes","\\SE00035694\Memory\Transition Pages RePurposed/sec","\\SE00035694\Memory\Free & Zero Page List Bytes","\\SE00035694\Memory\Modified Page List Bytes","\\SE00035694\Memory\Standby Cache Reserve Bytes","\\SE00035694\Memory\Standby Cache Normal Priority Bytes","\\SE00035694\Memory\Standby Cache Core Bytes" + "07/30/2015 11:54:52.288","1158.202545","1403789312.000000","7621783552.000000","18949070848.000000","0.000000","13.942249","1.991750","1142.268546","0.000000","0.000000","0.000000","0.000000","408887296.000000","184975360.000000","0.000000","430072.000000","242142.000000","33556038.000000","600846336.000000","650051584.000000","408686592.000000","4395008.000000","2433024.000000","19406848.000000","10178560.000000","600846336.000000","40.222466","1370888.000000","1338.000000","0.000000","25022464.000000","46465024.000000","24576.000000","1378742272.000000","0.000000" + */ + private static final String PERF_MEM_PATH = "\\Memory\\*"; + + /* + "(PDH-CSV 4.0)","\\SE00035694\PhysicalDisk(0 C: D: E:)\Current Disk Queue Length","\\SE00035694\PhysicalDisk(0 C: D: E:)\% Disk Time","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk Queue Length","\\SE00035694\PhysicalDisk(0 C: D: E:)\% Disk Read Time","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk Read Queue Length","\\SE00035694\PhysicalDisk(0 C: D: E:)\% Disk Write Time","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk Write Queue Length","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk sec/Transfer","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk sec/Read","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk sec/Write","\\SE00035694\PhysicalDisk(0 C: D: E:)\Disk Transfers/sec","\\SE00035694\PhysicalDisk(0 C: D: E:)\Disk Reads/sec","\\SE00035694\PhysicalDisk(0 C: D: E:)\Disk Writes/sec","\\SE00035694\PhysicalDisk(0 C: D: E:)\Disk Bytes/sec","\\SE00035694\PhysicalDisk(0 C: D: E:)\Disk Read Bytes/sec","\\SE00035694\PhysicalDisk(0 C: D: E:)\Disk Write Bytes/sec","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk Bytes/Transfer","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk Bytes/Read","\\SE00035694\PhysicalDisk(0 C: D: E:)\Avg. Disk Bytes/Write","\\SE00035694\PhysicalDisk(0 C: D: E:)\% Idle Time","\\SE00035694\PhysicalDisk(0 C: D: E:)\Split IO/Sec","\\SE00035694\PhysicalDisk(_Total)\Current Disk Queue Length","\\SE00035694\PhysicalDisk(_Total)\% Disk Time","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk Queue Length","\\SE00035694\PhysicalDisk(_Total)\% Disk Read Time","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk Read Queue Length","\\SE00035694\PhysicalDisk(_Total)\% Disk Write Time","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk Write Queue Length","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk sec/Transfer","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk sec/Read","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk sec/Write","\\SE00035694\PhysicalDisk(_Total)\Disk Transfers/sec","\\SE00035694\PhysicalDisk(_Total)\Disk Reads/sec","\\SE00035694\PhysicalDisk(_Total)\Disk Writes/sec","\\SE00035694\PhysicalDisk(_Total)\Disk Bytes/sec","\\SE00035694\PhysicalDisk(_Total)\Disk Read Bytes/sec","\\SE00035694\PhysicalDisk(_Total)\Disk Write Bytes/sec","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk Bytes/Transfer","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk Bytes/Read","\\SE00035694\PhysicalDisk(_Total)\Avg. Disk Bytes/Write","\\SE00035694\PhysicalDisk(_Total)\% Idle Time","\\SE00035694\PhysicalDisk(_Total)\Split IO/Sec" + "07/30/2015 11:55:26.544","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100.148515","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100.148515","0.000000" + */ + private static final String PERF_DISK_PATH = "\\PhysicalDisk(*)\\*"; + + /* + "(PDH-CSV 4.0)","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Bytes Total/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Received/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Sent/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Current Bandwidth","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Bytes Received/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Received Unicast/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Received Discarded","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Received Errors","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Received Unknown","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Bytes Sent/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Sent Unicast/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Outbound Discarded","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Packets Outbound Errors","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Output Queue Length","\\SE00035694\Network Interface(Intel[R] Ethernet Connection I218-LM)\Offloaded Connections","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Bytes Total/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Received/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Sent/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Current Bandwidth","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Bytes Received/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Received Unicast/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Received Discarded","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Received Errors","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Received Unknown","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Bytes Sent/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Sent Unicast/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Outbound Discarded","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Packets Outbound Errors","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Output Queue Length","\\SE00035694\Network Interface(Intel[R] Dual Band Wireless-N 7260)\Offloaded Connections","\\SE00035694\Network Interface(6TO4 Adapter)\Bytes Total/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Received/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Sent/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Current Bandwidth","\\SE00035694\Network Interface(6TO4 Adapter)\Bytes Received/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Received Unicast/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Received Discarded","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Received Errors","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Received Unknown","\\SE00035694\Network Interface(6TO4 Adapter)\Bytes Sent/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Sent Unicast/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Outbound Discarded","\\SE00035694\Network Interface(6TO4 Adapter)\Packets Outbound Errors","\\SE00035694\Network Interface(6TO4 Adapter)\Output Queue Length","\\SE00035694\Network Interface(6TO4 Adapter)\Offloaded Connections","\\SE00035694\Network Interface(Local Area Connection* 12)\Bytes Total/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Received/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Sent/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Current Bandwidth","\\SE00035694\Network Interface(Local Area Connection* 12)\Bytes Received/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Received Unicast/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Received Discarded","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Received Errors","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Received Unknown","\\SE00035694\Network Interface(Local Area Connection* 12)\Bytes Sent/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Sent Unicast/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Outbound Discarded","\\SE00035694\Network Interface(Local Area Connection* 12)\Packets Outbound Errors","\\SE00035694\Network Interface(Local Area Connection* 12)\Output Queue Length","\\SE00035694\Network Interface(Local Area Connection* 12)\Offloaded Connections","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Bytes Total/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Received/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Sent/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Current Bandwidth","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Bytes Received/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Received Unicast/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Received Discarded","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Received Errors","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Received Unknown","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Bytes Sent/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Sent Unicast/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Outbound Discarded","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Packets Outbound Errors","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Output Queue Length","\\SE00035694\Network Interface(isatap.ki.sw.ericsson.se)\Offloaded Connections","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Bytes Total/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Received/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Sent/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Current Bandwidth","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Bytes Received/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Received Unicast/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Received Discarded","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Received Errors","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Received Unknown","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Bytes Sent/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Sent Unicast/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Outbound Discarded","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Packets Outbound Errors","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Output Queue Length","\\SE00035694\Network Interface(isatap.{B9D01222-E737-4A0B-8321-7FE782CD4197})\Offloaded Connections","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Bytes Total/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Received/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Sent/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Current Bandwidth","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Bytes Received/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Received Unicast/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Received Discarded","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Received Errors","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Received Unknown","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Bytes Sent/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Sent Unicast/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Outbound Discarded","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Packets Outbound Errors","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Output Queue Length","\\SE00035694\Network Interface(isatap.{BA17492A-F69D-42F3-890A-3E9B8D2DA7C9})\Offloaded Connections","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Bytes Total/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Received/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Sent/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Current Bandwidth","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Bytes Received/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Received Unicast/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Received Non-Unicast/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Received Discarded","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Received Errors","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Received Unknown","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Bytes Sent/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Sent Unicast/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Sent Non-Unicast/sec","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Outbound Discarded","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Packets Outbound Errors","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Output Queue Length","\\SE00035694\Network Interface(isatap.{A42279F6-5D04-468C-A354-23EC38A4D962})\Offloaded Connections" + "07/30/2015 11:56:40.899","6479.124376","13.269125","9.477947","3.791179","100000000.000000","6183.412438","5.686768","3.791179","0.000000","0.000000","0.000000","295.711938","3.791179","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","300000000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","30000000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","100000.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000","0.000000" + */ + private static final String PERF_NET_PATH = "\\Network Interface(*)\\*"; + + //typeperf "path" -SC 0 -y +} diff --git a/src/zutil/parser/CSVParser.java b/src/zutil/parser/CSVParser.java new file mode 100644 index 0000000..1f26be1 --- /dev/null +++ b/src/zutil/parser/CSVParser.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2015 ezivkoc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.parser; + +import zutil.struct.MutableInt; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; + +/** + * Created by Ziver + */ +public class CSVParser extends Parser{ + + private Reader in; + private char delimiter; + private boolean parseHeader; + + private DataNode headers; + + + public CSVParser(Reader in){ + this(in, false, ','); + } + public CSVParser(Reader in, boolean inclusedHeader){ + this(in, inclusedHeader, ','); + } + public CSVParser(Reader in, boolean includesHeader, char delimiter){ + this.in = in; + this.delimiter = delimiter; + this.parseHeader = includesHeader; + } + + public DataNode getHeaders() { + return headers; + } + + /** + * Starts parsing from a string + * + * @param csv is the JSON String to parse + * @return a DataNode object representing the JSON in the input String + */ + public static DataNode read(String csv){ + try{ + return new CSVParser(new StringReader(csv)).read(); + }catch (IOException e){ + e.printStackTrace(); + }catch (NullPointerException e){} + return null; + } + + + /** + * Starts parsing from the input. + * This method will block until one row has been parsed. + * + * @return a DataNode object representing a row in the CSV + */ + @Override + public DataNode read() throws IOException { + if(parseHeader) { + parseHeader = false; + headers = read(); + } + + DataNode data = new DataNode(DataNode.DataType.List); + StringBuilder value = new StringBuilder(); + boolean quoteStarted = false; + int c; + while((c=in.read()) >= 0 && c != '\n'){ + if(c == delimiter && !quoteStarted){ + data.add(value.toString()); + value.delete(0, value.length()); // Reset StringBuilder + } + else if(c == '\"' && // Ignored quotes + (value.length() == 0 || quoteStarted)){ + quoteStarted = !quoteStarted; + } + else + value.append((char)c); + } + if(value.length() > 0) + data.add(value.toString()); + if(data.size() == 0) + return null; + return data; + } +} diff --git a/src/zutil/parser/Parser.java b/src/zutil/parser/Parser.java new file mode 100644 index 0000000..50799ff --- /dev/null +++ b/src/zutil/parser/Parser.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015 ezivkoc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.parser; + +import zutil.struct.MutableInt; + +import java.io.IOException; +import java.io.StringReader; + +/** + * Created by Ziver + */ +public abstract class Parser { + + /** + * Starts parsing data from the input. + * This method will block until one {@link DataNode} has been parsed. + * + * @return a DataNode object representing one item from the input data + * or null it it is the end of the stream + */ + public abstract DataNode read() throws IOException; + +} diff --git a/src/zutil/parser/json/JSONParser.java b/src/zutil/parser/json/JSONParser.java index 2424483..b5d8abc 100644 --- a/src/zutil/parser/json/JSONParser.java +++ b/src/zutil/parser/json/JSONParser.java @@ -24,6 +24,7 @@ package zutil.parser.json; import zutil.parser.DataNode; import zutil.parser.DataNode.DataType; +import zutil.parser.Parser; import zutil.struct.MutableInt; import java.io.IOException; @@ -36,7 +37,7 @@ import java.util.regex.Pattern; * * @author Ziver */ -public class JSONParser{ +public class JSONParser extends Parser { public static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9.]++$"); public static final Pattern BOOLEAN_PATTERN = Pattern.compile("^(true|false)$", Pattern.CASE_INSENSITIVE); @@ -47,11 +48,12 @@ public class JSONParser{ } /** - * Starts parsing from the InputStream. + * Starts parsing from the input. * This method will block until one root tree has been parsed. * * @return a DataNode object representing the input JSON */ + @Override public DataNode read() throws IOException { return parse(in, new MutableInt()); } @@ -80,11 +82,13 @@ public class JSONParser{ DataNode node = null; end.i = 0; - char c = '_'; - while((c=(char)in.read()) < 0 || Character.isWhitespace(c) || - c == ',' || c == ':'); + int c = '_'; + while((c=in.read()) >= 0 && + (Character.isWhitespace(c) || c == ',' || c == ':')); switch( c ){ + // End of stream + case -1: break; // This is the end of an Map or List case ']': case '}': @@ -114,19 +118,19 @@ public class JSONParser{ case '\"': root = new DataNode(DataType.String); StringBuilder str = new StringBuilder(); - while((c=(char)in.read()) >= 0 && c != '\"') - str.append(c); + while((c=in.read()) >= 0 && c != '\"') + str.append((char)c); root.set(str.toString()); break; // Parse unknown type default: - StringBuilder tmp = new StringBuilder().append(c); - while((c=(char)in.read()) >= 0 && c != ',' && c != '='){ + StringBuilder tmp = new StringBuilder().append((char)c); + while((c=in.read()) >= 0 && c != ',' && c != '='){ if(c == ']' || c == '}'){ end.i = 1; break; } - tmp.append(c); + tmp.append((char)c); } // Check what type of type the data is String data = tmp.toString().trim(); diff --git a/src/zutil/test/CSVParserTest.java b/src/zutil/test/CSVParserTest.java new file mode 100644 index 0000000..147ea9d --- /dev/null +++ b/src/zutil/test/CSVParserTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2015 ezivkoc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.test; + +import org.junit.Test; +import zutil.parser.CSVParser; +import zutil.parser.DataNode; + +import java.io.IOException; +import java.io.StringReader; + +import static org.junit.Assert.*; + +/** + * Created by ezivkoc on 2015-07-30. + */ +public class CSVParserTest { + + + @Test + public void emptyTest(){ + DataNode node = CSVParser.read(""); + assertEquals(null, node); + } + + @Test + public void simpleTest(){ + DataNode node = CSVParser.read("hello,world,you"); + assertEquals(3, node.size()); + assertEquals("hello", node.get(0).getString()); + assertEquals("world", node.get(1).getString()); + assertEquals("you", node.get(2).getString()); + } + + @Test + public void simpleHeaderTest() throws IOException { + CSVParser parser = new CSVParser(new StringReader("where,what,who\nhello,world,you"), true); + DataNode node = parser.read(); + assertEquals(3, node.size()); + assertEquals("hello", node.get(0).getString()); + assertEquals("world", node.get(1).getString()); + assertEquals("you", node.get(2).getString()); + node = parser.getHeaders(); + assertEquals("where", node.get(0).getString()); + assertEquals("what", node.get(1).getString()); + assertEquals("who", node.get(2).getString()); + } + + @Test + public void simpleMultilineTest() throws IOException { + CSVParser parser = new CSVParser( + new StringReader("hello,world,you\nhello,world,you\nhello,world,you")); + int rows=0; + for(DataNode node = parser.read(); node != null; node=parser.read(), ++rows) { + assertEquals(3, node.size()); + assertEquals("hello", node.get(0).getString()); + assertEquals("world", node.get(1).getString()); + assertEquals("you", node.get(2).getString()); + } + assertEquals(3, rows); + } + + @Test + public void quotedTest(){ + DataNode node = CSVParser.read("\"hello\",\"world\",\"you\""); + assertEquals(3, node.size()); + assertEquals("hello", node.get(0).getString()); + assertEquals("world", node.get(1).getString()); + assertEquals("you", node.get(2).getString()); + } + + @Test + public void quotedIncorrectlyTest(){ + DataNode node = CSVParser.read("hello\",wo\"rl\"d,\"you\""); + assertEquals(3, node.size()); + assertEquals("hello\"", node.get(0).getString()); + assertEquals("wo\"rl\"d", node.get(1).getString()); + assertEquals("you", node.get(2).getString()); + } + + @Test + public void quotedCommaTest(){ + DataNode node = CSVParser.read("hello,\"world,you\""); + assertEquals(2, node.size()); + assertEquals("hello", node.get(0).getString()); + assertEquals("world,you", node.get(1).getString()); + } +} diff --git a/src/zutil/test/JSONTest.java b/src/zutil/test/JSONParserTest.java similarity index 96% rename from src/zutil/test/JSONTest.java rename to src/zutil/test/JSONParserTest.java index 16152b7..53f11dc 100644 --- a/src/zutil/test/JSONTest.java +++ b/src/zutil/test/JSONParserTest.java @@ -31,7 +31,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -public class JSONTest{ +public class JSONParserTest { @Test public void nullString(){