Skip to content

Commit 7262fb9

Browse files
committed
fix(resmon): Time recording
1 parent bd3f4ca commit 7262fb9

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/core/commands.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,10 @@ void SwiftlyResourceMonitorManagerViewPlugin(CPlayerSlot slot, CCommandContext c
600600
usagesTable.add(string_format(" %llu ", it->second.size()));
601601

602602
if (it->second.size() == 0)
603-
usagesTable.add(" 0.000ms / 0.000ms ");
603+
usagesTable.add(" 0.00000ms / 0.00000ms ");
604604
else
605605
{
606-
auto it2 = it->second.end();
607-
--it2;
608-
float max = *(it2);
606+
float max = *std::max_element(it->second.begin(), it->second.end());
609607

610608
float avg = 0;
611609
uint64_t avgCount = 0;
@@ -615,7 +613,7 @@ void SwiftlyResourceMonitorManagerViewPlugin(CPlayerSlot slot, CCommandContext c
615613
++avgCount;
616614
}
617615

618-
usagesTable.add(string_format(" %.3fms / %.3fms ", (avg / avgCount), max));
616+
usagesTable.add(string_format(" %.5fms / %.5fms ", (avg / avgCount), max));
619617
}
620618
usagesTable.endOfRow();
621619
}
@@ -632,7 +630,6 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
632630
TextTable pluginsTable('-', '|', '+');
633631

634632
pluginsTable.add(" ID ");
635-
pluginsTable.add(" Name ");
636633
pluginsTable.add(" Status ");
637634
pluginsTable.add(" Type ");
638635
pluginsTable.add(" Memory ");
@@ -653,7 +650,6 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
653650
std::map<std::string, std::map<std::string, std::list<float>>> data = g_ResourceMonitor->GetResmonTimeTables();
654651

655652
pluginsTable.add(" core ");
656-
pluginsTable.add(" [Swiftly] Core ");
657653
pluginsTable.add(" Loaded ");
658654
pluginsTable.add(" - ");
659655
pluginsTable.add(" - ");
@@ -671,9 +667,7 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
671667
if (it->second.size() == 0)
672668
continue;
673669

674-
auto maxend = it->second.end();
675-
--maxend;
676-
max += *(maxend);
670+
max += *std::max_element(it->second.begin(), it->second.end());
677671
++maxCount;
678672

679673
for (std::list<float>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
@@ -683,7 +677,7 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
683677
}
684678
}
685679

686-
pluginsTable.add(string_format(" %.3fms / %.3fms ", (avg / avgCount), (max / maxCount)));
680+
pluginsTable.add(string_format(" %.5fms / %.5fms ", (avg / avgCount), (max / maxCount)));
687681
}
688682
else
689683
pluginsTable.add(" 0.000ms / 0.000ms ");
@@ -695,8 +689,6 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
695689
std::string plugin_id = plugin->GetName();
696690

697691
pluginsTable.add(" " + plugin_id + " ");
698-
std::string plugin_name = (plugin->GetPluginState() == PluginState_t::Started ? plugin->GetPlName() : "-");
699-
pluginsTable.add(string_format(" %s ", (plugin_name.size() > 24 ? (plugin_name.substr(0, 21) + "...") : plugin_name).c_str()));
700692
pluginsTable.add(std::string(" ") + (plugin->GetPluginState() == PluginState_t::Started ? "Loaded" : "Unloaded") + " ");
701693
pluginsTable.add(std::string(" ") + (plugin->GetKind() == PluginKind_t::Lua ? "Lua" : "None") + " ");
702694
if (plugin->GetKind() == PluginKind_t::Lua && plugin->GetPluginState() == PluginState_t::Started)
@@ -722,9 +714,7 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
722714
if (it->second.size() == 0)
723715
continue;
724716

725-
auto maxend = it->second.end();
726-
--maxend;
727-
max += *(maxend);
717+
max += *std::max_element(it->second.begin(), it->second.end());
728718
++maxCount;
729719

730720
for (std::list<float>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
@@ -734,10 +724,10 @@ void SwiftlyResourceMonitorManagerView(CPlayerSlot slot, CCommandContext context
734724
}
735725
}
736726

737-
pluginsTable.add(string_format(" %.3fms / %.3fms ", (avg / avgCount), (max / maxCount)));
727+
pluginsTable.add(string_format(" %.5fms / %.5fms ", (avg / avgCount), (max / maxCount)));
738728
}
739729
else
740-
pluginsTable.add(" 0.000ms / 0.000ms ");
730+
pluginsTable.add(" 0.00000ms / 0.00000ms ");
741731

742732
pluginsTable.endOfRow();
743733
}

src/resourcemonitor/ResourceMonitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ResourceMonitor
2727
std::map<std::string, std::map<std::string, std::list<float>>> GetResmonTimeTables() { return this->resmonTimesTable; }
2828
};
2929

30-
extern ResourceMonitor *g_ResourceMonitor;
30+
extern ResourceMonitor* g_ResourceMonitor;
3131

3232
class TempResMon
3333
{
@@ -46,7 +46,7 @@ class TempResMon
4646

4747
~TempResMon()
4848
{
49-
g_ResourceMonitor->RecordTime(m_plugin_id, m_key, std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startTime).count() / 1000);
49+
g_ResourceMonitor->RecordTime(m_plugin_id, m_key, float(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startTime).count()) / 1000.0);
5050
}
5151
};
5252

0 commit comments

Comments
 (0)