-
Notifications
You must be signed in to change notification settings - Fork 8
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
Routes and TDigest #72
Open
sumitjoshi1989
wants to merge
1
commit into
master
Choose a base branch
from
javabrake_apm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ bin | |
**target | ||
**.DS_Store | ||
**.vscode | ||
Main.java |
This file contains 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 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 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 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,128 @@ | ||
package io.airbrake.javabrake; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Metrics { | ||
public static int FLUSH_PERIOD = 15; | ||
|
||
Date startTime = new Date(); | ||
Date endTime; | ||
Map<String, Span> spans = new HashMap<>(); | ||
Span currSpan; | ||
Map<String, Long> groups = new HashMap<>(); | ||
|
||
public void end() { | ||
if (endTime == null) | ||
endTime = new Date(); | ||
} | ||
|
||
protected Span newSpan(String name, Date startTime) { | ||
return new Span(this, name, startTime); | ||
} | ||
|
||
public void startSpan(String name, Date startTime) { | ||
if (this.currSpan != null) { | ||
if (this.currSpan.name == name) { | ||
this.currSpan.level += 1; | ||
return; | ||
} | ||
this.currSpan.pause(); | ||
} | ||
|
||
Span span = this.spans.get(name); | ||
if (span == null) { | ||
span = this.newSpan(name, startTime); | ||
this.spans.put(name, span); | ||
} else | ||
span.resume(); | ||
|
||
span.parent = this.currSpan; | ||
this.currSpan = span; | ||
} | ||
|
||
public void endSpan(String name, Date endTime) { | ||
if (this.currSpan != null && this.currSpan.name == name) { | ||
if (this._endSpan(this.currSpan, endTime)) { | ||
this.currSpan = this.currSpan.parent; | ||
if (this.currSpan != null) | ||
this.currSpan.resume(); | ||
return; | ||
} | ||
} | ||
|
||
Span span = this.spans.get(name); | ||
if (span == null) | ||
return; | ||
this._endSpan(span, endTime); | ||
} | ||
|
||
protected boolean _endSpan(Span span, Date endTime) { | ||
|
||
if (span.level > 0) { | ||
span.level -= 1; | ||
return false; | ||
} | ||
|
||
span.end(endTime); | ||
this.spans.get(span.name); | ||
return true; | ||
|
||
} | ||
|
||
protected void _inc_group(String name, long ms) { | ||
this.groups.put(name, (this.groups.getOrDefault(name, (long) 0) + ms)); | ||
} | ||
} | ||
|
||
class Span { | ||
|
||
Metrics metric; | ||
Span parent; | ||
Date startTime; | ||
Date endTime; | ||
String name; | ||
long dur = 0; | ||
int level = 0; | ||
|
||
public Span(Metrics metric, String name, Date startTime) { | ||
this.metric = metric; | ||
this.startTime = startTime; | ||
this.name = name; | ||
} | ||
|
||
public void init() { | ||
this.startTime = new Date(); | ||
this.endTime = null; | ||
} | ||
|
||
public void end(Date endTime) { | ||
if (endTime != null) | ||
this.endTime = endTime; | ||
else { | ||
this.endTime = new Date(); | ||
} | ||
|
||
this.dur += (this.endTime.getTime() - this.metric.spans.get(this.name).startTime.getTime()); | ||
this.metric._inc_group(this.name, this.dur); | ||
this.metric = null; | ||
} | ||
|
||
protected void pause() { | ||
if (this.paused()) | ||
return; | ||
this.dur += (new Date().getTime() - this.startTime.getTime()); | ||
this.startTime = null; | ||
} | ||
|
||
protected boolean paused() { | ||
return this.startTime == null; | ||
} | ||
|
||
protected void resume() { | ||
if (!this.paused()) | ||
return; | ||
this.startTime = new Date(); | ||
} | ||
} |
This file contains 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 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.
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.
Please indent this one at the same level as the other lines.