From b5f71a8a079665e98de31e1a15634c86c27cb10e Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 19 Nov 2024 11:53:39 -0300 Subject: [PATCH] perf: replace manual function name extraction with std::source_location (#3132) Replaced the previous string concatenation approach for logging function names with `std::source_location::current().function_name()`. This change significantly improves performance by avoiding runtime string operations. Instead of manually manipulating function signatures using `methodName` to extract function names, `std::source_location` provides this information directly in an efficient manner. --- src/creatures/combat/combat.cpp | 12 ++--- src/creatures/creature.cpp | 50 +++++++++--------- src/game/game.cpp | 52 +++++++++---------- .../functions/core/game/config_functions.cpp | 2 +- src/lua/scripts/luascript.cpp | 2 +- src/pch.hpp | 15 ------ src/utils/definitions.hpp | 2 + 7 files changed, 61 insertions(+), 74 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 34a28398e9e..6b7667a71a5 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -1066,7 +1066,7 @@ void Combat::setupChain(const std::shared_ptr &weapon) { } bool Combat::doCombatChain(const std::shared_ptr &caster, const std::shared_ptr &target, bool aggressive) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!params.chainCallback) { return false; } @@ -1469,7 +1469,7 @@ void Combat::setRuneSpellName(const std::string &value) { std::vector>> Combat::pickChainTargets(const std::shared_ptr &caster, const CombatParams ¶ms, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive, const std::shared_ptr &initialTarget /* = nullptr */) { Benchmark bm_pickChain; - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!caster) { return {}; } @@ -1512,7 +1512,7 @@ std::vector>> Combat::pickChainTargets } if (closestSpectator) { - g_logger().trace("[{}] closestSpectator: {}", __METHOD_NAME__, closestSpectator->getName()); + g_logger().trace("[{}] closestSpectator: {}", __FUNCTION__, closestSpectator->getName()); bool found = false; for (auto &[pos, vec] : resultMap) { @@ -1531,7 +1531,7 @@ std::vector>> Combat::pickChainTargets continue; } if (backtracking) { - g_logger().debug("[{}] backtracking", __METHOD_NAME__); + g_logger().debug("[{}] backtracking", __FUNCTION__); targets.pop_back(); backtrackingAttempts--; continue; @@ -1539,7 +1539,7 @@ std::vector>> Combat::pickChainTargets break; } - g_logger().debug("[{}] resultMap: {} in {} ms", __METHOD_NAME__, resultMap.size(), bm_pickChain.duration()); + g_logger().debug("[{}] resultMap: {} in {} ms", __FUNCTION__, resultMap.size(), bm_pickChain.duration()); return resultMap; } @@ -2221,7 +2221,7 @@ void MagicField::onStepInField(const std::shared_ptr &creature) { } void Combat::applyExtensions(const std::shared_ptr &caster, const std::shared_ptr &target, CombatDamage &damage, const CombatParams ¶ms) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (damage.extension || !caster || damage.primary.type == COMBAT_HEALING) { return; } diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 2081b0572fc..32f3c598b81 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -35,7 +35,7 @@ Creature::~Creature() { } bool Creature::canSee(const Position &myPos, const Position &pos, int32_t viewRangeX, int32_t viewRangeY) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (myPos.z <= MAP_INIT_SURFACE_LAYER) { // we are on ground level or above (7 -> 0) // view is from 7 -> 0 @@ -95,7 +95,7 @@ int32_t Creature::getWalkSize() { } void Creature::onThink(uint32_t interval) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &followCreature = getFollowCreature(); const auto &master = getMaster(); @@ -168,7 +168,7 @@ void Creature::onCreatureWalk() { checkingWalkCreature = true; - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); g_dispatcher().addWalkEvent([self = getCreature(), this] { checkingWalkCreature = false; @@ -287,7 +287,7 @@ void Creature::stopEventWalk() { } void Creature::onCreatureAppear(const std::shared_ptr &creature, bool isLogin) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature.get() == this) { if (isLogin) { setLastPosition(getPosition()); @@ -296,7 +296,7 @@ void Creature::onCreatureAppear(const std::shared_ptr &creature, bool } void Creature::onRemoveCreature(const std::shared_ptr &creature, bool) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); onCreatureDisappear(creature, true); // Update player from monster target list (avoid memory usage after clean) @@ -307,7 +307,7 @@ void Creature::onRemoveCreature(const std::shared_ptr &creature, bool) } void Creature::onCreatureDisappear(const std::shared_ptr &creature, bool isLogout) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (getAttackedCreature() == creature) { setAttackedCreature(nullptr); onAttackedCreatureDisappear(isLogout); @@ -320,7 +320,7 @@ void Creature::onCreatureDisappear(const std::shared_ptr &creature, bo } void Creature::onChangeZone(ZoneType_t zone) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &attackedCreature = getAttackedCreature(); if (attackedCreature && zone == ZONE_PROTECTION) { onCreatureDisappear(attackedCreature, false); @@ -328,7 +328,7 @@ void Creature::onChangeZone(ZoneType_t zone) { } void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (zone == ZONE_PROTECTION) { const auto &attackedCreature = getAttackedCreature(); if (attackedCreature) { @@ -338,7 +338,7 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { } void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (hasSummons()) { std::vector> despawnMonsterList; for (const auto &summon : getSummons()) { @@ -385,7 +385,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { } void Creature::onCreatureMove(const std::shared_ptr &creature, const std::shared_ptr &newTile, const Position &newPos, const std::shared_ptr &oldTile, const Position &oldPos, bool teleport) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature.get() == this) { lastStep = OTSYS_TIME(); lastStepCost = 1; @@ -447,7 +447,7 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s } void Creature::onDeath() { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); bool lastHitUnjustified = false; bool mostDamageUnjustified = false; const auto &lastHitCreature = g_game().getCreatureByID(lastHitCreatureId); @@ -585,7 +585,7 @@ void Creature::onDeath() { } bool Creature::dropCorpse(const std::shared_ptr &lastHitCreature, const std::shared_ptr &mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!lootDrop && getMonster()) { if (getMaster()) { // Scripting event onDeath @@ -882,7 +882,7 @@ void Creature::goToFollowCreature_async(std::function &&onComplete) { } void Creature::goToFollowCreature() { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &followCreature = getFollowCreature(); if (!followCreature) { return; @@ -937,7 +937,7 @@ bool Creature::canFollowMaster() const { } bool Creature::setFollowCreature(const std::shared_ptr &creature) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature) { if (getFollowCreature() == creature) { return true; @@ -1086,7 +1086,7 @@ void Creature::onAttackedCreatureDrainHealth(const std::shared_ptr &ta } void Creature::onAttackedCreatureKilled(const std::shared_ptr &target) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (target != getCreature()) { uint64_t gainExp = target->getGainedExperience(static_self_cast()); onGainExperience(gainExp, target); @@ -1094,7 +1094,7 @@ void Creature::onAttackedCreatureKilled(const std::shared_ptr &target) } bool Creature::deprecatedOnKilledCreature(const std::shared_ptr &target, bool lastHit) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &master = getMaster(); if (master) { master->deprecatedOnKilledCreature(target, lastHit); @@ -1109,7 +1109,7 @@ bool Creature::deprecatedOnKilledCreature(const std::shared_ptr &targe } void Creature::onGainExperience(uint64_t gainExp, const std::shared_ptr &target) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &master = getMaster(); if (gainExp == 0 || !master) { return; @@ -1140,7 +1140,7 @@ void Creature::onGainExperience(uint64_t gainExp, const std::shared_ptr &newMaster, bool reloadCreature /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); // Persists if this creature has ever been a summon this->summoned = true; const auto &oldMaster = getMaster(); @@ -1173,7 +1173,7 @@ bool Creature::setMaster(const std::shared_ptr &newMaster, bool reload } bool Creature::addCondition(const std::shared_ptr &condition, bool attackerPlayer /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (condition == nullptr) { return false; } @@ -1211,7 +1211,7 @@ bool Creature::addCombatCondition(const std::shared_ptr &condition, b } void Creature::removeCondition(ConditionType_t type) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); auto it = conditions.begin(), end = conditions.end(); while (it != end) { std::shared_ptr condition = *it; @@ -1229,7 +1229,7 @@ void Creature::removeCondition(ConditionType_t type) { } void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t conditionId, bool force /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); auto it = conditions.begin(); const auto end = conditions.end(); while (it != end) { @@ -1292,7 +1292,7 @@ std::shared_ptr Creature::getCondition(ConditionType_t type) const { } std::shared_ptr Creature::getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId /* = 0*/) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); for (const auto &condition : conditions) { if (condition->getType() == type && condition->getId() == conditionId && condition->getSubId() == subId) { return condition; @@ -1312,7 +1312,7 @@ std::vector> Creature::getConditionsByType(ConditionT } void Creature::executeConditions(uint32_t interval) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); auto it = conditions.begin(), end = conditions.end(); while (it != end) { std::shared_ptr condition = *it; @@ -1331,7 +1331,7 @@ void Creature::executeConditions(uint32_t interval) { } bool Creature::hasCondition(ConditionType_t type, uint32_t subId /* = 0*/) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (isSuppress(type, false)) { return false; } @@ -1607,7 +1607,7 @@ ZoneType_t Creature::getZoneType() { } bool Creature::getPathTo(const Position &targetPos, std::vector &dirList, const FindPathParams &fpp) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (fpp.maxSearchDist != 0 || fpp.keepDistance) { return g_game().map.getPathMatchingCond(getCreature(), targetPos, dirList, FrozenPathingConditionCall(targetPos), fpp); } diff --git a/src/game/game.cpp b/src/game/game.cpp index 77a277c69ad..cde008d4f65 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1161,7 +1161,7 @@ bool Game::internalPlaceCreature(const std::shared_ptr &creature, cons } bool Game::placeCreature(const std::shared_ptr &creature, const Position &pos, bool extendedPos /*=false*/, bool forced /*= false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!internalPlaceCreature(creature, pos, extendedPos, forced)) { return false; } @@ -1188,7 +1188,7 @@ bool Game::placeCreature(const std::shared_ptr &creature, const Positi } bool Game::removeCreature(const std::shared_ptr &creature, bool isLogout /* = true*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!creature || creature->isRemoved()) { return false; } @@ -1256,7 +1256,7 @@ bool Game::removeCreature(const std::shared_ptr &creature, bool isLogo } void Game::executeDeath(uint32_t creatureId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); std::shared_ptr creature = getCreatureByID(creatureId); if (creature && !creature->isRemoved()) { afterCreatureZoneChange(creature, creature->getZones(), {}); @@ -1265,7 +1265,7 @@ void Game::executeDeath(uint32_t creatureId) { } void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player || !player->hasFlag(PlayerFlags_t::CanMapClickTeleport)) { return; @@ -1278,7 +1278,7 @@ void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { } void Game::playerInspectItem(const std::shared_ptr &player, const Position &pos) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const std::shared_ptr &thing = internalGetThing(player, pos, 0, 0, STACKPOS_TOPDOWN_ITEM); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); @@ -1295,7 +1295,7 @@ void Game::playerInspectItem(const std::shared_ptr &player, const Positi } void Game::playerInspectItem(const std::shared_ptr &player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); player->sendItemInspection(itemId, itemCount, nullptr, cyclopedia); } @@ -1349,7 +1349,7 @@ FILELOADER_ERRORS Game::loadAppearanceProtobuf(const std::string &file) { } void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -1434,7 +1434,7 @@ void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, } void Game::playerMoveCreature(const std::shared_ptr &player, const std::shared_ptr &movingCreature, const Position &movingCreatureOrigPos, const std::shared_ptr &toTile) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); g_dispatcher().addWalkEvent([=, this] { if (!player->canDoAction()) { @@ -1590,7 +1590,7 @@ ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature } ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature, const std::shared_ptr &toTile, uint32_t flags /*= 0*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature->hasCondition(CONDITION_ROOTED)) { return RETURNVALUE_NOTPOSSIBLE; } @@ -2009,7 +2009,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, } ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, const std::shared_ptr &item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags /*= 0*/, const std::shared_ptr &actor /*=nullptr*/, const std::shared_ptr &tradeItem /* = nullptr*/, bool checkTile /* = true*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (fromCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2271,7 +2271,7 @@ ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, const st } ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, const std::shared_ptr &item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (toCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2359,7 +2359,7 @@ ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, const st ReturnValue Game::internalRemoveItem(const std::shared_ptr &items, int32_t count /*= -1*/, bool test /*= false*/, uint32_t flags /*= 0*/, bool force /*= false*/) { auto item = items; - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (item == nullptr) { g_logger().debug("{} - Item is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2439,7 +2439,7 @@ std::tuple Game::addItemBatch(const std::shared return std::make_tuple(ret, totalAdded, containersCreated); } - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = toCylinder->getPlayer(); bool dropping = false; auto setupDestination = [&]() -> std::shared_ptr { @@ -2519,7 +2519,7 @@ std::tuple Game::addItemBatch(const std::shared } std::tuple Game::createItemBatch(const std::shared_ptr &toCylinder, const std::vector> &itemCounts, uint32_t flags /* = 0 */, bool dropOnMap /* = true */, uint32_t autoContainerId /* = 0 */) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); std::vector> items; for (const auto &[itemId, count, subType] : itemCounts) { const auto &itemType = Item::items[itemId]; @@ -2553,7 +2553,7 @@ std::tuple Game::createItem(const std::shared_p } ReturnValue Game::internalPlayerAddItem(const std::shared_ptr &player, const std::shared_ptr &item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); uint32_t remainderCount = 0; ReturnValue ret; if (slot == CONST_SLOT_WHEREEVER) { @@ -2585,7 +2585,7 @@ ReturnValue Game::internalPlayerAddItem(const std::shared_ptr &player, c } std::shared_ptr Game::findItemOfType(const std::shared_ptr &cylinder, uint16_t itemId, bool depthSearch /*= true*/, int32_t subType /*= -1*/) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (cylinder == nullptr) { g_logger().error("[{}] Cylinder is nullptr", __FUNCTION__); return nullptr; @@ -2751,7 +2751,7 @@ void Game::addMoney(const std::shared_ptr &cylinder, uint64_t money, u } std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t newId, int32_t newCount /*= -1*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0))) { // chargeless item placed on map = infinite return item; } @@ -2889,7 +2889,7 @@ std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t n } ReturnValue Game::internalTeleport(const std::shared_ptr &thing, const Position &newPos, bool pushMove /* = true*/, uint32_t flags /*= 0*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (thing == nullptr) { g_logger().error("[{}] thing is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -3676,7 +3676,7 @@ void Game::playerStopAutoWalk(uint32_t playerId) { } void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint16_t fromItemId, const Position &toPos, uint8_t toStackPos, uint16_t toItemId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -3821,7 +3821,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPos, uint8_t index, uint16_t itemId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -3931,7 +3931,7 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo } void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t itemId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -5285,7 +5285,7 @@ void Game::internalCloseTrade(const std::shared_ptr &player) { } void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint16_t amount, bool ignoreCap /* = false*/, bool inBackpacks /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (amount == 0) { return; } @@ -5341,7 +5341,7 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint } void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint16_t amount, bool ignoreEquipped) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (amount == 0) { return; } @@ -6445,14 +6445,14 @@ void Game::addCreatureCheck(const std::shared_ptr &creature) { } void Game::removeCreatureCheck(const std::shared_ptr &creature) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature->inCheckCreaturesVector.load()) { creature->creatureCheck.store(false); } } void Game::checkCreatures() { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); static size_t index = 0; std::erase_if(checkCreatureLists[index], [this](const std::shared_ptr creature) { @@ -9481,7 +9481,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui } void Game::playerForgeFuseItems(uint32_t playerId, ForgeAction_t actionType, uint16_t firstItemId, uint8_t tier, uint16_t secondItemId, bool usedCore, bool reduceTierLoss, bool convergence) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; diff --git a/src/lua/functions/core/game/config_functions.cpp b/src/lua/functions/core/game/config_functions.cpp index 045ea7519f1..029895a43e5 100644 --- a/src/lua/functions/core/game/config_functions.cpp +++ b/src/lua/functions/core/game/config_functions.cpp @@ -83,7 +83,7 @@ int ConfigFunctions::luaConfigManagerGetFloat(lua_State* L) { float value = g_configManager().getFloat(key); double finalValue = shouldRound ? static_cast(std::round(value * 100.0) / 100.0) : value; - g_logger().debug("[{}] key: {}, finalValue: {}, shouldRound: {}", __METHOD_NAME__, magic_enum::enum_name(key), finalValue, shouldRound); + g_logger().debug("[{}] key: {}, finalValue: {}, shouldRound: {}", __FUNCTION__, magic_enum::enum_name(key), finalValue, shouldRound); lua_pushnumber(L, finalValue); return 1; } diff --git a/src/lua/scripts/luascript.cpp b/src/lua/scripts/luascript.cpp index 7c0ce2c096c..9bb926b5676 100644 --- a/src/lua/scripts/luascript.cpp +++ b/src/lua/scripts/luascript.cpp @@ -237,7 +237,7 @@ bool LuaScriptInterface::closeState() { std::string LuaScriptInterface::getMetricsScope() const { #ifdef FEATURE_METRICS - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); int32_t scriptId; int32_t callbackId; bool timerEvent; diff --git a/src/pch.hpp b/src/pch.hpp index 79f14433fcc..d66b5fc10ce 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -170,20 +170,5 @@ format_as(E e) { #include "lua/global/shared_object.hpp" -constexpr std::string_view methodName(const char* s) { - const std::string_view prettyFunction(s); - const size_t bracket = prettyFunction.rfind('('); - const size_t space = prettyFunction.rfind(' ', bracket) + 1; - return prettyFunction.substr(space, bracket - space); -} - -#if defined(__GNUC__) || defined(__clang__) - #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) -#elif defined(_MSC_VER) - #define __METHOD_NAME__ methodName(__FUNCSIG__) -#else - #error "Compiler not supported" -#endif - #include "account/account_info.hpp" #include "config/config_enums.hpp" diff --git a/src/utils/definitions.hpp b/src/utils/definitions.hpp index d557896f361..24a6b7d134b 100644 --- a/src/utils/definitions.hpp +++ b/src/utils/definitions.hpp @@ -13,6 +13,8 @@ #define __FUNCTION__ __func__ #endif +#define __METRICS_METHOD_NAME__ std::source_location::current().function_name() + #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif