2016-02-16 23:21:12 +03:00
|
|
|
/**
|
|
|
|
Lightweight profiler library for c++
|
2017-03-30 06:14:23 +03:00
|
|
|
Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2017-03-30 06:14:23 +03:00
|
|
|
Licensed under either of
|
|
|
|
* MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
|
|
|
|
* Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
at your option.
|
2016-11-13 16:39:59 +03:00
|
|
|
|
2017-03-30 06:14:23 +03:00
|
|
|
The MIT License
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
of the Software, and to permit persons to whom the Software is furnished
|
|
|
|
to do so, subject to the following conditions:
|
2016-11-13 16:39:59 +03:00
|
|
|
|
2017-03-30 06:14:23 +03:00
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
2016-11-13 16:39:59 +03:00
|
|
|
|
2017-03-30 06:14:23 +03:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2016-11-13 16:39:59 +03:00
|
|
|
|
|
|
|
|
2017-03-30 06:14:23 +03:00
|
|
|
The Apache License, Version 2.0 (the "License");
|
|
|
|
You may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2017-03-30 06:14:23 +03:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2016-02-17 23:43:37 +03:00
|
|
|
**/
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2017-03-05 22:59:03 +03:00
|
|
|
#ifndef EASY_PROFILER_MANAGER_H
|
|
|
|
#define EASY_PROFILER_MANAGER_H
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2017-03-05 23:50:38 +03:00
|
|
|
#include <easy/profiler.h>
|
|
|
|
#include <easy/easy_socket.h>
|
|
|
|
|
2016-02-18 19:27:17 +03:00
|
|
|
#include "spin_lock.h"
|
2016-09-11 16:57:35 +03:00
|
|
|
#include "outstream.h"
|
2016-09-13 23:03:01 +03:00
|
|
|
#include "hashed_cstr.h"
|
2017-03-05 23:50:38 +03:00
|
|
|
|
2016-02-18 19:27:17 +03:00
|
|
|
#include <map>
|
2016-08-11 23:52:33 +03:00
|
|
|
#include <vector>
|
2016-09-13 23:03:01 +03:00
|
|
|
#include <unordered_map>
|
2016-09-09 06:14:34 +03:00
|
|
|
#include <thread>
|
2016-09-13 23:03:01 +03:00
|
|
|
#include <atomic>
|
2016-09-20 22:57:34 +03:00
|
|
|
//#include <list>
|
2016-02-20 05:24:12 +03:00
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-01 22:22:58 +03:00
|
|
|
#ifdef _WIN32
|
2016-06-21 00:13:45 +03:00
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
2016-09-05 22:02:32 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/syscall.h>
|
2016-09-20 22:57:34 +03:00
|
|
|
#include <chrono>
|
2016-09-26 23:11:25 +03:00
|
|
|
#include <time.h>
|
2016-06-21 00:13:45 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
inline uint32_t getCurrentThreadId()
|
|
|
|
{
|
2016-09-01 22:22:58 +03:00
|
|
|
#ifdef _WIN32
|
2016-09-06 23:03:05 +03:00
|
|
|
return (uint32_t)::GetCurrentThreadId();
|
2016-06-21 00:13:45 +03:00
|
|
|
#else
|
2016-09-06 23:03:05 +03:00
|
|
|
EASY_THREAD_LOCAL static const pid_t x = syscall(__NR_gettid);
|
|
|
|
EASY_THREAD_LOCAL static const uint32_t _id = (uint32_t)x;//std::hash<std::thread::id>()(std::this_thread::get_id());
|
2016-09-05 22:02:32 +03:00
|
|
|
return _id;
|
2016-06-21 00:13:45 +03:00
|
|
|
#endif
|
|
|
|
}
|
2016-06-20 23:21:54 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
namespace profiler {
|
|
|
|
|
|
|
|
class SerializedBlock;
|
|
|
|
|
|
|
|
struct do_not_calc_hash {
|
|
|
|
template <class T> inline size_t operator()(T _value) const {
|
|
|
|
return static_cast<size_t>(_value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2016-08-28 02:41:02 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
#ifndef EASY_ENABLE_BLOCK_STATUS
|
|
|
|
# define EASY_ENABLE_BLOCK_STATUS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EASY_ENABLE_ALIGNMENT
|
|
|
|
# define EASY_ENABLE_ALIGNMENT 0
|
|
|
|
#endif
|
2016-09-11 16:57:35 +03:00
|
|
|
|
2016-12-12 03:13:07 +03:00
|
|
|
#ifndef EASY_ALIGNMENT_SIZE
|
|
|
|
# define EASY_ALIGNMENT_SIZE 64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-09-20 22:57:34 +03:00
|
|
|
#if EASY_ENABLE_ALIGNMENT == 0
|
2016-09-11 16:57:35 +03:00
|
|
|
# define EASY_ALIGNED(TYPE, VAR, A) TYPE VAR
|
|
|
|
# define EASY_MALLOC(MEMSIZE, A) malloc(MEMSIZE)
|
|
|
|
# define EASY_FREE(MEMPTR) free(MEMPTR)
|
|
|
|
#else
|
2017-02-13 20:19:41 +03:00
|
|
|
# if defined(_MSC_VER)
|
2016-09-11 16:57:35 +03:00
|
|
|
# define EASY_ALIGNED(TYPE, VAR, A) __declspec(align(A)) TYPE VAR
|
|
|
|
# define EASY_MALLOC(MEMSIZE, A) _aligned_malloc(MEMSIZE, A)
|
|
|
|
# define EASY_FREE(MEMPTR) _aligned_free(MEMPTR)
|
|
|
|
# elif defined(__GNUC__)
|
|
|
|
# define EASY_ALIGNED(TYPE, VAR, A) TYPE VAR __attribute__(aligned(A))
|
|
|
|
# else
|
|
|
|
# define EASY_ALIGNED(TYPE, VAR, A) TYPE VAR
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <const uint16_t N>
|
2016-09-22 23:06:43 +03:00
|
|
|
class chunk_allocator
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
2016-12-12 03:13:07 +03:00
|
|
|
struct chunk { EASY_ALIGNED(int8_t, data[N], EASY_ALIGNMENT_SIZE); chunk* prev = nullptr; };
|
2016-09-11 16:57:35 +03:00
|
|
|
|
|
|
|
struct chunk_list
|
|
|
|
{
|
|
|
|
chunk* last = nullptr;
|
|
|
|
|
|
|
|
~chunk_list()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
auto p = last;
|
|
|
|
last = last->prev;
|
|
|
|
EASY_FREE(p);
|
|
|
|
} while (last != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk& back()
|
|
|
|
{
|
|
|
|
return *last;
|
|
|
|
}
|
|
|
|
|
|
|
|
void emplace_back()
|
|
|
|
{
|
|
|
|
auto prev = last;
|
2016-12-12 03:13:07 +03:00
|
|
|
last = ::new (EASY_MALLOC(sizeof(chunk), EASY_ALIGNMENT_SIZE)) chunk();
|
2016-09-11 16:57:35 +03:00
|
|
|
last->prev = prev;
|
|
|
|
*(uint16_t*)last->data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void invert()
|
|
|
|
{
|
|
|
|
chunk* next = nullptr;
|
|
|
|
|
|
|
|
while (last->prev != nullptr) {
|
|
|
|
auto p = last->prev;
|
|
|
|
last->prev = next;
|
|
|
|
next = last;
|
|
|
|
last = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
last->prev = next;
|
|
|
|
}
|
|
|
|
};
|
2016-02-16 23:21:12 +03:00
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
//typedef std::list<chunk> chunk_list;
|
|
|
|
|
|
|
|
chunk_list m_chunks;
|
|
|
|
uint32_t m_size;
|
|
|
|
uint16_t m_shift;
|
2016-02-18 19:27:17 +03:00
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
public:
|
2016-02-18 19:27:17 +03:00
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
chunk_allocator() : m_size(0), m_shift(0)
|
2016-08-28 02:41:02 +03:00
|
|
|
{
|
|
|
|
m_chunks.emplace_back();
|
|
|
|
}
|
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
void* allocate(uint16_t n)
|
2016-08-28 02:41:02 +03:00
|
|
|
{
|
2016-09-11 16:57:35 +03:00
|
|
|
++m_size;
|
|
|
|
|
|
|
|
if (!need_expand(n))
|
2016-08-28 02:41:02 +03:00
|
|
|
{
|
2016-09-11 16:57:35 +03:00
|
|
|
int8_t* data = m_chunks.back().data + m_shift;
|
|
|
|
m_shift += n + sizeof(uint16_t);
|
|
|
|
|
|
|
|
*(uint16_t*)data = n;
|
|
|
|
data = data + sizeof(uint16_t);
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
if (m_shift + 1 < N)
|
2016-09-11 16:57:35 +03:00
|
|
|
*(uint16_t*)(data + n) = 0;
|
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
m_shift = n + sizeof(uint16_t);
|
2016-08-28 02:41:02 +03:00
|
|
|
m_chunks.emplace_back();
|
2016-09-11 16:57:35 +03:00
|
|
|
auto data = m_chunks.back().data;
|
|
|
|
|
|
|
|
*(uint16_t*)data = n;
|
|
|
|
data = data + sizeof(uint16_t);
|
|
|
|
|
|
|
|
*(uint16_t*)(data + n) = 0;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool need_expand(uint16_t n) const
|
|
|
|
{
|
|
|
|
return (m_shift + n + sizeof(uint16_t)) > N;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t size() const
|
|
|
|
{
|
|
|
|
return m_size;
|
2016-08-28 02:41:02 +03:00
|
|
|
}
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
inline bool empty() const
|
|
|
|
{
|
|
|
|
return m_size == 0;
|
|
|
|
}
|
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
m_size = 0;
|
2016-09-11 16:57:35 +03:00
|
|
|
m_shift = 0;
|
2016-08-28 02:41:02 +03:00
|
|
|
m_chunks.clear();
|
|
|
|
m_chunks.emplace_back();
|
|
|
|
}
|
2016-09-11 16:57:35 +03:00
|
|
|
|
|
|
|
/** Serialize data to stream.
|
|
|
|
|
|
|
|
\warning Data will be cleared after serialization.
|
|
|
|
*/
|
|
|
|
void serialize(profiler::OStream& _outputStream)
|
|
|
|
{
|
|
|
|
m_chunks.invert();
|
|
|
|
|
|
|
|
auto current = m_chunks.last;
|
|
|
|
do {
|
|
|
|
const int8_t* data = current->data;
|
|
|
|
uint16_t i = 0;
|
2016-09-16 01:37:50 +03:00
|
|
|
while (i + 1 < N && *(uint16_t*)data != 0) {
|
2016-09-11 16:57:35 +03:00
|
|
|
const uint16_t size = sizeof(uint16_t) + *(uint16_t*)data;
|
|
|
|
_outputStream.write((const char*)data, size);
|
|
|
|
data = data + size;
|
|
|
|
i += size;
|
2016-09-16 01:37:50 +03:00
|
|
|
}
|
2016-09-11 16:57:35 +03:00
|
|
|
current = current->prev;
|
|
|
|
} while (current != nullptr);
|
|
|
|
|
|
|
|
clear();
|
|
|
|
}
|
2016-08-28 02:41:02 +03:00
|
|
|
};
|
2016-02-18 19:27:17 +03:00
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-02-20 05:24:12 +03:00
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
const uint16_t SIZEOF_CSWITCH = sizeof(profiler::BaseBlockData) + 1 + sizeof(uint16_t);
|
2016-09-04 19:35:58 +03:00
|
|
|
|
2016-09-07 21:50:42 +03:00
|
|
|
typedef std::vector<profiler::SerializedBlock*> serialized_list_t;
|
|
|
|
|
|
|
|
template <class T, const uint16_t N>
|
2016-09-22 23:06:43 +03:00
|
|
|
struct BlocksList
|
2016-08-28 02:41:02 +03:00
|
|
|
{
|
2016-09-07 21:50:42 +03:00
|
|
|
BlocksList() = default;
|
2016-02-20 05:24:12 +03:00
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
class Stack {
|
2016-09-07 21:50:42 +03:00
|
|
|
//std::stack<T> m_stack;
|
|
|
|
std::vector<T> m_stack;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
inline void clear() { m_stack.clear(); }
|
|
|
|
inline bool empty() const { return m_stack.empty(); }
|
|
|
|
|
|
|
|
inline void emplace(profiler::Block& _block) {
|
|
|
|
//m_stack.emplace(_block);
|
|
|
|
m_stack.emplace_back(_block);
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:09:47 +03:00
|
|
|
inline void emplace(profiler::Block&& _block) {
|
|
|
|
//m_stack.emplace(_block);
|
|
|
|
m_stack.emplace_back(std::forward<profiler::Block&&>(_block));
|
|
|
|
}
|
|
|
|
|
2016-09-07 21:50:42 +03:00
|
|
|
template <class ... TArgs> inline void emplace(TArgs ... _args) {
|
|
|
|
//m_stack.emplace(_args);
|
|
|
|
m_stack.emplace_back(_args...);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T& top() {
|
|
|
|
//return m_stack.top();
|
|
|
|
return m_stack.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void pop() {
|
|
|
|
//m_stack.pop();
|
|
|
|
m_stack.pop_back();
|
2016-09-04 14:48:35 +03:00
|
|
|
}
|
|
|
|
};
|
2016-08-11 23:52:33 +03:00
|
|
|
|
2016-09-07 21:50:42 +03:00
|
|
|
Stack openedList;
|
2016-09-11 16:57:35 +03:00
|
|
|
chunk_allocator<N> closedList;
|
2016-09-07 21:50:42 +03:00
|
|
|
uint64_t usedMemorySize = 0;
|
|
|
|
|
|
|
|
void clearClosed() {
|
2016-09-11 16:57:35 +03:00
|
|
|
//closedList.clear();
|
2016-09-07 21:50:42 +03:00
|
|
|
usedMemorySize = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
struct ThreadStorage
|
2016-09-07 21:50:42 +03:00
|
|
|
{
|
2016-09-11 16:57:35 +03:00
|
|
|
BlocksList<std::reference_wrapper<profiler::Block>, SIZEOF_CSWITCH * (uint16_t)128U> blocks;
|
|
|
|
BlocksList<profiler::Block, SIZEOF_CSWITCH * (uint16_t)128U> sync;
|
2016-09-06 23:03:05 +03:00
|
|
|
std::string name;
|
2016-11-27 14:26:00 +03:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
const pthread_t pthread_id;
|
|
|
|
#endif
|
|
|
|
|
2016-11-20 17:09:50 +03:00
|
|
|
const profiler::thread_id_t id;
|
2016-12-21 21:59:40 +03:00
|
|
|
std::atomic<char> expired;
|
|
|
|
std::atomic_bool frame; ///< is new frame working
|
2016-11-20 17:09:50 +03:00
|
|
|
bool allowChildren;
|
|
|
|
bool named;
|
2016-12-12 22:26:32 +03:00
|
|
|
bool guarded;
|
2016-08-11 23:52:33 +03:00
|
|
|
|
2016-09-04 14:48:35 +03:00
|
|
|
void storeBlock(const profiler::Block& _block);
|
|
|
|
void storeCSwitch(const profiler::Block& _block);
|
2016-08-28 02:41:02 +03:00
|
|
|
void clearClosed();
|
2017-04-05 22:36:06 +03:00
|
|
|
void popSilent();
|
2016-09-07 21:40:40 +03:00
|
|
|
|
2016-11-20 17:09:50 +03:00
|
|
|
ThreadStorage();
|
2016-08-28 02:41:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-12 22:26:32 +03:00
|
|
|
typedef uint32_t processid_t;
|
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
class BlockDescriptor;
|
|
|
|
|
|
|
|
class ProfileManager
|
2016-08-28 02:41:02 +03:00
|
|
|
{
|
2016-09-22 23:06:43 +03:00
|
|
|
#ifndef EASY_MAGIC_STATIC_CPP11
|
|
|
|
friend class ProfileManagerInstance;
|
|
|
|
#endif
|
2016-09-11 16:57:35 +03:00
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
ProfileManager();
|
|
|
|
ProfileManager(const ProfileManager& p) = delete;
|
|
|
|
ProfileManager& operator=(const ProfileManager&) = delete;
|
|
|
|
|
|
|
|
typedef profiler::guard_lock<profiler::spin_lock> guard_lock_t;
|
|
|
|
typedef std::map<profiler::thread_id_t, ThreadStorage> map_of_threads_stacks;
|
2016-09-22 23:06:43 +03:00
|
|
|
typedef std::vector<BlockDescriptor*> block_descriptors_t;
|
2016-09-14 23:23:09 +03:00
|
|
|
|
2017-02-13 20:19:41 +03:00
|
|
|
#ifdef EASY_PROFILER_HASHED_CSTR_DEFINED
|
2016-09-22 23:06:43 +03:00
|
|
|
typedef std::unordered_map<profiler::hashed_cstr, profiler::block_id_t> descriptors_map_t;
|
2016-09-14 23:23:09 +03:00
|
|
|
#else
|
2016-09-22 23:06:43 +03:00
|
|
|
typedef std::unordered_map<profiler::hashed_stdstring, profiler::block_id_t> descriptors_map_t;
|
2016-09-14 23:23:09 +03:00
|
|
|
#endif
|
2016-09-13 23:03:01 +03:00
|
|
|
|
2016-12-12 22:26:32 +03:00
|
|
|
const processid_t m_processId;
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
map_of_threads_stacks m_threads;
|
|
|
|
block_descriptors_t m_descriptors;
|
2016-09-22 23:06:43 +03:00
|
|
|
descriptors_map_t m_descriptorsMap;
|
2016-12-12 22:26:32 +03:00
|
|
|
uint64_t m_usedMemorySize;
|
|
|
|
profiler::timestamp_t m_beginTime;
|
|
|
|
profiler::timestamp_t m_endTime;
|
2017-03-31 21:17:08 +03:00
|
|
|
std::atomic<profiler::timestamp_t> m_frameMax;
|
2017-04-03 23:08:52 +03:00
|
|
|
std::atomic<profiler::timestamp_t> m_frameAvg;
|
|
|
|
std::atomic<profiler::timestamp_t> m_frameCur;
|
2016-09-13 23:03:01 +03:00
|
|
|
profiler::spin_lock m_spin;
|
|
|
|
profiler::spin_lock m_storedSpin;
|
2016-12-21 21:59:40 +03:00
|
|
|
profiler::spin_lock m_dumpSpin;
|
|
|
|
std::atomic<char> m_profilerStatus;
|
2016-09-13 23:03:01 +03:00
|
|
|
std::atomic_bool m_isEventTracingEnabled;
|
2016-12-21 21:59:40 +03:00
|
|
|
std::atomic_bool m_isAlreadyListening;
|
2017-04-03 23:08:52 +03:00
|
|
|
std::atomic_bool m_frameMaxReset;
|
|
|
|
std::atomic_bool m_frameAvgReset;
|
2016-09-13 23:03:01 +03:00
|
|
|
|
2016-09-05 22:11:03 +03:00
|
|
|
std::string m_csInfoFilename = "/tmp/cs_profiling_info.log";
|
|
|
|
|
2016-12-21 21:59:40 +03:00
|
|
|
uint32_t dumpBlocksToStream(profiler::OStream& _outputStream, bool _lockSpin);
|
2016-09-22 23:06:43 +03:00
|
|
|
void setBlockStatus(profiler::block_id_t _id, profiler::EasyBlockStatus _status);
|
2016-09-11 16:57:35 +03:00
|
|
|
|
2016-09-08 21:03:05 +03:00
|
|
|
std::thread m_listenThread;
|
2016-12-01 23:25:54 +03:00
|
|
|
void listen(uint16_t _port);
|
2016-09-08 21:03:05 +03:00
|
|
|
|
2016-09-08 23:15:01 +03:00
|
|
|
std::atomic_bool m_stopListen;
|
2016-09-28 00:37:20 +03:00
|
|
|
|
2016-02-16 23:21:12 +03:00
|
|
|
public:
|
2016-08-11 23:52:33 +03:00
|
|
|
|
2016-02-17 18:18:06 +03:00
|
|
|
static ProfileManager& instance();
|
2016-09-07 21:32:14 +03:00
|
|
|
~ProfileManager();
|
2016-08-11 23:52:33 +03:00
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
const profiler::BaseBlockDescriptor* addBlockDescriptor(profiler::EasyBlockStatus _defaultStatus,
|
|
|
|
const char* _autogenUniqueId,
|
|
|
|
const char* _name,
|
|
|
|
const char* _filename,
|
|
|
|
int _line,
|
|
|
|
profiler::block_type_t _block_type,
|
2016-12-21 21:59:40 +03:00
|
|
|
profiler::color_t _color,
|
|
|
|
bool _copyName = false);
|
2016-09-06 23:03:05 +03:00
|
|
|
|
2016-12-12 22:26:32 +03:00
|
|
|
bool storeBlock(const profiler::BaseBlockDescriptor* _desc, const char* _runtimeName);
|
2016-08-21 14:46:16 +03:00
|
|
|
void beginBlock(profiler::Block& _block);
|
2016-09-07 21:32:14 +03:00
|
|
|
void endBlock();
|
2017-03-31 21:17:08 +03:00
|
|
|
profiler::timestamp_t maxFrameDuration();
|
2017-04-03 23:08:52 +03:00
|
|
|
profiler::timestamp_t avgFrameDuration();
|
|
|
|
profiler::timestamp_t curFrameDuration() const;
|
2016-12-21 21:59:40 +03:00
|
|
|
void setEnabled(bool isEnable);
|
2017-03-01 11:14:02 +02:00
|
|
|
bool isEnabled() const;
|
2016-09-15 23:15:07 +03:00
|
|
|
void setEventTracingEnabled(bool _isEnable);
|
2017-03-01 11:14:02 +02:00
|
|
|
bool isEventTracingEnabled() const;
|
2016-08-28 02:41:02 +03:00
|
|
|
uint32_t dumpBlocksToFile(const char* filename);
|
2016-09-20 22:57:34 +03:00
|
|
|
const char* registerThread(const char* name, profiler::ThreadGuard& threadGuard);
|
2016-11-20 17:09:50 +03:00
|
|
|
const char* registerThread(const char* name);
|
2016-08-28 02:41:02 +03:00
|
|
|
|
2016-09-05 22:11:03 +03:00
|
|
|
void setContextSwitchLogFilename(const char* name)
|
|
|
|
{
|
|
|
|
m_csInfoFilename = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* getContextSwitchLogFilename() const
|
|
|
|
{
|
|
|
|
return m_csInfoFilename.c_str();
|
|
|
|
}
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
void beginContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _time, profiler::thread_id_t _target_thread_id, const char* _target_process, bool _lockSpin = true);
|
2016-12-12 22:26:32 +03:00
|
|
|
void endContextSwitch(profiler::thread_id_t _thread_id, processid_t _process_id, profiler::timestamp_t _endtime, bool _lockSpin = true);
|
2016-12-01 23:30:43 +03:00
|
|
|
void startListen(uint16_t _port);
|
|
|
|
void stopListen();
|
2017-03-01 11:14:02 +02:00
|
|
|
bool isListening() const;
|
2016-09-28 00:37:20 +03:00
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
private:
|
|
|
|
|
2017-04-02 14:23:11 +03:00
|
|
|
void beginFrame();
|
|
|
|
void endFrame();
|
|
|
|
|
2016-12-21 21:59:40 +03:00
|
|
|
void enableEventTracer();
|
|
|
|
void disableEventTracer();
|
|
|
|
|
|
|
|
char checkThreadExpired(ThreadStorage& _registeredThread);
|
2016-11-20 17:09:50 +03:00
|
|
|
|
2016-09-28 00:37:20 +03:00
|
|
|
void storeBlockForce(const profiler::BaseBlockDescriptor* _desc, const char* _runtimeName, ::profiler::timestamp_t& _timestamp);
|
|
|
|
void storeBlockForce2(const profiler::BaseBlockDescriptor* _desc, const char* _runtimeName, ::profiler::timestamp_t _timestamp);
|
2016-12-12 22:26:32 +03:00
|
|
|
void storeBlockForce2(ThreadStorage& _registeredThread, const profiler::BaseBlockDescriptor* _desc, const char* _runtimeName, ::profiler::timestamp_t _timestamp);
|
2016-09-28 00:37:20 +03:00
|
|
|
|
2016-12-12 22:26:32 +03:00
|
|
|
ThreadStorage& _threadStorage(profiler::thread_id_t _thread_id);
|
2016-09-13 23:03:01 +03:00
|
|
|
ThreadStorage* _findThreadStorage(profiler::thread_id_t _thread_id);
|
|
|
|
|
2016-12-12 22:26:32 +03:00
|
|
|
inline ThreadStorage& threadStorage(profiler::thread_id_t _thread_id)
|
|
|
|
{
|
|
|
|
guard_lock_t lock(m_spin);
|
|
|
|
return _threadStorage(_thread_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ThreadStorage* findThreadStorage(profiler::thread_id_t _thread_id)
|
2016-09-13 23:03:01 +03:00
|
|
|
{
|
|
|
|
guard_lock_t lock(m_spin);
|
|
|
|
return _findThreadStorage(_thread_id);
|
|
|
|
}
|
2016-02-16 23:21:12 +03:00
|
|
|
};
|
|
|
|
|
2017-03-05 22:59:03 +03:00
|
|
|
#endif // EASY_PROFILER_MANAGER_H
|