Skip to content

Commit

Permalink
Make NetworkProfiler callstack optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Nov 24, 2019
1 parent 4499154 commit bd24ea1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 47 deletions.
99 changes: 54 additions & 45 deletions src/NetworkProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ClassEntrySizeCounter : public param_archive_entry {
uint64_t* sizeCounter;
ClassEntrySizeCounter* parent = nullptr;
std::vector<ClassEntrySizeCounter*> activeSubs;
std::string* data;
std::string* data = nullptr;

ClassEntrySizeCounter(r_string name_, uint64_t* size) : sizeCounter(size) {
*sizeCounter += name_.length();
Expand All @@ -34,6 +34,10 @@ class ClassEntrySizeCounter : public param_archive_entry {
ClassEntrySizeCounter(r_string name_, ClassEntrySizeCounter* parent_) : sizeCounter(parent_->sizeCounter), parent(parent_), data(parent_->data) {
*sizeCounter += name_.length();
parent->activeSubs.push_back(this);
if (data) {
*data += name_;
data->push_back('/');
}
};

//! virtual destructor
Expand Down Expand Up @@ -178,10 +182,9 @@ class ClassEntrySizeCounter : public param_archive_entry {
void NetworkProfiler::init() {
auto iface = client::host::request_plugin_interface("BIDebugEngine_getCallstack", 1);
if (!iface) {
diag_log("ASP: Network statistics failed to enable because ArmaDebugEngine is missing"sv);
return;
}
getCallstackRaw = reinterpret_cast<decltype(getCallstackRaw)>(*iface);
diag_log("ASP: Network statistics ArmaDebugEngine not present, you won't get callstacks"sv);
} else
getCallstackRaw = reinterpret_cast<decltype(getCallstackRaw)>(*iface);

static auto _pubVar = client::host::register_sqf_command("publicVariable", "Profiler redirect", [](game_state& gs, game_value_parameter arg) -> game_value {
static tracy::SourceLocationData info {
Expand All @@ -191,7 +194,8 @@ void NetworkProfiler::init() {
0
};
static int64_t publicVarSize;
auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

r_string varName = arg;
auto varValue = sqf::get_variable(sqf::current_namespace(), varName);
Expand All @@ -200,8 +204,8 @@ void NetworkProfiler::init() {
publicVarSize += getVariableSize(varValue, logPacketContent ? &data : nullptr);
publicVarSize += varName.size();

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -222,7 +226,8 @@ void NetworkProfiler::init() {
0
};
static int64_t publicVarSize;
auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

r_string varName = arg;
auto varValue = sqf::get_variable(sqf::current_namespace(), varName);
Expand All @@ -232,8 +237,8 @@ void NetworkProfiler::init() {
publicVarSize += varName.size();
publicVarSize += 4; //clientID

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -254,7 +259,8 @@ void NetworkProfiler::init() {
0
};
static int64_t publicVarSize;
auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

r_string varName = arg;
auto varValue = sqf::get_variable(sqf::current_namespace(), varName);
Expand All @@ -263,8 +269,8 @@ void NetworkProfiler::init() {
publicVarSize += getVariableSize(varValue, logPacketContent ? &data : nullptr);
publicVarSize += varName.size();

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -284,15 +290,16 @@ void NetworkProfiler::init() {
"",
0
};
auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
remoteExecSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -310,16 +317,17 @@ void NetworkProfiler::init() {
"",
0
};
auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
remoteExecSize += getVariableSize(par, logPacketContent ? &data : nullptr);
remoteExecSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -336,15 +344,16 @@ void NetworkProfiler::init() {
"",
0
};
auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
remoteExecSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -363,16 +372,17 @@ void NetworkProfiler::init() {
0
};

auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
remoteExecSize += getVariableSize(par, logPacketContent ? &data : nullptr);
remoteExecSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -393,16 +403,17 @@ void NetworkProfiler::init() {
if (arg.size() != 3 || arg[2].type_enum() != game_data_type::BOOL || !static_cast<bool>(arg[2]))
return host::functions.invoke_raw_binary(__sqf::binary__setvariable__object__array__ret__nothing, par, arg);

auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
setVariableSize += getVariableSize(par, logPacketContent ? &data : nullptr);
setVariableSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -423,16 +434,17 @@ void NetworkProfiler::init() {
if (arg.size() != 3 || arg[2].type_enum() != game_data_type::BOOL || !static_cast<bool>(arg[2]))
return host::functions.invoke_raw_binary(__sqf::binary__setvariable__namespace__array__ret__nothing, par, arg);

auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
setVariableSize += getVariableSize(par, logPacketContent ? &data : nullptr);
setVariableSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -453,16 +465,17 @@ void NetworkProfiler::init() {
if (arg.size() != 3 || arg[2].type_enum() != game_data_type::BOOL || !static_cast<bool>(arg[2]))
return host::functions.invoke_raw_binary(__sqf::binary__setvariable__location__array__ret__nothing, par, arg);

auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
setVariableSize += getVariableSize(par, logPacketContent ? &data : nullptr);
setVariableSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -483,16 +496,17 @@ void NetworkProfiler::init() {
if (arg.size() != 3 || arg[2].type_enum() != game_data_type::BOOL || !static_cast<bool>(arg[2]))
return host::functions.invoke_raw_binary(__sqf::binary__setvariable__group__array__ret__nothing, par, arg);

auto callstack = NetworkProfiler::getCallstackRaw(&gs);
auto_array<std::pair<r_string, uint32_t>> callstack;
if (getCallstackRaw) callstack = getCallstackRaw(&gs);

std::string data;
setVariableSize += getVariableSize(par, logPacketContent ? &data : nullptr);
setVariableSize += getVariableSize(arg, logPacketContent ? &data : nullptr);

r_string name = arg[0];

tracy::ScopedZone zone(&info, tracy::t_withCallstack{});
AdapterTracy::sendCallstack(callstack);
tracy::ScopedZone zone(&info, tracy::t_withCallstack{ getCallstackRaw != nullptr });
if (getCallstackRaw) AdapterTracy::sendCallstack(callstack);
if (logPacketContent)
zone.Text(data.c_str(), data.size());
else
Expand All @@ -506,15 +520,10 @@ void NetworkProfiler::init() {
uint32_t NetworkProfiler::getVariableSize(const game_value& var, std::string* data) {
auto ncnst = const_cast<game_value&>(var);
uint64_t size = 0;
if (data) {
param_archive ar(rv_allocator<ClassEntrySizeCounter>::create_single(""sv, &size, data));

(&ncnst)->serialize(ar);
} else {
param_archive ar(rv_allocator<ClassEntrySizeCounter>::create_single(""sv, &size));
param_archive ar(rv_allocator<ClassEntrySizeCounter>::create_single(""sv, &size, data));

(&ncnst)->serialize(ar);
}
(&ncnst)->serialize(ar);

return size;
}
2 changes: 1 addition & 1 deletion src/scriptProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ void scriptProfiler::preStart() {
}, game_data_type::STRING, game_data_type::STRING);
}

if (getCommandLineParam("-profilerNetwork"sv)) {
if (getCommandLineParam("-profilerEnableNetwork"sv)) {
if (std::dynamic_pointer_cast<AdapterTracy>(GProfilerAdapter)) {
diag_log("ASP: Network statistics enabled"sv);
GNetworkProfiler.init();
Expand Down
2 changes: 1 addition & 1 deletion tracy
Submodule tracy updated from c65f9f to 55a220

0 comments on commit bd24ea1

Please sign in to comment.