protected override void OnProfilingFinished(BaseProfilerResult <ProfilerCategory> result) { var frameMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.Frame, 0); var lockMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.Lock, 0); var updateMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.Update, 0); var updateNetworkMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.UpdateNetwork, 0); var updateReplMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.UpdateReplication, 0); var updateSessionCompsMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.UpdateSessionComponents, 0); var updateSessionCompsAllMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.UpdateSessionComponentsAll, 0); var updateSessionCompsOtherMs = updateSessionCompsAllMs - updateSessionCompsMs; var updateGpsMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.UpdateGps, 0); var updateParallelWaitMs = (float)result.GetMainThreadTickMsOrElse(ProfilerCategory.UpdateParallelWait, 0); var updateOtherMs = updateMs - updateNetworkMs - updateReplMs - updateSessionCompsAllMs - updateGpsMs - updateParallelWaitMs; TorchInfluxDbWriter .Measurement("profiler_game_loop") .Field("frame", frameMs / result.TotalFrameCount) .Field("wait", lockMs / result.TotalFrameCount) .Field("update", updateMs / result.TotalFrameCount) .Field("update_network", updateNetworkMs / result.TotalFrameCount) .Field("update_replication", updateReplMs / result.TotalFrameCount) .Field("update_session_components", updateSessionCompsMs / result.TotalFrameCount) .Field("update_session_components_all", updateSessionCompsAllMs / result.TotalFrameCount) .Field("update_session_components_other", updateSessionCompsOtherMs / result.TotalFrameCount) .Field("update_gps", updateGpsMs / result.TotalFrameCount) .Field("update_parallel_wait", updateParallelWaitMs / result.TotalFrameCount) .Field("update_other", updateOtherMs / result.TotalFrameCount) .Write(); }
public void OnInterval(int intervalsSinceStart) { if (intervalsSinceStart % 600 != 0) { return; } var voxels = MyEntities .GetEntities() .Select(e => e as MyVoxelBase) .Where(e => e != null) .Where(e => !e.Closed) .ToArray(); var planets = voxels.OfType <MyPlanet>().ToArray(); var asteroidCount = voxels.Length - planets.Length; TorchInfluxDbWriter .Measurement("voxels_asteroids_total") .Field("count", asteroidCount) .Write(); TorchInfluxDbWriter .Measurement("voxels_planets_total") .Field("count", planets.Length) .Write(); }
protected override void OnProfilingFinished(BaseProfilerResult <IMyFaction> result) { // get online players per faction var onlineFactions = new Dictionary <string, int>(); var onlinePlayers = MySession.Static.Players.GetOnlinePlayers(); foreach (var onlinePlayer in onlinePlayers) { var faction = MySession.Static.Factions.TryGetPlayerFaction(onlinePlayer.PlayerId()); if (faction == null) { continue; } onlineFactions.Increment(faction.Tag); } foreach (var(faction, entity) in result.GetTopEntities()) { onlineFactions.TryGetValue(faction.Tag, out var onlinePlayerCount); onlinePlayerCount = Math.Max(1, onlinePlayerCount); // fix zero division var mainMs = entity.MainThreadTime / result.TotalFrameCount; var mainMsPerMember = mainMs / onlinePlayerCount; TorchInfluxDbWriter .Measurement("profiler_factions") .Tag("faction_tag", faction.Tag) .Field("main_ms", mainMs) .Field("main_ms_per_member", mainMsPerMember) .Write(); } }
public void OnInterval(int intervalsSinceStart) { var simSpeed = Sync.ServerSimulationRatio; _simSpeeds[intervalsSinceStart % _simSpeeds.Length] = simSpeed; if (intervalsSinceStart < _config.FirstIgnoredSeconds) { return; } if (intervalsSinceStart % IntervalsPerWrite != 0) { return; } var maxSimSpeed = _simSpeeds.Max(); var minSimSpeed = _simSpeeds.Min(); var avgSimSpeed = _simSpeeds.Average(); TorchInfluxDbWriter .Measurement("server_sync") .Field("sim_speed", avgSimSpeed) .Field("sim_speed_min", minSimSpeed) .Field("sim_speed_max", maxSimSpeed) .Write(); }
public void OnInterval(int intervalsSinceStart) { if (!_config.Enabled) { return; } if (intervalsSinceStart % 20 != 0) { return; } var continents = new Dictionary <string, int>(); var countries = new Dictionary <string, int>(); var onlinePlayers = MySession.Static.Players.GetOnlinePlayers().ToArray(); foreach (var onlinePlayer in onlinePlayers) { if (onlinePlayer == null) { return; } var steamId = onlinePlayer.SteamId(); if (_ipLocations.TryGetValue(steamId, out var ipLocation)) { // null when localhost continents.Increment(ipLocation.ContinentName ?? "<unknown>"); countries.Increment(ipLocation.CountryName ?? "<unknown>"); } else { // update `_ipLocations` (for next interval) LoadIpLocation(steamId).Forget(Log); } } foreach (var(continentName, count) in continents) { Log.Trace($"writing continent data: '{continentName}'"); TorchInfluxDbWriter .Measurement("players_continents") .Tag("continent_name", continentName) .Field("online_player_count", count) .Write(); } foreach (var(countryName, count) in countries) { Log.Trace($"writing country data: '{countryName}'"); TorchInfluxDbWriter .Measurement("players_countries") .Tag("country_name", countryName) .Field("online_player_count", count) .Write(); } }
public void OnInterval(int intervalsSinceStart) { if (intervalsSinceStart < _config.FirstIgnoredSeconds) { return; } if (intervalsSinceStart % 10 != 0) { return; } const long GB = 1024 * 1024 * 1024; _process.Refresh(); // https://docs.microsoft.com/en-us/dotnet/api/system.gc.gettotalmemory // [...] the best available approximation of the number of bytes currently allocated in managed memory. var heap = (float)GC.GetTotalMemory(false) / GB; // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.privatememorysize64 // [...] the current size of memory used by the process, in bytes, that cannot be shared with other processes. var privat = (float)_process.PrivateMemorySize64 / GB; // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.workingset64 // [...] the current size of working set memory used by the process. // [...] the set of memory pages currently visible to the process in physical RAM memory. // [...] includes both shared and private data. var workingSet = (float)_process.WorkingSet64 / GB; // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.nonpagedsystemmemorysize64 // [...] the current size of nonpaged system memory used by the process. var nonPagedSys = (float)_process.NonpagedSystemMemorySize64 / GB; // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.pagedsystemmemorysize64 // [...] the current size of pageable system memory used by the process. var pagedSys = (float)_process.PagedSystemMemorySize64 / GB; // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.pagedmemorysize64 // [...] the current size of memory in the virtual memory paging file used by the process. var pagedVirtual = (float)_process.PagedMemorySize64 / GB; // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.virtualmemorysize64 // [...] the current size of virtual memory used by the process. var virt = (float)_process.VirtualMemorySize64 / GB; TorchInfluxDbWriter .Measurement("resource") .Field("heap", heap) .Field("private", privat) .Field("working_set", workingSet) .Field("non_paged_sys", nonPagedSys) .Field("paged_sys", pagedSys) .Field("paged_virtual", pagedVirtual) .Field("virtual", virt) .Write(); }
protected override void OnProfilingFinished(BaseProfilerResult <Type> result) { foreach (var(type, entry) in result.GetTopEntities(MaxDisplayCount)) { TorchInfluxDbWriter .Measurement("profiler_block_types") .Tag("block_type", type.Name) .Field("main_ms", (float)entry.MainThreadTime / result.TotalFrameCount) .Write(); } }
protected override void OnProfilingFinished(BaseProfilerResult <string> result) { foreach (var(name, entity) in result.GetTopEntities()) { TorchInfluxDbWriter .Measurement("profiler_method_names") .Tag("method_name", name) .Field("ms", (float)entity.MainThreadTime / result.TotalFrameCount) .Write(); } }
protected override void OnProfilingFinished(BaseProfilerResult <MyCubeGrid> result) { foreach (var(grid, entity) in result.GetTopEntities(MaxDisplayCount)) { TorchInfluxDbWriter .Measurement("profiler") .Tag("grid_name", GridToResultText(grid)) .Field("main_ms", (float)entity.MainThreadTime / result.TotalFrameCount) .Write(); } }
protected override void OnProfilingFinished(BaseProfilerResult <string> result) { foreach (var(methodName, entry) in result.GetTopEntities()) { var eventName = methodName.Split('#')[1]; TorchInfluxDbWriter .Measurement("profiler_network_events") .Tag("site_name", eventName) .Field("main_ms", (float)entry.MainThreadTime / result.TotalFrameCount) .Write(); } }
protected override void OnProfilingFinished(BaseProfilerResult <MyIdentity> result) { foreach (var(player, entity) in result.GetTopEntities(10)) { var playerName = player.DisplayName; var steamId = MySession.Static.Players.TryGetSteamId(player.IdentityId); playerName = _nameConflictSolver.GetSafeName(playerName, steamId); var mainMs = entity.MainThreadTime / result.TotalFrameCount; TorchInfluxDbWriter .Measurement("profiler_players") .Tag("player_name", playerName) .Field("main_ms", mainMs) .Write(); } }
protected override void OnProfilingFinished(BaseProfilerResult <MySessionComponentBase> result) { foreach (var(comp, entity) in result.GetTopEntities()) { var ms = (float)entity.MainThreadTime / result.TotalFrameCount; var type = comp.GetType(); var name = _myConfig.MonitorSessionComponentNamespace ? $"{type.Namespace}/{type.Name}" : type.Name; TorchInfluxDbWriter .Measurement("profiler_game_loop_session_components") .Tag("comp_name", name) .Field("main_ms", ms) .Write(); } }
public void OnInterval(int intervalsSinceStart) { if (intervalsSinceStart < _config.FirstIgnoredSeconds) { return; } if (intervalsSinceStart % 10 != 0) { return; } var count = MyEntities.GetEntities().Count(e => e is MyFloatingObject); TorchInfluxDbWriter .Measurement("floating_objects") .Field("count", count) .Write(); }
protected override void OnProfilingFinished(BaseProfilerResult <MyProgrammableBlock> result) { foreach (var(pb, entity) in result.GetTopEntities(MaxDisplayCount)) { var grid = pb?.GetParentEntityOfType <MyCubeGrid>(); if (grid == null) { return; } var gridName = _nameConflictSolver.GetSafeName(grid.DisplayName, grid.EntityId); var mainMs = (float)entity.MainThreadTime / result.TotalFrameCount; TorchInfluxDbWriter .Measurement("profiler_scripts") .Tag("grid_name", gridName) .Field("main_ms", mainMs) .Write(); } }
void ProcessResult(BaseProfilerResult <HkWorld> result) { foreach (var(world, entity) in result.GetTopEntities(_physicsConfig.PhysicsMaxClusterCount)) { // this usually doesn't happen but just in case if (!TryGetHeaviestGrid(world, out var heaviestGrid)) { continue; } heaviestGrid.BigOwners.TryGetFirst(out var ownerId); var faction = MySession.Static.Factions.GetPlayerFaction(ownerId); var factionTag = faction?.Tag ?? "<n/a>"; var gridName = heaviestGrid.DisplayName.OrNull() ?? "<no name>"; var mainMs = entity.MainThreadTime / result.TotalFrameCount; TorchInfluxDbWriter .Measurement("profiler_physics_grids") .Tag("grid", $"[{factionTag}] {gridName}") .Field("main_ms", mainMs) .Write(); } }
public void OnInterval(int intervalsSinceStart) { if (intervalsSinceStart % IntervalSecs != 0) { return; } var onlinePlayers = MySession.Static.Players.GetOnlinePlayers().ToArray(); var factionList = MySession.Static.Factions.Factions.Values; var factions = new Dictionary <string, int>(); foreach (var onlinePlayer in onlinePlayers) { if (onlinePlayer == null) { continue; } var playerId = onlinePlayer.PlayerId(); var steamId = onlinePlayer.SteamId(); if (steamId == 0) { continue; } _playerOnlineTimeDb.IncrementPlayerOnlineTime(steamId, (double)IntervalSecs / 3600); var onlineTime = _playerOnlineTimeDb.GetPlayerOnlineTime(steamId); var faction = factionList.FirstOrDefault(f => f.Members.ContainsKey(playerId)); var factionTag = faction?.Tag ?? "<single>"; factions.Increment(factionTag); var playerName = onlinePlayer.DisplayName; playerName = _nameConflictSolver.GetSafeName(playerName, steamId); TorchInfluxDbWriter .Measurement("players_players") .Tag("steam_id", $"{steamId}") .Tag("player_name", playerName) .Tag("faction_tag", factionTag) .Field("is_online", 1) .Field("online_time", onlineTime) .Write(); } foreach (var(factionTag, onlineMemberCount) in factions) { TorchInfluxDbWriter .Measurement("players_factions") .Tag("faction_tag", factionTag) .Field("online_member_count", onlineMemberCount) .Write(); } var totalOnlineTime = _playerOnlineTimeDb.GetTotalOnlineTime(); TorchInfluxDbWriter .Measurement("server") .Field("players", onlinePlayers.Length) .Field("online_time", totalOnlineTime) .Write(); _playerOnlineTimeDb.WriteToDb(); }
public void OnInterval(int intervalsSinceStart) { if (intervalsSinceStart < _config.FirstIgnoredSeconds) { return; } if (intervalsSinceStart % 60 != 0) { return; } var allGroups = MyCubeGridGroups.Static.Logical.Groups .Select(g => g.Nodes.Select(n => n.NodeData).ToArray()) .ToArray(); var allGrids = allGroups.SelectMany(g => g).ToArray(); //total { var totalBlockCount = allGrids.Sum(g => g.BlocksCount); TorchInfluxDbWriter .Measurement("blocks_all") .Field("block_count", totalBlockCount) .Write(); } // per grid { var gridBlockCounts = new Dictionary <long, int>(); foreach (var grid in allGrids) { gridBlockCounts.Increment(grid.EntityId); } var topGridBlockCounts = gridBlockCounts.OrderByDescending(p => p.Value).Take(MaxMonitoredCount); var gridNames = allGrids.ToDictionary(p => p.EntityId, p => p.DisplayName); foreach (var(gridId, blockCount) in topGridBlockCounts) { var gridName = gridNames[gridId]; TorchInfluxDbWriter .Measurement("blocks_grids") .Tag("name", gridName.Replace("\\", "-")) .Field("block_count", blockCount) .Write(); } } // per player/faction { var playerBlockCounts = new Dictionary <long, int>(); var factionBlockCounts = new Dictionary <string, int>(); foreach (var grid in allGrids) { foreach (var block in grid.CubeBlocks) { var ownerId = GetOwnerId(block); playerBlockCounts.Increment(ownerId); } } var topPlayerBlockCounts = playerBlockCounts.OrderByDescending(p => p.Value).Take(MaxMonitoredCount); var playerNames = MySession.Static.Players.GetAllIdentities().ToDictionary(id => id.IdentityId, id => id.DisplayName); playerNames[0] = "<nobody>"; foreach (var(id, blockCount) in topPlayerBlockCounts) { if (!playerNames.TryGetValue(id, out var playerName)) { continue; } TorchInfluxDbWriter .Measurement("blocks_players") .Tag("name", playerName.Replace("\\", "-")) .Field("block_count", blockCount) .Write(); } foreach (var(idId, blockCount) in playerBlockCounts) { var faction = MySession.Static.Factions.TryGetPlayerFaction(idId); if (faction == null) { continue; } factionBlockCounts.Increment(faction.Name, blockCount); } var topFactionBlockCounts = factionBlockCounts.OrderByDescending(p => p.Value).Take(MaxMonitoredCount); foreach (var(factionName, blockCount) in topFactionBlockCounts) { TorchInfluxDbWriter .Measurement("blocks_factions") .Tag("name", factionName.Replace("\\", "-")) .Field("block_count", blockCount) .Write(); } playerBlockCounts.Clear(); factionBlockCounts.Clear(); } }