aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SimStatsReporter.cs
diff options
context:
space:
mode:
authorTeravus Ovares2007-12-12 06:58:55 +0000
committerTeravus Ovares2007-12-12 06:58:55 +0000
commit081f4403ea2a2f8352d480910052bf5032e2e4a5 (patch)
tree9eeda0d127f84b1e0538ac834e7921a074b6503e /OpenSim/Region/Environment/Scenes/SimStatsReporter.cs
parent* Patch from justincc to fix Inconsistent automatic mysql table creation - se... (diff)
downloadopensim-SC-081f4403ea2a2f8352d480910052bf5032e2e4a5.zip
opensim-SC-081f4403ea2a2f8352d480910052bf5032e2e4a5.tar.gz
opensim-SC-081f4403ea2a2f8352d480910052bf5032e2e4a5.tar.bz2
opensim-SC-081f4403ea2a2f8352d480910052bf5032e2e4a5.tar.xz
* Added some simstats to fill the simulator pane of the Statistics monitor.
* I stress, this is an initial implementation and the Agents(Child and Root) are definately obviously incorrect.
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SimStatsReporter.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/SimStatsReporter.cs158
1 files changed, 158 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SimStatsReporter.cs b/OpenSim/Region/Environment/Scenes/SimStatsReporter.cs
new file mode 100644
index 0000000..55bd6a7
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SimStatsReporter.cs
@@ -0,0 +1,158 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Timers;
5using libsecondlife.Packets;
6using OpenSim.Framework;
7using Timer = System.Timers.Timer;
8
9namespace OpenSim.Region.Environment.Scenes
10{
11 public class SimStatsReporter
12 {
13 public delegate void SendStatResult(SimStatsPacket pack);
14
15 public event SendStatResult OnSendStatsResult;
16
17 private enum Stats : uint
18 {
19 TimeDilation = 0,
20 SimFPS = 1,
21 PhysicsFPS = 2,
22 AgentUpdates = 3,
23 Agents = 13,
24 ChildAgents = 14,
25 InPacketsPerSecond = 17,
26 OutPacketsPerSecond = 18,
27 UnAckedBytes = 24
28 }
29
30 private int statsUpdatesEveryMS = 1000;
31 private float m_timeDilation = 0;
32 private int m_fps = 0;
33 private float m_pfps = 0;
34 private float m_agentUpdates = 0;
35 private int m_rootAgents = 0;
36 private int m_childAgents = 0;
37 private int m_inPacketsPerSecond = 0;
38 private int m_outPacketsPerSecond = 0;
39 private int m_unAckedBytes = 0;
40 private RegionInfo ReportingRegion;
41
42 private Timer m_report = new Timer();
43
44
45 public SimStatsReporter(RegionInfo regionData)
46 {
47 ReportingRegion = regionData;
48 m_report.AutoReset = true;
49 m_report.Interval = statsUpdatesEveryMS;
50 m_report.Elapsed += new ElapsedEventHandler(statsHeartBeat);
51 m_report.Enabled = true;
52 }
53
54 private void statsHeartBeat(object sender, EventArgs e)
55 {
56 m_report.Enabled = false;
57 SimStatsPacket statpack = new SimStatsPacket();
58 SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[9];
59 statpack.Region = new SimStatsPacket.RegionBlock();
60 statpack.Region.RegionX = ReportingRegion.RegionLocX;
61 statpack.Region.RegionY = ReportingRegion.RegionLocY;
62 statpack.Region.RegionFlags = (uint)21;
63 statpack.Region.ObjectCapacity = (uint)15000;
64
65 sb[0] = new SimStatsPacket.StatBlock();
66 sb[0].StatID = (uint)Stats.TimeDilation;
67 sb[0].StatValue = (m_timeDilation);
68
69 sb[1] = new SimStatsPacket.StatBlock();
70 sb[1].StatID = (uint)Stats.SimFPS;
71 sb[1].StatValue = (int)(m_fps);
72
73 sb[2] = new SimStatsPacket.StatBlock();
74 sb[2].StatID = (uint)Stats.PhysicsFPS;
75 sb[2].StatValue = (m_pfps / statsUpdatesEveryMS);
76
77 sb[3] = new SimStatsPacket.StatBlock();
78 sb[3].StatID = (uint)Stats.AgentUpdates;
79 sb[3].StatValue = (m_agentUpdates / statsUpdatesEveryMS);
80
81 sb[4] = new SimStatsPacket.StatBlock();
82 sb[4].StatID = (uint)Stats.Agents;
83 sb[4].StatValue = m_rootAgents;
84
85 sb[5] = new SimStatsPacket.StatBlock();
86 sb[5].StatID = (uint)Stats.ChildAgents;
87 sb[5].StatValue = m_childAgents;
88
89 sb[6] = new SimStatsPacket.StatBlock();
90 sb[6].StatID = (uint)Stats.InPacketsPerSecond;
91 sb[6].StatValue = (int)(m_inPacketsPerSecond / statsUpdatesEveryMS);
92
93 sb[7] = new SimStatsPacket.StatBlock();
94 sb[7].StatID = (uint)Stats.OutPacketsPerSecond;
95 sb[7].StatValue = (int)(m_outPacketsPerSecond / statsUpdatesEveryMS);
96
97 sb[8] = new SimStatsPacket.StatBlock();
98 sb[8].StatID = (uint)Stats.UnAckedBytes;
99 sb[8].StatValue = (int) (m_unAckedBytes / statsUpdatesEveryMS);
100
101 statpack.Stat = sb;
102
103 if (OnSendStatsResult != null)
104 {
105 OnSendStatsResult(statpack);
106 }
107 resetvalues();
108 m_report.Enabled = true;
109 }
110
111 private void resetvalues()
112 {
113 m_fps = 0;
114 m_pfps = 0;
115 m_agentUpdates = 0;
116 m_inPacketsPerSecond = 0;
117 m_outPacketsPerSecond = 0;
118 m_unAckedBytes = 0;
119
120 }
121 public void SetTimeDilation(float td)
122 {
123 m_timeDilation = td;
124 }
125 public void SetRootAgents(int rootAgents)
126 {
127 m_rootAgents = rootAgents;
128 }
129 public void SetChildAgents(int childAgents)
130 {
131 m_childAgents = childAgents;
132 }
133 public void AddFPS(int frames)
134 {
135 m_fps += frames;
136 }
137 public void AddPhysicsFPS(float frames)
138 {
139 m_pfps += frames;
140 }
141 public void AddAgentUpdates(float numUpdates)
142 {
143 m_agentUpdates += numUpdates;
144 }
145 public void AddInPackets(int numPackets)
146 {
147 m_inPacketsPerSecond += numPackets;
148 }
149 public void AddOutPackets(int numPackets)
150 {
151 m_outPacketsPerSecond += numPackets;
152 }
153 public void AddunAckedBytes(int numBytes)
154 {
155 m_unAckedBytes += numBytes;
156 }
157 }
158}