-
Notifications
You must be signed in to change notification settings - Fork 14
fix(ENGKNOW-2060): Add MetricsMonitor and fix pipe headers. #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e16f88a
fix(ENGKNOW-2060): Fix headers for added steps, and more.
gmagnu 44fe9c9
fix(ENGKNOW-2060): Fix headers for added steps, and more.
gmagnu 176eb95
fix(ENGKNOW-2060): Fix headers for added steps, and more. Add defau…
gmagnu f473f01
fix(ENGKNOW-2060): Fix headers for added steps, and more. Add defau…
gmagnu 2a6f89a
fix(ENGKNOW-2060): Fix headers for added steps, and more. Add defau…
gmagnu 4ad0035
fix(ENGKNOW-2060): Move to new test bucket.
gmagnu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
gortools/src/main/scala/gorsat/Monitors/StatsMonitor.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * BEGIN_COPYRIGHT | ||
| * | ||
| * Copyright (C) 2011-2013 deCODE genetics Inc. | ||
| * Copyright (C) 2013-2019 WuXi NextCode Inc. | ||
| * All Rights Reserved. | ||
| * | ||
| * GORpipe is free software: you can redistribute it and/or modify | ||
| * it under the terms of the AFFERO GNU General Public License as published by | ||
| * the Free Software Foundation. | ||
| * | ||
| * GORpipe is distributed "AS-IS" AND WITHOUT ANY WARRANTY OF ANY KIND, | ||
| * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, | ||
| * NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. See | ||
| * the AFFERO GNU General Public License for the complete license terms. | ||
| * | ||
| * You should have received a copy of the AFFERO GNU General Public License | ||
| * along with GORpipe. If not, see <http://www.gnu.org/licenses/agpl-3.0.html> | ||
| * | ||
| * END_COPYRIGHT | ||
| */ | ||
|
|
||
| package gorsat.Monitors | ||
|
|
||
| import gorsat.Commands.{Analysis, RowHeader} | ||
| import org.gorpipe.gor.model.Row | ||
|
|
||
| /** | ||
| * Collect basic stats about the analysis stream. | ||
| */ | ||
| case class StatsMonitor() extends Analysis { | ||
| var startTime: Long = System.currentTimeMillis | ||
| var stopTime = 0L | ||
|
|
||
| var rowCount = 0L | ||
| var bytesCount = 0L | ||
|
|
||
| override def isTypeInformationMaintained: Boolean = true | ||
|
|
||
| def elapsedTime(): Long = if (stopTime > 0) stopTime - startTime else System.currentTimeMillis - startTime | ||
|
|
||
| override def process(r : Row): Unit = { | ||
| bytesCount += r.length() | ||
| rowCount += 1 | ||
|
|
||
|
|
||
| super.process(r) | ||
| } | ||
| override def finish(): Unit = { | ||
| if (rowHeader == null) { | ||
| rowHeader = new RowHeader(Array(), Array()) | ||
| } | ||
| stopTime = System.currentTimeMillis; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
gortools/src/test/java/gorsat/monitors/StatsMonitorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package gorsat.monitors; | ||
|
|
||
| import gorsat.Analysis.ForkWrite; | ||
| import gorsat.Analysis.OutputOptions; | ||
| import gorsat.Monitors.StatsMonitor; | ||
| import gorsat.process.PipeInstance; | ||
| import org.gorpipe.gor.binsearch.GorIndexType; | ||
| import org.gorpipe.gor.monitor.GorMonitor; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import scala.Option; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.zip.Deflater; | ||
|
|
||
| import static gorsat.TestUtils.createPipeInstance; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class StatsMonitorTest{ | ||
|
|
||
| @Rule | ||
| public TemporaryFolder workDir = new TemporaryFolder(); | ||
| private Path workDirPath; | ||
|
|
||
| @Before | ||
| public void setupTest() { | ||
| workDirPath = workDir.getRoot().toPath(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRowCountAndBytesCount() { | ||
|
|
||
| var statsMonitor = new StatsMonitor(); | ||
| try (PipeInstance pipe = createPipeInstance(false)) { | ||
| pipe.init("gorrows -p chr1:1-1000 | calc a 'abc'", null); | ||
| pipe.lastStep().$bar(statsMonitor); | ||
|
|
||
| while (pipe.hasNext()) { | ||
| pipe.next(); | ||
| } | ||
| } | ||
|
|
||
| assertEquals("chrom\tpos\ta", statsMonitor.getHeader()); | ||
| assertEquals(999, statsMonitor.rowCount()); | ||
| assertEquals(11880, statsMonitor.bytesCount()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testElapsedTime() throws InterruptedException { | ||
| StatsMonitor monitor = new StatsMonitor(); | ||
| Thread.sleep(100); | ||
| monitor.finish(); | ||
|
|
||
| long elapsedTime = monitor.elapsedTime(); | ||
| assertTrue(elapsedTime >= 100); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRowCountAndBytesCountForSelfWriting() { | ||
|
|
||
| var statsMonitor = new StatsMonitor(); | ||
| try (PipeInstance pipe = createPipeInstance(false)) { | ||
| pipe.init("gorrows -p chr1:1-1000 | calc a 'abc' | write " + workDirPath.resolve("test.gor").toString(), new GorMonitor()); | ||
| pipe.lastStep().$bar(statsMonitor); | ||
|
|
||
| while (pipe.hasNext()) { | ||
| pipe.next(); | ||
| } | ||
| } | ||
|
|
||
| assertEquals("", statsMonitor.getHeader()); | ||
| assertEquals(0, statsMonitor.rowCount()); | ||
| assertEquals(0, statsMonitor.bytesCount()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRowCountAndBytesCountForAddedWrite() { | ||
|
|
||
| var statsMonitor = new StatsMonitor(); | ||
| ForkWrite forkWrite = null; | ||
| try (PipeInstance pipe = createPipeInstance(true)) { | ||
| pipe.init("gorrows -p chr1:1-1000 | calc a 'abc'", new GorMonitor()); | ||
| pipe.lastStep().$bar(statsMonitor); | ||
|
|
||
| var outputOptions = new OutputOptions(false, false, true, false, | ||
| false, GorIndexType.NONE, new String[0], new String[0], Option.empty(), Option.empty(), Deflater.BEST_SPEED, | ||
| Option.empty(), false, false, null, "", null, false, false); | ||
| forkWrite = new ForkWrite(-1, workDirPath.resolve("test.gor").toString(), pipe.getSession(), pipe.getHeader(), outputOptions); | ||
|
|
||
| pipe.lastStep().$bar(forkWrite); | ||
|
|
||
| while (pipe.hasNext()) { | ||
| pipe.next(); | ||
| } | ||
| } | ||
|
|
||
| assertEquals("chrom\tpos\ta", statsMonitor.getHeader()); | ||
| assertEquals(999, statsMonitor.rowCount()); | ||
| assertEquals(11880, statsMonitor.bytesCount()); | ||
|
|
||
| assertEquals("c84f18441d00c7ea79d233efdaf8f07b", forkWrite.getMd5()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hraðvirkara?