1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var SocketPoolWrapper
= (function() {
9 * SocketPoolWrapper is a wrapper around socket pools entries. It's
10 * used by the log and sockets view to print tables containing both
11 * a synopsis of the state of all pools, and listing the groups within
14 * The constructor takes a socket pool and its parent, and generates a
15 * unique name from the two, which is stored as |fullName|. |parent|
16 * must itself be a SocketPoolWrapper.
20 function SocketPoolWrapper(socketPool
, parent
) {
21 this.origPool
= socketPool
;
22 this.fullName
= socketPool
.name
;
23 if (this.fullName
!= socketPool
.type
)
24 this.fullName
+= ' (' + socketPool
.type
+ ')';
26 this.fullName
= parent
.fullName
+ '->' + this.fullName
;
30 * Returns an array of SocketPoolWrappers created from each of the socket
31 * pools in |socketPoolInfo|. Nested socket pools appear immediately after
32 * their parent, and groups of nodes from trees with root nodes with the same
33 * id are placed adjacent to each other.
35 SocketPoolWrapper
.createArrayFrom = function(socketPoolInfo
) {
36 // Create SocketPoolWrappers for each socket pool and separate socket pools
37 // them into different arrays based on root node name.
38 var socketPoolGroups
= [];
39 var socketPoolNameLists
= {};
40 for (var i
= 0; i
< socketPoolInfo
.length
; ++i
) {
41 var name
= socketPoolInfo
[i
].name
;
42 if (!socketPoolNameLists
[name
]) {
43 socketPoolNameLists
[name
] = [];
44 socketPoolGroups
.push(socketPoolNameLists
[name
]);
46 addSocketPoolsToList(socketPoolNameLists
[name
], socketPoolInfo
[i
], null);
50 var socketPoolList
= [];
51 for (var i
= 0; i
< socketPoolGroups
.length
; ++i
) {
52 socketPoolList
= socketPoolList
.concat(socketPoolGroups
[i
]);
54 return socketPoolList
;
58 * Recursively creates SocketPoolWrappers from |origPool| and all its
59 * children and adds them all to |socketPoolList|. |parent| is the
60 * SocketPoolWrapper for the parent of |origPool|, or null, if it's
61 * a top level socket pool.
63 function addSocketPoolsToList(socketPoolList
, origPool
, parent
) {
64 var socketPool
= new SocketPoolWrapper(origPool
, parent
);
65 socketPoolList
.push(socketPool
);
66 if (origPool
.nested_pools
) {
67 for (var i
= 0; i
< origPool
.nested_pools
.length
; ++i
) {
68 addSocketPoolsToList(socketPoolList
,
69 origPool
.nested_pools
[i
],
76 * Returns a table printer containing information on each
77 * SocketPoolWrapper in |socketPools|.
79 SocketPoolWrapper
.createTablePrinter = function(socketPools
) {
80 var tablePrinter
= new TablePrinter();
81 tablePrinter
.addHeaderCell('Name');
82 tablePrinter
.addHeaderCell('Handed Out');
83 tablePrinter
.addHeaderCell('Idle');
84 tablePrinter
.addHeaderCell('Connecting');
85 tablePrinter
.addHeaderCell('Max');
86 tablePrinter
.addHeaderCell('Max Per Group');
87 tablePrinter
.addHeaderCell('Generation');
89 for (var i
= 0; i
< socketPools
.length
; i
++) {
90 var origPool
= socketPools
[i
].origPool
;
92 tablePrinter
.addRow();
93 tablePrinter
.addCell(socketPools
[i
].fullName
);
95 tablePrinter
.addCell(origPool
.handed_out_socket_count
);
96 var idleCell
= tablePrinter
.addCell(origPool
.idle_socket_count
);
98 tablePrinter
.addCell(origPool
.connecting_socket_count
);
100 if (origPool
.groups
) {
101 var idleSources
= [];
102 var connectingSources
= [];
103 for (var groupName
in origPool
.groups
) {
104 var group
= origPool
.groups
[groupName
];
105 idleSources
= idleSources
.concat(group
.idle_sockets
);
106 connectingSources
= connectingSources
.concat(group
.connect_jobs
);
108 idleCell
.link
= sourceListLink(idleSources
);
109 connectingCell
.link
= sourceListLink(connectingSources
);
112 tablePrinter
.addCell(origPool
.max_socket_count
);
113 tablePrinter
.addCell(origPool
.max_sockets_per_group
);
114 tablePrinter
.addCell(origPool
.pool_generation_number
);
119 SocketPoolWrapper
.prototype = {
121 * Returns a table printer containing information on all a
122 * socket pool's groups.
124 createGroupTablePrinter: function() {
125 var tablePrinter
= new TablePrinter();
126 tablePrinter
.setTitle(this.fullName
);
128 tablePrinter
.addHeaderCell('Name');
129 tablePrinter
.addHeaderCell('Pending');
130 tablePrinter
.addHeaderCell('Top Priority');
131 tablePrinter
.addHeaderCell('Active');
132 tablePrinter
.addHeaderCell('Idle');
133 tablePrinter
.addHeaderCell('Connect Jobs');
134 tablePrinter
.addHeaderCell('Backup Timer');
135 tablePrinter
.addHeaderCell('Stalled');
137 for (var groupName
in this.origPool
.groups
) {
138 var group
= this.origPool
.groups
[groupName
];
140 tablePrinter
.addRow();
141 tablePrinter
.addCell(groupName
);
142 tablePrinter
.addCell(group
.pending_request_count
);
143 if (group
.top_pending_priority
!= undefined)
144 tablePrinter
.addCell(group
.top_pending_priority
);
146 tablePrinter
.addCell('-');
148 tablePrinter
.addCell(group
.active_socket_count
);
149 var idleCell
= tablePrinter
.addCell(group
.idle_sockets
.length
);
150 var connectingCell
= tablePrinter
.addCell(group
.connect_jobs
.length
);
152 idleCell
.link
= sourceListLink(group
.idle_sockets
);
153 connectingCell
.link
= sourceListLink(group
.connect_jobs
);
155 tablePrinter
.addCell(
156 group
.backup_job_timer_is_running
? 'started' : 'stopped');
157 tablePrinter
.addCell(group
.is_stalled
);
164 * Takes in a list of source IDs and returns a link that will select the
167 function sourceListLink(sources
) {
170 return '#events&q=id:' + sources
.join(',');
173 return SocketPoolWrapper
;