code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
public Ansi bgBrightRed() { return this.bgBright(Color.RED); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
bgBrightRed
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi bgBrightYellow() { return this.bgBright(Color.YELLOW); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
bgBrightYellow
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(Attribute attribute) { attributeOptions.add(attribute.value()); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursor(final int x, final int y) { return appendEscapeSequence('H', x, y); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursor
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorToColumn(final int x) { return appendEscapeSequence('G', x); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorToColumn
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorUp(final int y) { return appendEscapeSequence('A', y); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorUp
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorDown(final int y) { return appendEscapeSequence('B', y); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorDown
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorRight(final int x) { return appendEscapeSequence('C', x); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorRight
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorLeft(final int x) { return appendEscapeSequence('D', x); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorLeft
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorDownLine() { return appendEscapeSequence('E'); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorDownLine
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorDownLine(final int n) { return appendEscapeSequence('E', n); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorDownLine
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorUpLine() { return appendEscapeSequence('F'); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorUpLine
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi cursorUpLine(final int n) { return appendEscapeSequence('F', n); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
cursorUpLine
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi eraseScreen() { return appendEscapeSequence('J', Erase.ALL.value()); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
eraseScreen
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi eraseScreen(final Erase kind) { return appendEscapeSequence('J', kind.value()); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
eraseScreen
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi eraseLine() { return appendEscapeSequence('K'); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
eraseLine
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi eraseLine(final Erase kind) { return appendEscapeSequence('K', kind.value()); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
eraseLine
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi scrollUp(final int rows) { return appendEscapeSequence('S', rows); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
scrollUp
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi scrollDown(final int rows) { return appendEscapeSequence('T', rows); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
scrollDown
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi saveCursorPosition() { return appendEscapeSequence('s'); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
saveCursorPosition
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
@Deprecated public Ansi restorCursorPosition() { return appendEscapeSequence('u'); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
restorCursorPosition
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi restoreCursorPosition() { return appendEscapeSequence('u'); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
restoreCursorPosition
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi reset() { return a(Attribute.RESET); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
reset
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi bold() { return a(Attribute.INTENSITY_BOLD); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
bold
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi boldOff() { return a(Attribute.INTENSITY_BOLD_OFF); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
boldOff
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(String value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(boolean value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(char value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(char[] value, int offset, int len) { flushAttributes(); builder.append(value, offset, len); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(char[] value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(CharSequence value, int start, int end) { flushAttributes(); builder.append(value, start, end); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(CharSequence value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(double value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(float value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(int value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(long value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(Object value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi a(StringBuffer value) { flushAttributes(); builder.append(value); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
a
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi newline() { flushAttributes(); builder.append(System.getProperty("line.separator")); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
newline
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
public Ansi format(String pattern, Object... args) { flushAttributes(); builder.append(String.format(pattern, args)); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
format
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
@Override public String toString() { flushAttributes(); return builder.toString(); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
toString
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
private Ansi appendEscapeSequence(char command) { flushAttributes(); builder.append(FIRST_ESC_CHAR); builder.append(SECOND_ESC_CHAR); builder.append(command); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
appendEscapeSequence
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
private Ansi appendEscapeSequence(char command, int option) { flushAttributes(); builder.append(FIRST_ESC_CHAR); builder.append(SECOND_ESC_CHAR); builder.append(option); builder.append(command); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
appendEscapeSequence
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
private Ansi appendEscapeSequence(char command, Object... options) { flushAttributes(); return _appendEscapeSequence(command, options); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
appendEscapeSequence
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
private void flushAttributes() { if (attributeOptions.isEmpty()) { return; } if (attributeOptions.size() == 1 && attributeOptions.get(0) == 0) { builder.append(FIRST_ESC_CHAR); builder.append(SECOND_ESC_CHAR); builder.append('m'); } else { _appendEscapeSequence('m', attributeOptions.toArray()); } attributeOptions.clear(); }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
flushAttributes
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
private Ansi _appendEscapeSequence(char command, Object... options) { builder.append(FIRST_ESC_CHAR); builder.append(SECOND_ESC_CHAR); int size = options.length; for (int i = 0; i < size; i++) { if (i != 0) { builder.append(';'); } if (options[i] != null) { builder.append(options[i]); } } builder.append(command); return this; }
Provides a fluent API for generating ANSI escape sequences. @author <a href="http://hiramchirino.com">Hiram Chirino</a> @since 1.0
_appendEscapeSequence
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/Ansi.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Apache-2.0
Node mark(String mark) { this.mark = mark; marks++; return this; }
convert nano-seconds to milli-seconds
mark
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/TreeView.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/TreeView.java
Apache-2.0
long getCost() { return endTimestamp - beginTimestamp; }
convert nano-seconds to milli-seconds
getCost
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/TreeView.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/TreeView.java
Apache-2.0
double getCostInMillis(long nanoSeconds) { return nanoSeconds / 1000000.0; }
convert nano-seconds to milli-seconds
getCostInMillis
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/TreeView.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/TreeView.java
Apache-2.0
public String toString() { StringBuilder sb = new StringBuilder(); if (times <= 1) { sb.append("[").append(getCostInMillis(getCost())).append(TIME_UNIT).append("] "); } else { sb.append("[min=").append(getCostInMillis(minCost)).append(TIME_UNIT).append(",max=") .append(getCostInMillis(maxCost)).append(TIME_UNIT).append(",total=") .append(getCostInMillis(totalCost)).append(TIME_UNIT).append(",count=") .append(times).append("] "); } return sb.toString(); }
convert nano-seconds to milli-seconds
toString
java
alibaba/arthas
core/src/main/java/com/taobao/arthas/core/view/TreeView.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/view/TreeView.java
Apache-2.0
public static AsyncProfiler getInstance() { return getInstance(null); }
Java API for in-process profiling. Serves as a wrapper around async-profiler native library. This class is a singleton. The first call to {@link #getInstance()} initiates loading of libasyncProfiler.so.
getInstance
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
public static synchronized AsyncProfiler getInstance(String libPath) { if (instance != null) { return instance; } AsyncProfiler profiler = new AsyncProfiler(); if (libPath != null) { System.load(libPath); } else { try { // No need to load library, if it has been preloaded with -agentpath profiler.getVersion(); } catch (UnsatisfiedLinkError e) { File file = extractEmbeddedLib(); if (file != null) { try { System.load(file.getPath()); } finally { file.delete(); } } else { System.loadLibrary("asyncProfiler"); } } } instance = profiler; return profiler; }
Java API for in-process profiling. Serves as a wrapper around async-profiler native library. This class is a singleton. The first call to {@link #getInstance()} initiates loading of libasyncProfiler.so.
getInstance
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
private static File extractEmbeddedLib() { String resourceName = "/" + getPlatformTag() + "/libasyncProfiler.so"; InputStream in = AsyncProfiler.class.getResourceAsStream(resourceName); if (in == null) { return null; } try { String extractPath = System.getProperty("one.profiler.extractPath"); File file = File.createTempFile("libasyncProfiler-", ".so", extractPath == null || extractPath.isEmpty() ? null : new File(extractPath)); try (FileOutputStream out = new FileOutputStream(file)) { byte[] buf = new byte[32000]; for (int bytes; (bytes = in.read(buf)) >= 0; ) { out.write(buf, 0, bytes); } } return file; } catch (IOException e) { throw new IllegalStateException(e); } finally { try { in.close(); } catch (IOException e) { // ignore } } }
Java API for in-process profiling. Serves as a wrapper around async-profiler native library. This class is a singleton. The first call to {@link #getInstance()} initiates loading of libasyncProfiler.so.
extractEmbeddedLib
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
private static String getPlatformTag() { String os = System.getProperty("os.name").toLowerCase(); String arch = System.getProperty("os.arch").toLowerCase(); if (os.contains("linux")) { if (arch.equals("amd64") || arch.equals("x86_64") || arch.contains("x64")) { return "linux-x64"; } else if (arch.equals("aarch64") || arch.contains("arm64")) { return "linux-arm64"; } else if (arch.equals("aarch32") || arch.contains("arm")) { return "linux-arm32"; } else if (arch.contains("86")) { return "linux-x86"; } else if (arch.contains("ppc64")) { return "linux-ppc64le"; } } else if (os.contains("mac")) { return "macos"; } throw new UnsupportedOperationException("Unsupported platform: " + os + "-" + arch); }
Java API for in-process profiling. Serves as a wrapper around async-profiler native library. This class is a singleton. The first call to {@link #getInstance()} initiates loading of libasyncProfiler.so.
getPlatformTag
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@Override public void start(String event, long interval) throws IllegalStateException { if (event == null) { throw new NullPointerException(); } start0(event, interval, true); }
Start profiling @param event Profiling event, see {@link Events} @param interval Sampling interval, e.g. nanoseconds for Events.CPU @throws IllegalStateException If profiler is already running
start
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@Override public void resume(String event, long interval) throws IllegalStateException { if (event == null) { throw new NullPointerException(); } start0(event, interval, false); }
Start or resume profiling without resetting collected data. Note that event and interval may change since the previous profiling session. @param event Profiling event, see {@link Events} @param interval Sampling interval, e.g. nanoseconds for Events.CPU @throws IllegalStateException If profiler is already running
resume
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@Override public void stop() throws IllegalStateException { stop0(); }
Stop profiling (without dumping results) @throws IllegalStateException If profiler is not running
stop
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@Override public String getVersion() { try { return execute0("version"); } catch (IOException e) { throw new IllegalStateException(e); } }
Get profiler agent version, e.g. "1.0" @return Version string
getVersion
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@Override public String execute(String command) throws IllegalArgumentException, IllegalStateException, IOException { if (command == null) { throw new NullPointerException(); } return execute0(command); }
Execute an agent-compatible profiling command - the comma-separated list of arguments described in arguments.cpp @param command Profiling command @return The command result @throws IllegalArgumentException If failed to parse the command @throws IOException If failed to create output file
execute
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@Override public String dumpCollapsed(Counter counter) { try { return execute0("collapsed," + counter.name().toLowerCase()); } catch (IOException e) { throw new IllegalStateException(e); } }
Dump profile in 'collapsed stacktraces' format @param counter Which counter to display in the output @return Textual representation of the profile
dumpCollapsed
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
public void addThread(Thread thread) { filterThread(thread, true); }
Add the given thread to the set of profiled threads. 'filter' option must be enabled to use this method. @param thread Thread to include in profiling
addThread
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
public void removeThread(Thread thread) { filterThread(thread, false); }
Remove the given thread from the set of profiled threads. 'filter' option must be enabled to use this method. @param thread Thread to exclude from profiling
removeThread
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
private void filterThread(Thread thread, boolean enable) { if (thread == null || thread == Thread.currentThread()) { filterThread0(null, enable); } else { // Need to take lock to avoid race condition with a thread state change synchronized (thread) { Thread.State state = thread.getState(); if (state != Thread.State.NEW && state != Thread.State.TERMINATED) { filterThread0(thread, enable); } } } }
Remove the given thread from the set of profiled threads. 'filter' option must be enabled to use this method. @param thread Thread to exclude from profiling
filterThread
java
alibaba/arthas
core/src/main/java/one/profiler/AsyncProfiler.java
https://github.com/alibaba/arthas/blob/master/core/src/main/java/one/profiler/AsyncProfiler.java
Apache-2.0
@BeforeEach public void setUp() throws OgnlException, ExpressException { FlowContext context = new FlowContext(); Object[] params = new Object[4]; params[0] = context; Advice advice = Advice.newForAfterReturning(null, getClass(), null, null, params, null); express = ExpressFactory.unpooledExpress(null).bind(advice).bind("cost", 123); }
https://github.com/alibaba/arthas/issues/2954
setUp
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
Apache-2.0
@Test public void testStringEquals() throws OgnlException, ExpressException { String conditionExpress = "\"aaa\".equals(params[0].flowAttribute.getBxApp())"; boolean result = express.is(conditionExpress); assertTrue(result); }
https://github.com/alibaba/arthas/issues/2954
testStringEquals
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
Apache-2.0
@Test public void testObjectEquals() throws OgnlException, ExpressException { String conditionExpress = "params[0].flowAttribute.getBxApp().equals(\"aaa\")"; boolean result = express.is(conditionExpress); assertTrue(result); }
https://github.com/alibaba/arthas/issues/2954
testObjectEquals
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
Apache-2.0
@Test public void testEqualSign() throws OgnlException, ExpressException { String conditionExpress = "\"aaa\" == params[0].flowAttribute.getBxApp()"; boolean result = express.is(conditionExpress); assertTrue(result); }
https://github.com/alibaba/arthas/issues/2954
testEqualSign
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/command/express/OgnlTest.java
Apache-2.0
@Test public void testSupportedPipeCharWithoutRegex() { String[] expectedTextTokenValue = new String[]{"thread", "|", "grep", "xxx"}; List<CliToken> actualTokens = CliTokenImpl.tokenize("thread| grep xxx"); assertEquals(expectedTextTokenValue, actualTokens); actualTokens = CliTokenImpl.tokenize("thread | grep xxx"); assertEquals(expectedTextTokenValue, actualTokens); actualTokens = CliTokenImpl.tokenize("thread |grep xxx"); assertEquals(expectedTextTokenValue, actualTokens); }
supported: <p> case1: thread| grep xxx [thread|, grep, xxx] -> [thread, |, grep, xxx] case:2 thread | grep xxx [thread, |, grep, xxx] -> [thread, |, grep, xxx] case3: thread |grep xxx [thread, |grep] -> [thread, |, grep, xxx]
testSupportedPipeCharWithoutRegex
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/shell/cli/impl/CliTokenImplTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/shell/cli/impl/CliTokenImplTest.java
Apache-2.0
@Test public void testSupportedPipeCharWithRegex() { String[] expectedTextTokenValue = new String[]{"trace", "-E", "classA|classB", "methodA|methodB", "|", "grep", "classA"}; List<CliToken> actualTokens = CliTokenImpl.tokenize("trace -E classA|classB methodA|methodB| grep classA"); assertEquals(expectedTextTokenValue, actualTokens); actualTokens = CliTokenImpl.tokenize("trace -E classA|classB methodA|methodB | grep classA"); assertEquals(expectedTextTokenValue, actualTokens); actualTokens = CliTokenImpl.tokenize("trace -E classA|classB methodA|methodB |grep classA"); assertEquals(expectedTextTokenValue, actualTokens); }
supported: <p> case1: trace -E classA|classB methodA|methodB| grep classA [trace, -E, classA|classB, methodA|methodB|, grep, classA] -> [trace, -E, classA|classB, methodA|methodB, |, grep, classA] case2: trace -E classA|classB methodA|methodB | grep classA [trace, -E, classA|classB, methodA|methodB, |, grep, classA] -> [trace, -E, classA|classB, methodA|methodB, |, grep, classA] case3: trace -E classA|classB methodA|methodB |grep classA [trace, -E, classA|classB, methodA|methodB, |grep, classA] -> [trace, -E, classA|classB, methodA|methodB, |, grep, classA]
testSupportedPipeCharWithRegex
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/shell/cli/impl/CliTokenImplTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/shell/cli/impl/CliTokenImplTest.java
Apache-2.0
@Test public void testMatchingWithRegularGrammar(){ Assert.assertTrue(new RegexMatcher("foo?").matching("fo")); Assert.assertTrue(new RegexMatcher("foo?").matching("foo")); Assert.assertTrue(new RegexMatcher("foo.").matching("fooo")); Assert.assertTrue(new RegexMatcher("foo*").matching("fooooo")); Assert.assertTrue(new RegexMatcher("foo.*").matching("foobarbarbar")); Assert.assertFalse(new RegexMatcher("foo+").matching("fo")); Assert.assertTrue(new RegexMatcher("foo+").matching("fooooo")); Assert.assertTrue(new RegexMatcher("foo\\s").matching("foo ")); Assert.assertFalse(new RegexMatcher("foo\\S").matching("foo ")); Assert.assertTrue(new RegexMatcher("foo\\w").matching("fooo")); Assert.assertTrue(new RegexMatcher("foo\\W").matching("foo ")); Assert.assertFalse(new RegexMatcher("foo\\W").matching("fooo")); Assert.assertTrue(new RegexMatcher("foo[1234]").matching("foo1")); Assert.assertFalse(new RegexMatcher("foo[1234]").matching("foo5")); Assert.assertTrue(new RegexMatcher("foo\\\\").matching("foo\\")); Assert.assertTrue(new RegexMatcher("foo\\d").matching("foo5")); Assert.assertTrue(new RegexMatcher("fo{1,3}").matching("fo")); Assert.assertFalse(new RegexMatcher("fo{1,3}").matching("foooo")); }
test regux with . | * + ? \s \S \w \W and so on...
testMatchingWithRegularGrammar
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/util/matcher/RegexMatcherTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/util/matcher/RegexMatcherTest.java
Apache-2.0
@Test public void testMatchingComplexRegex(){ String ipAddressPattern = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"; Assert.assertTrue(new RegexMatcher(ipAddressPattern).matching("1.1.1.1")); Assert.assertFalse(new RegexMatcher(ipAddressPattern).matching("255.256.255.0")); Assert.assertFalse(new RegexMatcher(ipAddressPattern).matching("1.1.1")); Assert.assertTrue(new RegexMatcher("^foobar$").matching("foobar")); Assert.assertFalse(new RegexMatcher("^foobar$").matching("\nfoobar")); Assert.assertFalse(new RegexMatcher("^foobar$").matching("foobar\n")); String emailAddressPattern = "[a-z\\d]+(\\.[a-z\\d]+)*@([\\da-z](-[\\da-z])?)+(\\.{1,2}[a-z]+)+"; Assert.assertTrue(new RegexMatcher(emailAddressPattern).matching("foo@bar.com")); Assert.assertFalse(new RegexMatcher(emailAddressPattern).matching("asdfghjkl")); }
test regux with . | * + ? \s \S \w \W and so on...
testMatchingComplexRegex
java
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/util/matcher/RegexMatcherTest.java
https://github.com/alibaba/arthas/blob/master/core/src/test/java/com/taobao/arthas/core/util/matcher/RegexMatcherTest.java
Apache-2.0
@Override public void draw(ArthasStreamObserver arthasStreamObserver, EnhancerModel result) { if (result.getEffect() != null) { String msg = ViewRenderUtil.renderEnhancerAffect(result.getEffect()); ResponseBody responseBody = ResponseBody.newBuilder() .setJobId(result.getJobId()) .setType(result.getType()) .setStringValue(msg) .build(); arthasStreamObserver.onNext(responseBody); } }
Term grpc view for EnhancerModel @author xuyang 2023/8/15
draw
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/view/GrpcEnhancerView.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/view/GrpcEnhancerView.java
Apache-2.0
@Override public void draw(ArthasStreamObserver arthasStreamObserver, WatchResponseModel model) { ObjectVO objectVO = model.getValue(); // Object obj = objectVO.needExpand() ? new ObjectView(model.getSizeLimit(), objectVO).draw() : objectVO.getObject(); JavaObject javaObject = toJavaObjectWithExpand(objectVO.getObject(), objectVO.getExpand()); WatchResponse watchResponse = WatchResponse.newBuilder() .setAccessPoint(model.getAccessPoint()) .setClassName(model.getClassName()) .setCost(model.getCost()) .setMethodName(model.getMethodName()) .setSizeLimit(model.getSizeLimit()) .setTs(DateUtils.formatDateTime(model.getTs())) .setValue(javaObject) .build(); ResponseBody responseBody = ResponseBody.newBuilder() .setJobId(model.getJobId()) .setResultId(model.getResultId()) .setType(model.getType()) .setWatchResponse(watchResponse) .build(); arthasStreamObserver.onNext(responseBody); }
Term view for WatchModel @author xuyang 2023/8/15
draw
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/view/GrpcWatchView.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/view/GrpcWatchView.java
Apache-2.0
Channel getChannelWithClientInterceptor(GrpcWebClientInterceptor interceptor) { return ClientInterceptors.intercept(channel, interceptor); }
TODO: Manage the connection pool to talk to the grpc-service
getChannelWithClientInterceptor
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcServiceConnectionManager.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcServiceConnectionManager.java
Apache-2.0
public ManagedChannel getChannel() { return channel; }
TODO: Manage the connection pool to talk to the grpc-service
getChannel
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcServiceConnectionManager.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcServiceConnectionManager.java
Apache-2.0
private Method getRpcMethod(Object stub, String rpcMethodName) { for (Method m : stub.getClass().getMethods()) { if (m.getName().equals(rpcMethodName)) { return m; } } throw new IllegalArgumentException("Couldn't find rpcmethod: " + rpcMethodName); }
Find the matching method in the stub class.
getRpcMethod
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcWebRequestHandler.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcWebRequestHandler.java
Apache-2.0
@Override public void onError(Throwable t) { Status s = Status.fromThrowable(t); sendResponse.writeError(s); latch.countDown(); }
Find the matching method in the stub class.
onError
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcWebRequestHandler.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcWebRequestHandler.java
Apache-2.0
@Override public void onCompleted() { sendResponse.writeTrailer(Status.OK, null); latch.countDown(); }
Find the matching method in the stub class.
onCompleted
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcWebRequestHandler.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/GrpcWebRequestHandler.java
Apache-2.0
byte[] getMessageBytes() { return mMsg; }
Reads frames from the input bytes and returns a single message.
getMessageBytes
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
Apache-2.0
int getLength() { return mLength; }
Reads frames from the input bytes and returns a single message.
getLength
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
Apache-2.0
int getNumberOfFrames() { return mNumFrames; }
Reads frames from the input bytes and returns a single message.
getNumberOfFrames
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
Apache-2.0
public boolean processInput(InputStream in, MessageUtils.ContentType contentType) { byte[] inBytes; try { InputStream inStream = (contentType == ContentType.GRPC_WEB_TEXT) ? Base64.getDecoder().wrap(in) : in; inBytes = IOUtils.getBytes(inStream); } catch (IOException e) { e.printStackTrace(); logger.warn("invalid input"); return false; } if (inBytes.length < 5) { logger.debug("invalid input. Expected minimum of 5 bytes"); return false; } while (getNextFrameBytes(inBytes)) { } mNumFrames = mFrames.size(); // common case is only one frame. if (mNumFrames == 1) { mMsg = mFrames.get(0); } else { // concatenate all frames into one byte array // TODO: this is inefficient. mMsg = new byte[mLength]; int offset = 0; for (byte[] f : mFrames) { System.arraycopy(f, 0, mMsg, offset, f.length); offset += f.length; } mFrames = null; } return true; }
Reads the bytes from the given InputStream and populates bytes in {@link #mMsg}
processInput
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
Apache-2.0
private boolean getNextFrameBytes(byte[] inBytes) { // Firstbyte should be 0x00 (for this to be a DATA frame) int firstByteValue = inBytes[mReadSoFar] | DATA_BYTE; if (firstByteValue != 0) { logger.debug("done with DATA bytes"); return false; } // Next 4 bytes = length of the bytes array starting after the 4 bytes. int offset = mReadSoFar + 1; int len = ByteBuffer.wrap(inBytes, offset, 4).getInt(); // Empty message is special case. // TODO: Can this is special handling be removed? if (len == 0) { mFrames.add(new byte[0]); return false; } // Make sure we have enough bytes in the inputstream int expectedNumBytes = len + 5 + mReadSoFar; if (inBytes.length < expectedNumBytes) { logger.warn(String.format("input doesn't have enough bytes. expected: %d, found %d", expectedNumBytes, inBytes.length)); return false; } // Read "len" bytes into message mLength += len; offset += 4; byte[] inputBytes = Arrays.copyOfRange(inBytes, offset, len + offset); mFrames.add(inputBytes); mReadSoFar += (len + 5); // we have more frames to process, if there are bytes unprocessed return inBytes.length > mReadSoFar; }
returns true if the next frame is a DATA frame
getNextFrameBytes
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageDeframer.java
Apache-2.0
public byte[] getPrefix(byte[] in, Type type) { int len = in.length; return new byte[] { type.value, (byte) ((len >> 24) & 0xff), (byte) ((len >> 16) & 0xff), (byte) ((len >> 8) & 0xff), (byte) ((len >> 0) & 0xff), }; }
Creates frames from the input bytes.
getPrefix
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageFramer.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageFramer.java
Apache-2.0
static Object getInputProtobufObj(Method rpcMethod, byte[] in) { Class[] inputArgs = rpcMethod.getParameterTypes(); Class inputArgClass = inputArgs[0]; // use the inputArg classtype to create a protobuf object Method parseFromObj; try { parseFromObj = inputArgClass.getMethod("parseFrom", byte[].class); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Couldn't find method in 'parseFrom' in " + inputArgClass.getName()); } Object inputObj; try { inputObj = parseFromObj.invoke(null, in); } catch (InvocationTargetException | IllegalAccessException e) { throw new IllegalArgumentException(e); } if (inputObj == null || !inputArgClass.isInstance(inputObj)) { throw new IllegalArgumentException("Input obj is **not** instance of the correct input class type"); } return inputObj; }
Find the input arg protobuf class for the given rpc-method. Convert the given bytes to the input protobuf. return that.
getInputProtobufObj
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageUtils.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/MessageUtils.java
Apache-2.0
@Override public boolean isEndOfInput() throws Exception { if (input.isEndOfInput()) { // Only end of input after last HTTP chunk has been sent return true; } else { return false; } }
Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating chunk. @param input {@link ChunkedInput} containing data to write @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for training headers.
isEndOfInput
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
Apache-2.0
@Override public void close() throws Exception { input.close(); }
Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating chunk. @param input {@link ChunkedInput} containing data to write @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for training headers.
close
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
Apache-2.0
@Deprecated @Override public HttpContent readChunk(ChannelHandlerContext ctx) throws Exception { return readChunk(ctx.alloc()); }
Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating chunk. @param input {@link ChunkedInput} containing data to write @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for training headers.
readChunk
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
Apache-2.0
@Override public HttpContent readChunk(ByteBufAllocator allocator) throws Exception { if (input.isEndOfInput()) { return null; } else { ByteBuf buf = input.readChunk(allocator); if (buf == null) { return null; } return new DefaultHttpContent(buf); } }
Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating chunk. @param input {@link ChunkedInput} containing data to write @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for training headers.
readChunk
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
Apache-2.0
@Override public long length() { return input.length(); }
Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating chunk. @param input {@link ChunkedInput} containing data to write @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for training headers.
length
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
Apache-2.0
@Override public long progress() { return input.progress(); }
Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating chunk. @param input {@link ChunkedInput} containing data to write @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for training headers.
progress
java
alibaba/arthas
labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
https://github.com/alibaba/arthas/blob/master/labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/proxy/SingleHttpChunkedInput.java
Apache-2.0
@Override public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { if (location instanceof StandardLocation) { String locationName = ((StandardLocation) location).name(); for (String name : superLocationNames) { if (name.equals(locationName)) { return super.list(location, packageName, kinds, recurse); } } } // merge JavaFileObjects from specified ClassLoader if (location == StandardLocation.CLASS_PATH && kinds.contains(JavaFileObject.Kind.CLASS)) { return new IterableJoin<JavaFileObject>(super.list(location, packageName, kinds, recurse), finder.find(packageName)); } return super.list(location, packageName, kinds, recurse); }
if it's not CustomJavaFileObject, then it's coming from standard file manager - let it handle the file
list
java
alibaba/arthas
memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
https://github.com/alibaba/arthas/blob/master/memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
Apache-2.0
@Override public Iterator<T> iterator() { return new IteratorJoin<T>(first.iterator(), next.iterator()); }
if it's not CustomJavaFileObject, then it's coming from standard file manager - let it handle the file
iterator
java
alibaba/arthas
memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
https://github.com/alibaba/arthas/blob/master/memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
Apache-2.0
@Override public boolean hasNext() { return first.hasNext() || next.hasNext(); }
if it's not CustomJavaFileObject, then it's coming from standard file manager - let it handle the file
hasNext
java
alibaba/arthas
memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
https://github.com/alibaba/arthas/blob/master/memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
Apache-2.0
@Override public T next() { if (first.hasNext()) { return first.next(); } return next.next(); }
if it's not CustomJavaFileObject, then it's coming from standard file manager - let it handle the file
next
java
alibaba/arthas
memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
https://github.com/alibaba/arthas/blob/master/memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
Apache-2.0
@Override public void remove() { throw new UnsupportedOperationException("remove"); }
if it's not CustomJavaFileObject, then it's coming from standard file manager - let it handle the file
remove
java
alibaba/arthas
memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
https://github.com/alibaba/arthas/blob/master/memorycompiler/src/main/java/com/taobao/arthas/compiler/DynamicJavaFileManager.java
Apache-2.0
public static String toString(InputStream input) throws IOException { BufferedReader br = null; try { StringBuilder sb = new StringBuilder(); br = new BufferedReader(new InputStreamReader(input)); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } return sb.toString(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { // ignore } } } }
Get the contents of an <code>InputStream</code> as a String using the default character encoding of the platform. <p> This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. @param input the <code>InputStream</code> to read from @return the requested String @throws NullPointerException if the input is null @throws IOException if an I/O error occurs
toString
java
alibaba/arthas
memorycompiler/src/test/java/com/taobao/arthas/compiler/DynamicCompilerTest.java
https://github.com/alibaba/arthas/blob/master/memorycompiler/src/test/java/com/taobao/arthas/compiler/DynamicCompilerTest.java
Apache-2.0
public static void closeOnFlush(Channel ch) { if (ch.isActive()) { ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } }
Closes the specified channel after all queued write requests are flushed.
closeOnFlush
java
alibaba/arthas
tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ChannelUtils.java
https://github.com/alibaba/arthas/blob/master/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ChannelUtils.java
Apache-2.0
public static void closeOnFlush(Channel ch) { if (ch.isActive()) { ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } }
Closes the specified channel after all queued write requests are flushed.
closeOnFlush
java
alibaba/arthas
tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/ChannelUtils.java
https://github.com/alibaba/arthas/blob/master/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/ChannelUtils.java
Apache-2.0
@RequestMapping("/api/tunnelAgents") @ResponseBody public Map<String, Object> tunnelAgentIds(@RequestParam(value = "agentId", required = true) String agentId) { Map<String, Object> result = new HashMap<String, Object>(); boolean success = false; try { AgentClusterInfo info = tunnelClusterStore.findAgent(agentId); if (info != null) { success = true; } } catch (Throwable e) { logger.error("try to find agentId error, id: {}", agentId, e); } result.put("success", success); return result; }
check if agentId exists @param agentId @return
tunnelAgentIds
java
alibaba/arthas
tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java
https://github.com/alibaba/arthas/blob/master/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java
Apache-2.0