Skip to content

Commit

Permalink
add Time as property for sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ripreal committed Nov 16, 2017
1 parent 941ff61 commit 2a4a952
Show file tree
Hide file tree
Showing 10 changed files with 587 additions and 243 deletions.
694 changes: 454 additions & 240 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified releases/v8LogScanner.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public String getTip() {
public void execute() {
V8LogScannerAppl appl = V8LogScannerAppl.instance();

String[] sortingProps = new String[2];
String[] sortingProps = new String[3];
sortingProps[0] = "Events_amount";
sortingProps[1] = PropTypes.Duration.toString();
sortingProps[2] = PropTypes.Time.toString();

String userInput = appl.getConsole().askInputFromList("input prop which will be used to sort result:", sortingProps);
if (userInput == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.v8LogScanner.cmdScanner;

import org.v8LogScanner.cmdAppl.CmdCommand;
import org.v8LogScanner.rgx.ScanProfile;

public class CmdGetTopThisHourEvents implements CmdCommand {
@Override
public String getTip() {
return "";
}

@Override
public void execute() {
V8LogScannerAppl appl = V8LogScannerAppl.instance();
ScanProfile.buildTopThisHourEvents(appl.profile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void runAppl() {

// Item 4.
main.add(new MenuItemCmd("Auto profiles", null, m_autoModes));
m_autoModes.add(new MenuItemCmd("Find latest in this hour events", new CmdGetTopThisHourEvents(), cursorLogScan));
m_autoModes.add(new MenuItemCmd("Find all users events", new CmdGetAllUserEvents(), heapLogScan));
m_autoModes.add(new MenuItemCmd("Find EXCP from rphost logs grouped by 'descr'", new CmdGetRphostExcp(), heapLogScan));
m_autoModes.add(new MenuItemCmd("Find EXCP caused by user", new CmdGetUserExcp(), heapLogScan));
Expand Down Expand Up @@ -184,7 +185,7 @@ public void runAppl() {
m_runServer.add(new MenuItemCmd("Run as a fullREST server (not work yet!)", null));

cmdAppl.setTitle(
"V8 Log Scanner v.1.0_beta"
"V8 Log Scanner v.1.1_beta"
+ "\nRuns on " + Constants.osType
+ "\n********************"
);
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/org/v8LogScanner/rgx/CursorOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

public class CursorOp extends AbstractOp {
Expand Down Expand Up @@ -65,7 +66,11 @@ public void execute(List<String> logFiles) {
}
afterSlize = syncReduced.size();
TreeMap<SortingKey, List<String>> rgxResult = finalReduction(syncReduced);

totalKeys = rgxResult.keySet().size();

sortLogs(rgxResult);

selector.setResult(rgxResult);
calc.end();
}
Expand Down Expand Up @@ -170,6 +175,18 @@ private TreeMap<SortingKey, List<String>> finalReduction(Collection<String> sour
return rgxResult;
}

private void sortLogs(TreeMap<SortingKey, List<String>> rgxResult) {

saveProcessingInfo("\n*SORTING...");

rgxResult.entrySet().
parallelStream().
forEach(n -> n.getValue().
sort(RgxOpManager::compare));

saveProcessingInfo("Sorting completed.");
}

private SortingKey createSortingKey(String input) {

String eventKey = RgxOpManager.getEventProperty(
Expand All @@ -179,6 +196,8 @@ private SortingKey createSortingKey(String input) {

if (sortingProp == PropTypes.Duration)
return new DurationKey(eventKey, sortingKey);
else if (sortingProp == PropTypes.Time)
return new TimeKey(eventKey, sortingKey, RgxOpManager.getTimeText(input));
else
return new SizeKey(eventKey, sortingKey);
}
Expand Down Expand Up @@ -319,4 +338,54 @@ public String toString() {
}
}

public class TimeKey implements SortingKey {

final String key;
private BigInteger sortingKey;
private String time;

public TimeKey(String key, BigInteger sortingKey, String time) {
this.key = key;
this.sortingKey = sortingKey;
this.time = time;
}

public String getKey() {
return key;
}

public BigInteger getSortingKey() {
return sortingKey;
}

public void setSortingKey(BigInteger sortingKey) {
this.sortingKey = sortingKey;
}

@Override
public int compareTo(SortingKey o) {
int comparedVal = sortingKey.compareTo(o.getSortingKey());
return -comparedVal;
}

public int hashCode() {
return sortingKey.hashCode();
}

public boolean equals(Object x) {
if (x == this)
return true;
if (x == null || (!(x instanceof DurationKey)))
return false;

DurationKey other = (DurationKey) x;
return sortingKey.equals(other.getSortingKey());
}

@Override
public String toString() {
return String.format("TIME: %s \nGROUP: %s", time, key);
}
}

}
8 changes: 8 additions & 0 deletions src/main/java/org/v8LogScanner/rgx/RgxOpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,12 @@ public static BigInteger getTime(String input) {
return time;
}

public static String getTimeText(String input) {
String time = "00:00";
Matcher timeMatcher = timePattern.matcher(input);
if (timeMatcher.find())
time = timeMatcher.group();
return time;
}

}
8 changes: 8 additions & 0 deletions src/main/java/org/v8LogScanner/rgx/ScanProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,12 @@ static void BuildFindSlowSQlEventsWithPlan(ScanProfile profile, String queryPlan
profile.setSortingProp(PropTypes.Duration);
}

static void buildTopThisHourEvents(ScanProfile profile) {
profile.clear();
profile.setRgxOp(RgxOpTypes.CURSOR_OP);
profile.setSortingProp(PropTypes.Time);
profile.addRegExp(new RegExp(RegExp.EventTypes.ANY));
profile.setDateRange(DateRanges.THIS_HOUR);
}

}
27 changes: 26 additions & 1 deletion src/test/java/org/v8LogScanner/testV8LogScanner/TestRgxOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void testStartRgxOp() throws Exception {
ScanProfile profile = localClient.getProfile();
profile.addLogPath(logFileName);
profile.addRegExp(new RegExp(EventTypes.EXCP));
profile.setSortingProp(PropTypes.ANY);
manager.startRgxOp();
List<SelectorEntry> logs = localClient.select(100, SelectDirections.FORWARD);

Expand Down Expand Up @@ -130,6 +131,7 @@ public void testGroupBySeveralProps() {
event.getGroupingProps().add(PropTypes.ClientID);
event.getGroupingProps().add(PropTypes.ComputerName);
profile.addRegExp(event);
profile.setSortingProp(PropTypes.ANY);

client.startRgxOp();
List<SelectorEntry> logs = client.select(100, SelectDirections.FORWARD);
Expand Down Expand Up @@ -394,7 +396,7 @@ public void testVSRQuieries() {
rgx.getFilter(PropTypes.Method).add("GET");
profile.addRegExp(rgx);
profile.addRegExp(new RegExp(EventTypes.VRSRESPONSE));

profile.setSortingProp(PropTypes.ANY);
localClient.startRgxOp();
List<SelectorEntry> entries = localClient.select(100, SelectDirections.FORWARD);
assertEquals(2, entries.size());
Expand Down Expand Up @@ -443,4 +445,27 @@ public void testUserScanOp() {
List<SelectorEntry> entries = localClient.select(100, SelectDirections.FORWARD);
assertEquals(1, entries.size());
}

@Test
public void testTopThisHourEvents() {
String logFileName = constructor
.addEXCP()
.addVRSREQUEST()
.build(LogFileTypes.FILE);

ClientsManager manager = new ClientsManager();
V8LogScannerClient localClient = manager.localClient();

ScanProfile profile = localClient.getProfile();
ScanProfile.buildTopThisHourEvents(profile);
profile.setDateRange(ScanProfile.DateRanges.ANY); // reset due limits in the test data
profile.addLogPath(logFileName);
manager.startRgxOp();
List<SelectorEntry> logs = localClient.select(100, SelectDirections.FORWARD);

assertEquals(3, logs.size());

V8LogFileConstructor.deleteLogFile(logFileName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void testSelect() {

client.getProfile().addLogPath(file);
client.getProfile().addRegExp(new RegExp());
client.getProfile().setSortingProp(RegExp.PropTypes.ANY);
client.startRgxOp();
List<SelectorEntry> entries = client.select(100, IRgxSelector.SelectDirections.FORWARD);
assertEquals(3, entries.size());
Expand Down

0 comments on commit 2a4a952

Please sign in to comment.