Skip to content

Commit

Permalink
thread dummp step(on working)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunlee01 committed Aug 19, 2016
1 parent 0b69591 commit 492b843
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 102 deletions.
12 changes: 11 additions & 1 deletion scouter.agent.java/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,15 @@ public final static synchronized Configure getInstance() {
// SFA(Stack Frequency Analyzer)
@ConfigDesc("Activating period threaddump function")
public boolean sfa_dump_enabled = false;
@ConfigDesc("Threaddump Interval(ms)")
@ConfigDesc("SFA thread dump Interval(ms)")
public int sfa_dump_interval_ms = 10000;

//ASTS(Auto Stack Trace Step)
@ConfigDesc("Activating auto stack trace step")
public boolean asts_enabled = true;
@ConfigDesc("SFA thread dump Interval(ms)")
public int asts_dump_interval_ms = 10000;

//Summary
@ConfigDesc("Activating summary function")
public boolean summary_enabled = true;
Expand Down Expand Up @@ -650,6 +656,10 @@ private void apply() {
this.counter_object_registry_path = getValue("counter_object_registry_path", "/tmp/scouter");
this.sfa_dump_enabled = getBoolean("sfa_dump_enabled", false);
this.sfa_dump_interval_ms = getInt("sfa_dump_interval_ms", 10000);

this.asts_enabled = getBoolean("asts_enabled", true);
this.asts_dump_interval_ms = getInt("asts_dump_interval_ms", 10000);

// 웹시스템으로 부터 WAS 사이의 성능과 어떤 웹서버가 요청을 보내 왔는지를 추적하는 기능을 ON/OFF하고
// 관련 키정보를 지정한다.
this.trace_webserver_enabled = getBoolean("trace_webserver_enabled", false);
Expand Down
31 changes: 22 additions & 9 deletions scouter.agent.java/src/scouter/agent/counter/task/MakeStack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scouter.agent.counter.task;

import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.counter.CounterBasket;
import scouter.agent.counter.anotation.Counter;
import scouter.agent.netio.data.DataProxy;
Expand All @@ -18,6 +19,7 @@
import java.util.Enumeration;

public class MakeStack {
static Configure conf = Configure.getInstance();

public long lastStackTime;
@Counter
Expand All @@ -27,7 +29,7 @@ public void make(CounterBasket pw) {
return;
}
long now = System.currentTimeMillis();
if (now < lastStackTime + getInterval())
if (now < lastStackTime + getSFAInterval())
return;
lastStackTime = now;
StringWriter sw = new StringWriter();
Expand All @@ -43,30 +45,36 @@ public void make(CounterBasket pw) {

StackPack p = new StackPack();
p.time = System.currentTimeMillis();
p.objHash = Configure.getInstance().getObjHash();
p.objHash = conf.getObjHash();
p.setStack(stack);

DataProxy.sendDirect(p);

long elapsed = (System.currentTimeMillis() - now);
Logger.trace("[SFA Counter Elasped]" + elapsed);
}

public static long pstack_requested;
private boolean isPStackEnabled() {
return Configure.getInstance().sfa_dump_enabled || System.currentTimeMillis() < pstack_requested;
return conf.sfa_dump_enabled || System.currentTimeMillis() < pstack_requested;
}
private long getInterval() {
return Configure.getInstance().sfa_dump_interval_ms;
private long getSFAInterval() {
return conf.sfa_dump_interval_ms;
}


long lastRegularDumpTime = 0;
long lastStackTraceGenTime = 0;
@Counter
public void regularDump(CounterBasket pw) {
public void stackTraceStepGenerator(CounterBasket pw) {
if (!conf.asts_enabled){
return;
}

long now = System.currentTimeMillis();
if (now < lastRegularDumpTime + 10000) {
if (now < lastStackTraceGenTime + conf.asts_dump_interval_ms) {
return;
}
lastRegularDumpTime = now;
lastStackTraceGenTime = now;

ThreadMXBean tmxBean = ManagementFactory.getThreadMXBean();
Enumeration<TraceContext> en = TraceContextManager.getContextEnumeration();
Expand All @@ -87,6 +95,7 @@ public void regularDump(CounterBasket pw) {
stacks[i] = DataProxy.sendStackElement(elements[i].toString());
}
DumpStep dumpStep = new DumpStep();
dumpStep.start_time = (int) (System.currentTimeMillis() - ctx.startTime);
dumpStep.stacks = stacks;
dumpStep.threadId = ctx.threadId;
dumpStep.threadName = tInfo.getThreadName();
Expand All @@ -96,6 +105,10 @@ public void regularDump(CounterBasket pw) {
dumpStep.lockOwnerName = tInfo.getLockOwnerName();

ctx.temporaryDumpStep = dumpStep;
ctx.hasDumpStack = true;
}

long elapsed = (System.currentTimeMillis() - now);
Logger.trace("[ASTS Elasped]" + elapsed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public TraceContext(boolean profile_summary) {

public SqlStep lastSqlStep;
public DumpStep temporaryDumpStep;
public boolean hasDumpStack;

public TraceContext createChild() {
TraceContext child = new TraceContext(this.isSummary);
Expand Down
5 changes: 5 additions & 0 deletions scouter.agent.java/src/scouter/agent/trace/TraceMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ public static void endHttpService(Object stat, Throwable thr) {
pack.sqlTime = ctx.sqlTime;
pack.ipaddr = IPUtil.toBytes(ctx.remoteIp);
pack.userid = ctx.userid;
if(ctx.hasDumpStack) {
pack.hasDump = 1;
} else {
pack.hasDump = 0;
}
// ////////////////////////////////////////////////////////
if (ctx.error != 0) {
pack.error = ctx.error;
Expand Down
6 changes: 4 additions & 2 deletions scouter.client/src/scouter/client/model/TextProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
package scouter.client.model;

import scouter.lang.TextTypes;

import java.util.HashMap;
import java.util.Map;

import scouter.lang.TextTypes;

public class TextProxy {

public TextProxy() {
Expand All @@ -44,6 +44,7 @@ public TextProxy() {
final public static TextModel login = new TextModel(TextTypes.LOGIN, 1024);
final public static TextModel desc = new TextModel(TextTypes.DESC, 1024);
final public static TextModel hashMessage = new TextModel(TextTypes.HASH_MSG, 1024);
final public static TextModel stackElement = new TextModel(TextTypes.STACK_ELEMENT, 8192);

private static Map<String, TextModel> textModelMap = new HashMap<String, TextModel>();

Expand All @@ -64,6 +65,7 @@ public TextProxy() {
textModelMap.put(TextTypes.LOGIN, login);
textModelMap.put(TextTypes.DESC, desc);
textModelMap.put(TextTypes.HASH_MSG, hashMessage);
textModelMap.put(TextTypes.STACK_ELEMENT, stackElement);
}

public static TextModel getTextModel(String textType) {
Expand Down
66 changes: 33 additions & 33 deletions scouter.client/src/scouter/client/xlog/ProfileText.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@
*/
package scouter.client.xlog;

import java.io.BufferedReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;

import scouter.client.model.TextProxy;
import scouter.client.model.XLogData;
import scouter.client.server.GroupPolicyConstants;
Expand All @@ -36,32 +29,14 @@
import scouter.client.util.SqlMakerUtil;
import scouter.client.xlog.views.XLogProfileView;
import scouter.lang.CountryCode;
import scouter.lang.step.ApiCallStep;
import scouter.lang.step.ApiCallSum;
import scouter.lang.step.HashedMessageStep;
import scouter.lang.step.MessageStep;
import scouter.lang.step.MethodStep;
import scouter.lang.step.MethodStep2;
import scouter.lang.step.MethodSum;
import scouter.lang.step.SocketStep;
import scouter.lang.step.SocketSum;
import scouter.lang.step.SqlStep;
import scouter.lang.step.SqlStep2;
import scouter.lang.step.SqlStep3;
import scouter.lang.step.SqlSum;
import scouter.lang.step.SqlXType;
import scouter.lang.step.Step;
import scouter.lang.step.StepControl;
import scouter.lang.step.StepEnum;
import scouter.lang.step.StepSingle;
import scouter.lang.step.StepSummary;
import scouter.lang.step.ThreadSubmitStep;
import scouter.util.DateUtil;
import scouter.util.FormatUtil;
import scouter.util.Hexa32;
import scouter.util.IPUtil;
import scouter.util.SortUtil;
import scouter.util.StringUtil;
import scouter.lang.step.*;
import scouter.util.*;

import java.io.BufferedReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

public class ProfileText {

Expand Down Expand Up @@ -170,6 +145,10 @@ public static void build(final String date, StyledText text, XLogData xperf, Ste
sb.append("\n► desc=" + t);
}
sb.append("\n");
if (xperf.p.hasDump == 1) {
sb.append("\n► dump=Y");
}
sb.append("\n");

sb.append("------------------------------------------------------------------------------------------\n");
sb.append(" p# # TIME T-GAP CPU CONTENTS\n");
Expand Down Expand Up @@ -348,6 +327,11 @@ public static void build(final String date, StyledText text, XLogData xperf, Ste
toString(sb, (HashedMessageStep) stepSingle);
sr.add(style(slen, sb.length() - slen, dgreen, SWT.NORMAL));
break;
case StepEnum.DUMP:
slen = sb.length();
toString(sb, (DumpStep) stepSingle);
sr.add(style(slen, sb.length() - slen, dgreen, SWT.NORMAL));
break;
case StepEnum.APICALL:
ApiCallStep apicall = (ApiCallStep) stepSingle;
slen = sb.length();
Expand Down Expand Up @@ -579,6 +563,11 @@ public static void buildThreadProfile(XLogData data, StyledText text, Step[] pro
toString(sb, (HashedMessageStep) stepSingle);
sr.add(style(slen, sb.length() - slen, dgreen, SWT.NORMAL));
break;
case StepEnum.DUMP:
slen = sb.length();
toString(sb, (DumpStep) stepSingle);
sr.add(style(slen, sb.length() - slen, dgreen, SWT.NORMAL));
break;
case StepEnum.APICALL:
ApiCallStep apicall = (ApiCallStep) stepSingle;
slen = sb.length();
Expand Down Expand Up @@ -641,6 +630,17 @@ public static void toString(StringBuffer sb, HashedMessageStep p) {
sb.append(m).append(" #").append(FormatUtil.print(p.value, "#,##0")).append(" ").append(FormatUtil.print(p.time, "#,##0")).append(" ms");
}

public static void toString(StringBuffer sb, DumpStep p) {
sb.append(p.threadId).append(" - ").append(p.threadName).append('\n');
for(int stackElementHash : p.stacks) {
String m = TextProxy.stackElement.getText(stackElementHash);
if(m == null) {
m = Hexa32.toString32(stackElementHash);
}
sb.append(m).append('\n');
}
}

public static void toString(StringBuffer sb, ThreadSubmitStep p) {
String m = TextProxy.apicall.getText(p.hash);
if (m == null)
Expand Down
Loading

0 comments on commit 492b843

Please sign in to comment.