Call Dispose() via using() on SqliteCommands in WebStatsModule after use.

0.7.3-post-fixes
Justin Clark-Casey (justincc) 2012-02-28 22:54:21 +00:00
parent b18e410586
commit 1750fba9ce
1 changed files with 99 additions and 100 deletions

View File

@ -224,13 +224,11 @@ namespace OpenSim.Region.UserStatistics
concurrencyCounter--; concurrencyCounter--;
response_code = 200; response_code = 200;
} }
else else
{ {
strOut = MainServer.Instance.GetHTTP404(""); strOut = MainServer.Instance.GetHTTP404("");
} }
responsedata["int_response_code"] = response_code; responsedata["int_response_code"] = response_code;
responsedata["content_type"] = contenttype; responsedata["content_type"] = contenttype;
@ -247,43 +245,44 @@ namespace OpenSim.Region.UserStatistics
// TODO: FIXME: implement stats migrations // TODO: FIXME: implement stats migrations
const string SQL = @"SELECT * FROM migrations LIMIT 1"; const string SQL = @"SELECT * FROM migrations LIMIT 1";
SqliteCommand cmd = new SqliteCommand(SQL, db); using (SqliteCommand cmd = new SqliteCommand(SQL, db))
try
{ {
cmd.ExecuteNonQuery(); try
} {
catch (SqliteSyntaxException) cmd.ExecuteNonQuery();
{ }
CreateTables(db); catch (SqliteSyntaxException)
{
CreateTables(db);
}
} }
} }
} }
public void CreateTables(SqliteConnection db) public void CreateTables(SqliteConnection db)
{ {
SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db); using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db))
createcmd.ExecuteNonQuery(); {
createcmd.ExecuteNonQuery();
createcmd.CommandText = SQL_MIGRA_TABLE_CREATE; createcmd.CommandText = SQL_MIGRA_TABLE_CREATE;
createcmd.ExecuteNonQuery(); createcmd.ExecuteNonQuery();
}
} }
public virtual void PostInitialise() public virtual void PostInitialise()
{ {
if (!enabled) if (!enabled)
{
return; return;
}
AddHandlers(); AddHandlers();
} }
public virtual void Close() public virtual void Close()
{ {
if (!enabled) if (!enabled)
{
return; return;
}
dbConn.Close(); dbConn.Close();
dbConn.Dispose(); dbConn.Dispose();
m_sessions.Clear(); m_sessions.Clear();
@ -304,7 +303,8 @@ namespace OpenSim.Region.UserStatistics
public void OnRegisterCaps(UUID agentID, Caps caps) public void OnRegisterCaps(UUID agentID, Caps caps)
{ {
m_log.DebugFormat("[WEB STATS MODULE]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps); // m_log.DebugFormat("[WEB STATS MODULE]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
string capsPath = "/CAPS/VS/" + UUID.Random(); string capsPath = "/CAPS/VS/" + UUID.Random();
caps.RegisterHandler("ViewerStats", caps.RegisterHandler("ViewerStats",
new RestStreamHandler("POST", capsPath, new RestStreamHandler("POST", capsPath,
@ -318,7 +318,6 @@ namespace OpenSim.Region.UserStatistics
public void OnDeRegisterCaps(UUID agentID, Caps caps) public void OnDeRegisterCaps(UUID agentID, Caps caps)
{ {
} }
protected virtual void AddHandlers() protected virtual void AddHandlers()
@ -368,7 +367,6 @@ namespace OpenSim.Region.UserStatistics
public void OnMakeChildAgent(ScenePresence agent) public void OnMakeChildAgent(ScenePresence agent)
{ {
} }
public void OnClientClosed(UUID agentID, Scene scene) public void OnClientClosed(UUID agentID, Scene scene)
@ -430,6 +428,7 @@ namespace OpenSim.Region.UserStatistics
return scene.RegionInfo.RegionID; return scene.RegionInfo.RegionID;
} }
} }
return UUID.Zero; return UUID.Zero;
} }
@ -458,14 +457,14 @@ namespace OpenSim.Region.UserStatistics
UserSessionData usd; UserSessionData usd;
OSD message = OSDParser.DeserializeLLSDXml(request); OSD message = OSDParser.DeserializeLLSDXml(request);
OSDMap mmap; OSDMap mmap;
lock (m_sessions) lock (m_sessions)
{ {
if (agentID != UUID.Zero) if (agentID != UUID.Zero)
{ {
if (!m_sessions.ContainsKey(agentID)) if (!m_sessions.ContainsKey(agentID))
{ {
m_log.Warn("[WEB STATS MODULE]: no session for stat disclosure"); m_log.WarnFormat("[WEB STATS MODULE]: no session for stat disclosure for agent {0}", agentID);
return new UserSessionID(); return new UserSessionID();
} }
uid = m_sessions[agentID]; uid = m_sessions[agentID];
@ -585,8 +584,6 @@ namespace OpenSim.Region.UserStatistics
usd.n_out_kb = (float)net_out["kbytes"].AsReal(); usd.n_out_kb = (float)net_out["kbytes"].AsReal();
usd.n_out_pk = net_out["packets"].AsInteger(); usd.n_out_pk = net_out["packets"].AsInteger();
} }
} }
} }
@ -602,83 +599,85 @@ namespace OpenSim.Region.UserStatistics
lock (db) lock (db)
{ {
SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_UPDATE, db); using (SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_UPDATE, db))
updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":region_id", uid.session_data.region_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":last_updated", (int) uid.session_data.last_updated));
updatecmd.Parameters.Add(new SqliteParameter(":remote_ip", uid.session_data.remote_ip));
updatecmd.Parameters.Add(new SqliteParameter(":name_f", uid.session_data.name_f));
updatecmd.Parameters.Add(new SqliteParameter(":name_l", uid.session_data.name_l));
updatecmd.Parameters.Add(new SqliteParameter(":avg_agents_in_view", uid.session_data.avg_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":min_agents_in_view",
(int) uid.session_data.min_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":max_agents_in_view",
(int) uid.session_data.max_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":mode_agents_in_view",
(int) uid.session_data.mode_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":avg_fps", uid.session_data.avg_fps));
updatecmd.Parameters.Add(new SqliteParameter(":min_fps", uid.session_data.min_fps));
updatecmd.Parameters.Add(new SqliteParameter(":max_fps", uid.session_data.max_fps));
updatecmd.Parameters.Add(new SqliteParameter(":mode_fps", uid.session_data.mode_fps));
updatecmd.Parameters.Add(new SqliteParameter(":a_language", uid.session_data.a_language));
updatecmd.Parameters.Add(new SqliteParameter(":mem_use", uid.session_data.mem_use));
updatecmd.Parameters.Add(new SqliteParameter(":meters_traveled", uid.session_data.meters_traveled));
updatecmd.Parameters.Add(new SqliteParameter(":avg_ping", uid.session_data.avg_ping));
updatecmd.Parameters.Add(new SqliteParameter(":min_ping", uid.session_data.min_ping));
updatecmd.Parameters.Add(new SqliteParameter(":max_ping", uid.session_data.max_ping));
updatecmd.Parameters.Add(new SqliteParameter(":mode_ping", uid.session_data.mode_ping));
updatecmd.Parameters.Add(new SqliteParameter(":regions_visited", uid.session_data.regions_visited));
updatecmd.Parameters.Add(new SqliteParameter(":run_time", uid.session_data.run_time));
updatecmd.Parameters.Add(new SqliteParameter(":avg_sim_fps", uid.session_data.avg_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":min_sim_fps", uid.session_data.min_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":max_sim_fps", uid.session_data.max_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":mode_sim_fps", uid.session_data.mode_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":start_time", uid.session_data.start_time));
updatecmd.Parameters.Add(new SqliteParameter(":client_version", uid.session_data.client_version));
updatecmd.Parameters.Add(new SqliteParameter(":s_cpu", uid.session_data.s_cpu));
updatecmd.Parameters.Add(new SqliteParameter(":s_gpu", uid.session_data.s_gpu));
updatecmd.Parameters.Add(new SqliteParameter(":s_os", uid.session_data.s_os));
updatecmd.Parameters.Add(new SqliteParameter(":s_ram", uid.session_data.s_ram));
updatecmd.Parameters.Add(new SqliteParameter(":d_object_kb", uid.session_data.d_object_kb));
updatecmd.Parameters.Add(new SqliteParameter(":d_texture_kb", uid.session_data.d_texture_kb));
updatecmd.Parameters.Add(new SqliteParameter(":d_world_kb", uid.session_data.d_world_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_in_kb", uid.session_data.n_in_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_in_pk", uid.session_data.n_in_pk));
updatecmd.Parameters.Add(new SqliteParameter(":n_out_kb", uid.session_data.n_out_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_out_pk", uid.session_data.n_out_pk));
updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped));
updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends));
updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid));
updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit));
updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent));
updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet));
updatecmd.Parameters.Add(new SqliteParameter(":session_key", uid.session_data.session_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":agent_key", uid.session_data.agent_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":region_key", uid.session_data.region_id.ToString()));
// m_log.Debug("UPDATE");
int result = updatecmd.ExecuteNonQuery();
if (result == 0)
{ {
// m_log.Debug("INSERT"); updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString()));
updatecmd.CommandText = SQL_STATS_TABLE_INSERT; updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString()));
try updatecmd.Parameters.Add(new SqliteParameter(":region_id", uid.session_data.region_id.ToString()));
{ updatecmd.Parameters.Add(new SqliteParameter(":last_updated", (int) uid.session_data.last_updated));
updatecmd.ExecuteNonQuery(); updatecmd.Parameters.Add(new SqliteParameter(":remote_ip", uid.session_data.remote_ip));
} updatecmd.Parameters.Add(new SqliteParameter(":name_f", uid.session_data.name_f));
catch (SqliteExecutionException) updatecmd.Parameters.Add(new SqliteParameter(":name_l", uid.session_data.name_l));
{ updatecmd.Parameters.Add(new SqliteParameter(":avg_agents_in_view", uid.session_data.avg_agents_in_view));
m_log.Warn("[WEB STATS MODULE]: failed to write stats to storage Execution Exception"); updatecmd.Parameters.Add(new SqliteParameter(":min_agents_in_view",
} (int) uid.session_data.min_agents_in_view));
catch (SqliteSyntaxException) updatecmd.Parameters.Add(new SqliteParameter(":max_agents_in_view",
{ (int) uid.session_data.max_agents_in_view));
m_log.Warn("[WEB STATS MODULE]: failed to write stats to storage SQL Syntax Exception"); updatecmd.Parameters.Add(new SqliteParameter(":mode_agents_in_view",
} (int) uid.session_data.mode_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":avg_fps", uid.session_data.avg_fps));
updatecmd.Parameters.Add(new SqliteParameter(":min_fps", uid.session_data.min_fps));
updatecmd.Parameters.Add(new SqliteParameter(":max_fps", uid.session_data.max_fps));
updatecmd.Parameters.Add(new SqliteParameter(":mode_fps", uid.session_data.mode_fps));
updatecmd.Parameters.Add(new SqliteParameter(":a_language", uid.session_data.a_language));
updatecmd.Parameters.Add(new SqliteParameter(":mem_use", uid.session_data.mem_use));
updatecmd.Parameters.Add(new SqliteParameter(":meters_traveled", uid.session_data.meters_traveled));
updatecmd.Parameters.Add(new SqliteParameter(":avg_ping", uid.session_data.avg_ping));
updatecmd.Parameters.Add(new SqliteParameter(":min_ping", uid.session_data.min_ping));
updatecmd.Parameters.Add(new SqliteParameter(":max_ping", uid.session_data.max_ping));
updatecmd.Parameters.Add(new SqliteParameter(":mode_ping", uid.session_data.mode_ping));
updatecmd.Parameters.Add(new SqliteParameter(":regions_visited", uid.session_data.regions_visited));
updatecmd.Parameters.Add(new SqliteParameter(":run_time", uid.session_data.run_time));
updatecmd.Parameters.Add(new SqliteParameter(":avg_sim_fps", uid.session_data.avg_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":min_sim_fps", uid.session_data.min_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":max_sim_fps", uid.session_data.max_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":mode_sim_fps", uid.session_data.mode_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":start_time", uid.session_data.start_time));
updatecmd.Parameters.Add(new SqliteParameter(":client_version", uid.session_data.client_version));
updatecmd.Parameters.Add(new SqliteParameter(":s_cpu", uid.session_data.s_cpu));
updatecmd.Parameters.Add(new SqliteParameter(":s_gpu", uid.session_data.s_gpu));
updatecmd.Parameters.Add(new SqliteParameter(":s_os", uid.session_data.s_os));
updatecmd.Parameters.Add(new SqliteParameter(":s_ram", uid.session_data.s_ram));
updatecmd.Parameters.Add(new SqliteParameter(":d_object_kb", uid.session_data.d_object_kb));
updatecmd.Parameters.Add(new SqliteParameter(":d_texture_kb", uid.session_data.d_texture_kb));
updatecmd.Parameters.Add(new SqliteParameter(":d_world_kb", uid.session_data.d_world_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_in_kb", uid.session_data.n_in_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_in_pk", uid.session_data.n_in_pk));
updatecmd.Parameters.Add(new SqliteParameter(":n_out_kb", uid.session_data.n_out_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_out_pk", uid.session_data.n_out_pk));
updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped));
updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends));
updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid));
updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit));
updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent));
updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet));
updatecmd.Parameters.Add(new SqliteParameter(":session_key", uid.session_data.session_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":agent_key", uid.session_data.agent_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":region_key", uid.session_data.region_id.ToString()));
// m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id);
int result = updatecmd.ExecuteNonQuery();
if (result == 0)
{
// m_log.DebugFormat("[WEB STATS MODULE]: Database stats insert for {0}", uid.session_data.agent_id);
updatecmd.CommandText = SQL_STATS_TABLE_INSERT;
try
{
updatecmd.ExecuteNonQuery();
}
catch (Exception e)
{
m_log.WarnFormat(
"[WEB STATS MODULE]: failed to write stats for {0}, storage Execution Exception {1}{2}",
uid.session_data.agent_id, e.Message, e.StackTrace);
}
}
} }
} }
} }