1 | /* |
---|
2 | Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | contributor license agreements. See the NOTICE file distributed with |
---|
4 | this work for additional information regarding copyright ownership. |
---|
5 | The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | (the "License"); you may not use this file except in compliance with |
---|
7 | the License. You may obtain a copy of the License at |
---|
8 | |
---|
9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | |
---|
11 | Unless required by applicable law or agreed to in writing, software |
---|
12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | See the License for the specific language governing permissions and |
---|
15 | limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | // #/~threads |
---|
19 | sammy.get |
---|
20 | ( |
---|
21 | /^#\/(~threads)$/, |
---|
22 | function( context ) |
---|
23 | { |
---|
24 | var core_basepath = $( 'li[data-basepath]', app.menu_element ).attr( 'data-basepath' ); |
---|
25 | var content_element = $( '#content' ); |
---|
26 | |
---|
27 | $.get |
---|
28 | ( |
---|
29 | 'tpl/threads.html', |
---|
30 | function( template ) |
---|
31 | { |
---|
32 | content_element |
---|
33 | .html( template ); |
---|
34 | |
---|
35 | $.ajax |
---|
36 | ( |
---|
37 | { |
---|
38 | url : core_basepath + '/admin/threads?wt=json', |
---|
39 | dataType : 'json', |
---|
40 | context : $( '#threads', content_element ), |
---|
41 | beforeSend : function( xhr, settings ) |
---|
42 | { |
---|
43 | }, |
---|
44 | success : function( response, text_status, xhr ) |
---|
45 | { |
---|
46 | var self = this; |
---|
47 | |
---|
48 | var threadDumpData = response.system.threadDump; |
---|
49 | var threadDumpContent = []; |
---|
50 | var c = 0; |
---|
51 | for( var i = 1; i < threadDumpData.length; i += 2 ) |
---|
52 | { |
---|
53 | var state = threadDumpData[i].state.esc(); |
---|
54 | var name = '<a title="' + state +'"><span>' + threadDumpData[i].name.esc() + ' (' + threadDumpData[i].id.esc() + ')</span></a>'; |
---|
55 | |
---|
56 | var classes = [state]; |
---|
57 | var details = ''; |
---|
58 | |
---|
59 | if( 0 !== c % 2 ) |
---|
60 | { |
---|
61 | classes.push( 'odd' ); |
---|
62 | } |
---|
63 | |
---|
64 | if( threadDumpData[i].lock ) |
---|
65 | { |
---|
66 | classes.push( 'lock' ); |
---|
67 | name += "\n" + '<p title="Waiting on">' + threadDumpData[i].lock.esc() + '</p>'; |
---|
68 | } |
---|
69 | |
---|
70 | if( threadDumpData[i].stackTrace && 0 !== threadDumpData[i].stackTrace.length ) |
---|
71 | { |
---|
72 | classes.push( 'stacktrace' ); |
---|
73 | |
---|
74 | var stack_trace = threadDumpData[i].stackTrace |
---|
75 | .join( '###' ) |
---|
76 | .esc() |
---|
77 | .replace( /\(/g, '​(' ) |
---|
78 | .replace( /###/g, '</li><li>' ); |
---|
79 | |
---|
80 | name += '<div>' + "\n" |
---|
81 | + '<ul>' + "\n" |
---|
82 | + '<li>' + stack_trace + '</li>' |
---|
83 | + '</ul>' + "\n" |
---|
84 | + '</div>'; |
---|
85 | } |
---|
86 | |
---|
87 | var item = '<tr class="' + classes.join( ' ' ) +'">' + "\n" |
---|
88 | + '<td class="name">' + name + '</td>' + "\n" |
---|
89 | + '<td class="time">' + threadDumpData[i].cpuTime.esc() + '<br>' + threadDumpData[i].userTime.esc() + '</td>' + "\n" |
---|
90 | + '</tr>'; |
---|
91 | |
---|
92 | threadDumpContent.push( item ); |
---|
93 | c++; |
---|
94 | } |
---|
95 | |
---|
96 | var threadDumpBody = $( '#thread-dump tbody', this ); |
---|
97 | |
---|
98 | threadDumpBody |
---|
99 | .html( threadDumpContent.join( "\n" ) ); |
---|
100 | |
---|
101 | $( '.name a', threadDumpBody ) |
---|
102 | .die( 'click' ) |
---|
103 | .live |
---|
104 | ( |
---|
105 | 'click', |
---|
106 | function( event ) |
---|
107 | { |
---|
108 | $( this ).closest( 'tr' ) |
---|
109 | .toggleClass( 'open' ); |
---|
110 | } |
---|
111 | ); |
---|
112 | |
---|
113 | $( '.controls a', this ) |
---|
114 | .die( 'click' ) |
---|
115 | .live |
---|
116 | ( |
---|
117 | 'click', |
---|
118 | function( event ) |
---|
119 | { |
---|
120 | var threads_element = $( self ); |
---|
121 | var is_collapsed = threads_element.hasClass( 'collapsed' ); |
---|
122 | var thread_rows = $( 'tr', threads_element ); |
---|
123 | |
---|
124 | thread_rows |
---|
125 | .each |
---|
126 | ( |
---|
127 | function( index, element ) |
---|
128 | { |
---|
129 | if( is_collapsed ) |
---|
130 | { |
---|
131 | $( element ) |
---|
132 | .addClass( 'open' ); |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | $( element ) |
---|
137 | .removeClass( 'open' ); |
---|
138 | } |
---|
139 | } |
---|
140 | ); |
---|
141 | |
---|
142 | threads_element |
---|
143 | .toggleClass( 'collapsed' ) |
---|
144 | .toggleClass( 'expanded' ); |
---|
145 | } |
---|
146 | ); |
---|
147 | }, |
---|
148 | error : function( xhr, text_status, error_thrown) |
---|
149 | { |
---|
150 | }, |
---|
151 | complete : function( xhr, text_status ) |
---|
152 | { |
---|
153 | } |
---|
154 | } |
---|
155 | ); |
---|
156 | } |
---|
157 | ); |
---|
158 | } |
---|
159 | ); |
---|