PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/web/src/main/java/com/navercorp/pinpoint/web/view/TransactionInfoViewModel.java

https://gitlab.com/hansol6566/pinpoint
Java | 362 lines | 289 code | 53 blank | 20 comment | 12 complexity | b5eec88e740c8120a60484606fab85e3 MD5 | raw file
  1. /*
  2. * Copyright 2015 NAVER Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.navercorp.pinpoint.web.view;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import org.json.simple.JSONObject;
  23. import com.fasterxml.jackson.annotation.JsonProperty;
  24. import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  25. import com.navercorp.pinpoint.common.util.DateUtils;
  26. import com.navercorp.pinpoint.web.applicationmap.Link;
  27. import com.navercorp.pinpoint.web.applicationmap.Node;
  28. import com.navercorp.pinpoint.web.vo.TransactionId;
  29. import com.navercorp.pinpoint.web.vo.callstacks.Record;
  30. import com.navercorp.pinpoint.web.vo.callstacks.RecordSet;
  31. /**
  32. * @author jaehong.kim
  33. * @author minwoo.jung
  34. */
  35. public class TransactionInfoViewModel {
  36. private TransactionId traceId;
  37. private Collection<Node> nodes;
  38. private Collection<Link> links;
  39. private RecordSet recordSet;
  40. private String completeState;
  41. private boolean logLinkEnable;
  42. private String logButtonName;
  43. private String logPageUrl;
  44. private String disableButtonMessage;
  45. public TransactionInfoViewModel(TransactionId traceId, Collection<Node> nodes, Collection<Link> links, RecordSet recordSet, String completeState, boolean logLinkEnable, String logButtonName, String logPageUrl, String disableButtonMessage) {
  46. this.traceId = traceId;
  47. this.nodes = nodes;
  48. this.links = links;
  49. this.recordSet = recordSet;
  50. this.completeState = completeState;
  51. this.logLinkEnable = logLinkEnable;
  52. this.logButtonName = logButtonName;
  53. this.logPageUrl = logPageUrl;
  54. this.disableButtonMessage = disableButtonMessage;
  55. }
  56. @JsonProperty("applicationName")
  57. public String getApplicationName() {
  58. return recordSet.getApplicationName();
  59. }
  60. @JsonProperty("transactionId")
  61. public String getTransactionId() {
  62. return traceId.getFormatString();
  63. }
  64. @JsonProperty("agentId")
  65. public String getAgentId() {
  66. return recordSet.getAgentId();
  67. }
  68. @JsonProperty("applicationId")
  69. public String getApplicationId() {
  70. return recordSet.getApplicationId();
  71. }
  72. @JsonProperty("callStackStart")
  73. public long getCallStackStart() {
  74. return recordSet.getStartTime();
  75. }
  76. @JsonProperty("callStackEnd")
  77. public long getCallStackEnd() {
  78. return recordSet.getEndTime();
  79. }
  80. @JsonProperty("completeState")
  81. public String getCompleteState() {
  82. return completeState;
  83. }
  84. @JsonProperty("logLinkEnable")
  85. public boolean isLogLinkEnable() {
  86. return logLinkEnable;
  87. }
  88. @JsonProperty("loggingTransactionInfo")
  89. public boolean isLoggingTransactionInfo() {
  90. return recordSet.isLoggingTransactionInfo();
  91. }
  92. @JsonProperty("logButtonName")
  93. public String getLogButtonName() {
  94. return logButtonName;
  95. }
  96. @JsonProperty("logPageUrl")
  97. public String getLogPageUrl() {
  98. if (logPageUrl != null && logPageUrl.length() > 0) {
  99. StringBuilder sb = new StringBuilder();
  100. sb.append("transactionId=").append(traceId.getFormatString());
  101. sb.append("&time=").append(recordSet.getStartTime());
  102. return logPageUrl + "?" + sb.toString();
  103. }
  104. return "";
  105. }
  106. @JsonProperty("disableButtonMessage")
  107. public String getDisableButtonMessage() {
  108. return disableButtonMessage;
  109. }
  110. @JsonProperty("callStackIndex")
  111. public Map<String, Integer> getCallStackIndex() {
  112. final Map<String, Integer> index = new HashMap<String, Integer>();
  113. for (int i = 0; i < CallStack.INDEX.length; i++) {
  114. index.put(CallStack.INDEX[i], i);
  115. }
  116. return index;
  117. }
  118. @JsonProperty("callStack")
  119. public List<CallStack> getCallStack() {
  120. List<CallStack> list = new ArrayList<CallStack>();
  121. boolean first = true;
  122. long barRatio = 0;
  123. for(Record record : recordSet.getRecordList()) {
  124. if(first) {
  125. if(record.isMethod()) {
  126. long begin = record.getBegin();
  127. long end = record.getBegin() + record.getElapsed();
  128. if(end - begin > 0) {
  129. barRatio = 100 / (end - begin);
  130. }
  131. }
  132. first = false;
  133. }
  134. list.add(new CallStack(record, barRatio));
  135. }
  136. return list;
  137. }
  138. @JsonProperty("applicationMapData")
  139. public Map<String, List<Object>> getApplicationMapData() {
  140. Map<String, List<Object>> result = new HashMap<String, List<Object>>();
  141. List<Object> nodeDataArray = new ArrayList<Object>();
  142. for(Node node : nodes) {
  143. nodeDataArray.add(node);
  144. }
  145. result.put("nodeDataArray", nodeDataArray);
  146. List<Object> linkDataArray = new ArrayList<Object>();
  147. for(Link link : links) {
  148. linkDataArray.add(link);
  149. }
  150. result.put("linkDataArray", linkDataArray);
  151. return result;
  152. }
  153. @JsonSerialize(using=TransactionInfoCallStackSerializer.class)
  154. public static class CallStack {
  155. static final String[] INDEX = {"depth",
  156. "begin",
  157. "end",
  158. "excludeFromTimeline",
  159. "applicationName",
  160. "tab",
  161. "id",
  162. "parentId",
  163. "isMethod",
  164. "hasChild",
  165. "title",
  166. "arguments",
  167. "executeTime",
  168. "gap",
  169. "elapsedTime",
  170. "barWidth",
  171. "executionMilliseconds",
  172. "simpleClassName",
  173. "methodType",
  174. "apiType",
  175. "agent",
  176. "isFocused",
  177. "hasException",
  178. "logButtonName",
  179. "logPageUrl",
  180. "isAuthorized"
  181. };
  182. private String depth = "";
  183. private long begin;
  184. private long end;
  185. private boolean excludeFromTimeline;
  186. private String applicationName = "";
  187. private int tab;
  188. private String id = "";
  189. private String parentId = "";
  190. private boolean isMethod;
  191. private boolean hasChild;
  192. private String title = "";
  193. private String arguments = "";
  194. private String executeTime = "";
  195. private String gap = "";
  196. private String elapsedTime = "";
  197. private String barWidth = "";
  198. private String executionMilliseconds = "";
  199. private String simpleClassName = "";
  200. private String methodType = "";
  201. private String apiType = "";
  202. private String agent = "";
  203. private boolean isFocused;
  204. private boolean hasException;
  205. private boolean isAuthorized;
  206. public CallStack(final Record record, long barRatio) {
  207. begin = record.getBegin();
  208. end = record.getBegin() + record.getElapsed();
  209. excludeFromTimeline = record.isExcludeFromTimeline();
  210. applicationName = record.getApplicationName();
  211. tab = record.getTab();
  212. id = String.valueOf(record.getId());
  213. if (record.getParentId() > 0) {
  214. parentId = String.valueOf(record.getParentId());
  215. }
  216. isMethod = record.isMethod();
  217. hasChild = record.getHasChild();
  218. title = JSONObject.escape(record.getTitle());
  219. //arguments = JSONObject.escape(StringEscapeUtils.escapeHtml4(record.getArguments()));
  220. arguments = record.getArguments();
  221. if (record.isMethod()) {
  222. executeTime = DateUtils.longToDateStr(record.getBegin(), "HH:mm:ss SSS"); // time format
  223. gap = String.valueOf(record.getGap());
  224. elapsedTime = String.valueOf(record.getElapsed());
  225. barWidth = String.format("%1d", (int)(((end - begin) * barRatio) + 0.9));
  226. executionMilliseconds = String.valueOf(record.getExecutionMilliseconds());
  227. }
  228. simpleClassName = record.getSimpleClassName();
  229. methodType = String.valueOf(record.getMethodType());
  230. apiType = record.getApiType();
  231. agent = record.getAgent();
  232. isFocused = record.isFocused();
  233. hasException = record.getHasException();
  234. isAuthorized = record.isAuthorized();
  235. }
  236. public String getDepth() {
  237. return depth;
  238. }
  239. public long getBegin() {
  240. return begin;
  241. }
  242. public long getEnd() {
  243. return end;
  244. }
  245. public boolean isExcludeFromTimeline() {
  246. return excludeFromTimeline;
  247. }
  248. public String getApplicationName() {
  249. return applicationName;
  250. }
  251. public int getTab() {
  252. return tab;
  253. }
  254. public String getId() {
  255. return id;
  256. }
  257. public String getParentId() {
  258. return parentId;
  259. }
  260. public boolean isMethod() {
  261. return isMethod;
  262. }
  263. public boolean isHasChild() {
  264. return hasChild;
  265. }
  266. public String getTitle() {
  267. return title;
  268. }
  269. public String getArguments() {
  270. return arguments;
  271. }
  272. public String getExecuteTime() {
  273. return executeTime;
  274. }
  275. public String getGap() {
  276. return gap;
  277. }
  278. public String getElapsedTime() {
  279. return elapsedTime;
  280. }
  281. public String getBarWidth() {
  282. return barWidth;
  283. }
  284. public String getExecutionMilliseconds() {
  285. return executionMilliseconds;
  286. }
  287. public String getSimpleClassName() {
  288. return simpleClassName;
  289. }
  290. public String getMethodType() {
  291. return methodType;
  292. }
  293. public String getApiType() {
  294. return apiType;
  295. }
  296. public String getAgent() {
  297. return agent;
  298. }
  299. public boolean isFocused() {
  300. return isFocused;
  301. }
  302. public boolean isHasException() {
  303. return hasException;
  304. }
  305. public boolean isAuthorized() {
  306. return isAuthorized;
  307. }
  308. }
  309. }