Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Profile.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 14 Lines | |||||
#include <vector> | #include <vector> | ||||
#include "lib/adts/ring_buf.h" | #include "lib/adts/ring_buf.h" | ||||
#include "lib/posix/posix_pthread.h" | #include "lib/posix/posix_pthread.h" | ||||
#include "ps/Profiler2.h" | #include "ps/Profiler2.h" | ||||
#include "ps/Singleton.h" | #include "ps/Singleton.h" | ||||
#include <boost/flyweight.hpp> | |||||
#include <boost/flyweight/key_value.hpp> | |||||
#include <boost/flyweight/no_locking.hpp> | |||||
#include <boost/flyweight/no_tracking.hpp> | |||||
#define PROFILE_AMORTIZE_FRAMES 30 | #define PROFILE_AMORTIZE_FRAMES 30 | ||||
#define PROFILE_AMORTIZE_TURNS 1 | #define PROFILE_AMORTIZE_TURNS 1 | ||||
class CProfileManager; | class CProfileManager; | ||||
class CProfileNodeTable; | class CProfileNodeTable; | ||||
// To profile scripts usefully, we use a call hook that's called on every enter/exit, | // To profile scripts usefully, we use a call hook that's called on every enter/exit, | ||||
// and need to find the function name. But most functions are anonymous so we make do | // and need to find the function name. But most functions are anonymous so we make do | ||||
// with filename plus line number instead. | // with filename plus line number instead. | ||||
// Computing the names is fairly expensive, and we need to return an interned char* | // Computing the names is fairly expensive, and we need to return an interned char* | ||||
// for the profiler to hold a copy of, so we use boost::flyweight to construct interned | // for the profiler to hold a copy of, so we use boost::flyweight to construct interned | ||||
// strings per call location. | // strings per call location. | ||||
// | // | ||||
// TODO: Check again how much the overhead for getting filename and line really is and if | // TODO: Check again how much the overhead for getting filename and line really is and if | ||||
// it has increased with the new approach after the SpiderMonkey 31 upgrade. | // it has increased with the new approach after the SpiderMonkey 31 upgrade. | ||||
// | |||||
// Flyweight types (with no_locking because the call hooks are only used in the | |||||
// main thread, and no_tracking because we mustn't delete values the profiler is | |||||
// using and it's not going to waste much memory) | |||||
typedef boost::flyweight< | |||||
std::string, | |||||
boost::flyweights::no_tracking, | |||||
boost::flyweights::no_locking | |||||
> StringFlyweight; | |||||
class CProfileNode | class CProfileNode | ||||
{ | { | ||||
NONCOPYABLE(CProfileNode); | NONCOPYABLE(CProfileNode); | ||||
public: | public: | ||||
typedef std::vector<CProfileNode*>::iterator profile_iterator; | typedef std::vector<CProfileNode*>::iterator profile_iterator; | ||||
typedef std::vector<CProfileNode*>::const_iterator const_profile_iterator; | typedef std::vector<CProfileNode*>::const_iterator const_profile_iterator; | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator