aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Statistics/SimExtraStatsCollector.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-05-14 21:27:54 +0000
committerJustin Clarke Casey2008-05-14 21:27:54 +0000
commit56faeafdae5b4b76593e268bc994a7f663bd5685 (patch)
tree720efa22432151d2faaab08c61065a0ba02a047f /OpenSim/Framework/Statistics/SimExtraStatsCollector.cs
parent* Fixed attaching objects that are in-world. (diff)
downloadopensim-SC_OLD-56faeafdae5b4b76593e268bc994a7f663bd5685.zip
opensim-SC_OLD-56faeafdae5b4b76593e268bc994a7f663bd5685.tar.gz
opensim-SC_OLD-56faeafdae5b4b76593e268bc994a7f663bd5685.tar.bz2
opensim-SC_OLD-56faeafdae5b4b76593e268bc994a7f663bd5685.tar.xz
* Refactor: Renaming non viewer statistics classes from Reporters to Collectors - this seems more intuitive
Diffstat (limited to 'OpenSim/Framework/Statistics/SimExtraStatsCollector.cs')
-rw-r--r--OpenSim/Framework/Statistics/SimExtraStatsCollector.cs156
1 files changed, 156 insertions, 0 deletions
diff --git a/OpenSim/Framework/Statistics/SimExtraStatsCollector.cs b/OpenSim/Framework/Statistics/SimExtraStatsCollector.cs
new file mode 100644
index 0000000..4e69d17
--- /dev/null
+++ b/OpenSim/Framework/Statistics/SimExtraStatsCollector.cs
@@ -0,0 +1,156 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using OpenSim.Framework.Statistics.Interfaces;
33
34namespace OpenSim.Framework.Statistics
35{
36 /// <summary>
37 /// Collects sim statistics which aren't already being collected for the linden viewer's statistics pane
38 /// </summary>
39 public class SimExtraStatsCollector
40 {
41 private long assetsInCache;
42 private long texturesInCache;
43 private long assetCacheMemoryUsage;
44 private long textureCacheMemoryUsage;
45
46 public long AssetsInCache { get { return assetsInCache; } }
47 public long TexturesInCache { get { return texturesInCache; } }
48 public long AssetCacheMemoryUsage { get { return assetCacheMemoryUsage; } }
49 public long TextureCacheMemoryUsage { get { return textureCacheMemoryUsage; } }
50
51 /// <summary>
52 /// Retain a dictionary of all packet queues stats reporters
53 /// </summary>
54 private IDictionary<LLUUID, PacketQueueStatsCollector> packetQueueStatsCollectors
55 = new Dictionary<LLUUID, PacketQueueStatsCollector>();
56
57 public void AddAsset(AssetBase asset)
58 {
59 assetsInCache++;
60 assetCacheMemoryUsage += asset.Data.Length;
61 }
62
63 public void AddTexture(AssetBase image)
64 {
65 // Tedd: I added null check to avoid exception. Don't know if texturesInCache should ++ anyway?
66 if (image.Data != null)
67 {
68 texturesInCache++;
69 textureCacheMemoryUsage += image.Data.Length;
70 }
71 }
72
73 /// <summary>
74 /// Register as a packet queue stats provider
75 /// </summary>
76 /// <param name="uuid">An agent LLUUID</param>
77 /// <param name="provider"></param>
78 public void RegisterPacketQueueStatsProvider(LLUUID uuid, IPullStatsProvider provider)
79 {
80 lock (packetQueueStatsCollectors)
81 {
82 packetQueueStatsCollectors[uuid] = new PacketQueueStatsCollector(provider);
83 }
84 }
85
86 /// <summary>
87 /// Deregister a packet queue stats provider
88 /// </summary>
89 /// <param name="uuid">An agent LLUUID</param>
90 public void DeregisterPacketQueueStatsProvider(LLUUID uuid)
91 {
92 lock (packetQueueStatsCollectors)
93 {
94 packetQueueStatsCollectors.Remove(uuid);
95 }
96 }
97
98 /// <summary>
99 /// Report back collected statistical information.
100 /// </summary>
101 /// <returns></returns>
102 public string Report()
103 {
104 StringBuilder sb = new StringBuilder(Environment.NewLine);
105 sb.Append("ASSET CACHE STATISTICS");
106 sb.Append(Environment.NewLine);
107 sb.Append(
108 string.Format(
109@"Asset cache contains {0,6} assets using {1,10:0.000}K
110Texture cache contains {2,6} textures using {3,10:0.000}K" + Environment.NewLine,
111 AssetsInCache, AssetCacheMemoryUsage / 1024.0,
112 TexturesInCache, TextureCacheMemoryUsage / 1024.0));
113
114 sb.Append(Environment.NewLine);
115 sb.Append("PACKET QUEUE STATISTICS");
116 sb.Append(Environment.NewLine);
117 sb.Append("Agent UUID ");
118 sb.Append(
119 string.Format(
120 " {0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7}",
121 "Send", "In", "Out", "Resend", "Land", "Wind", "Cloud", "Task", "Texture", "Asset"));
122 sb.Append(Environment.NewLine);
123
124 foreach (LLUUID key in packetQueueStatsCollectors.Keys)
125 {
126 sb.Append(string.Format("{0}: ", key));
127 sb.Append(packetQueueStatsCollectors[key].Report());
128 sb.Append(Environment.NewLine);
129 }
130
131 return sb.ToString();
132 }
133 }
134
135 /// <summary>
136 /// Pull packet queue stats from packet queues and report
137 /// </summary>
138 public class PacketQueueStatsCollector
139 {
140 private IPullStatsProvider m_statsProvider;
141
142 public PacketQueueStatsCollector(IPullStatsProvider provider)
143 {
144 m_statsProvider = provider;
145 }
146
147 /// <summary>
148 /// Report back collected statistical information.
149 /// </summary>
150 /// <returns></returns>
151 public string Report()
152 {
153 return m_statsProvider.GetStats();
154 }
155 }
156}