2016-09-06 22:15:50 +03:00
|
|
|
/************************************************************************
|
|
|
|
* file name : block.cpp
|
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/02/16
|
|
|
|
* authors : Sergey Yagovtsev, Victor Zarubkin
|
|
|
|
* emails : yse.sey@gmail.com, v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
|
|
|
* description : The file contains implementation of profiling blocks
|
|
|
|
* :
|
|
|
|
* license : Lightweight profiler library for c++
|
2017-03-30 06:55:15 +03:00
|
|
|
* : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
|
2016-09-06 22:15:50 +03:00
|
|
|
* :
|
2017-03-30 06:55:15 +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:55:15 +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:
|
|
|
|
* :
|
|
|
|
* : The above copyright notice and this permission notice shall be included in all
|
|
|
|
* : copies or substantial portions of the Software.
|
|
|
|
* :
|
|
|
|
* : 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.
|
|
|
|
* :
|
|
|
|
* : The Apache License, Version 2.0 (the "License")
|
|
|
|
* :
|
|
|
|
* : You may not use this file except in compliance with the License.
|
2016-11-13 16:39:59 +03:00
|
|
|
* : You may obtain a copy of the License at
|
|
|
|
* :
|
|
|
|
* : 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-09-06 22:15:50 +03:00
|
|
|
************************************************************************/
|
2016-09-20 22:57:34 +03:00
|
|
|
|
2016-06-20 23:21:54 +03:00
|
|
|
#include "profile_manager.h"
|
2016-09-26 23:23:38 +03:00
|
|
|
#include "current_time.h"
|
2016-02-16 23:21:12 +03:00
|
|
|
|
|
|
|
using namespace profiler;
|
|
|
|
|
2016-11-20 13:42:05 +03:00
|
|
|
#ifndef EASY_PROFILER_API_DISABLED
|
2016-08-28 02:41:02 +03:00
|
|
|
BaseBlockData::BaseBlockData(timestamp_t _begin_time, block_id_t _descriptor_id)
|
|
|
|
: m_begin(_begin_time)
|
|
|
|
, m_end(0)
|
|
|
|
, m_id(_descriptor_id)
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
2016-08-28 02:41:02 +03:00
|
|
|
|
2016-02-16 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 23:10:14 +03:00
|
|
|
BaseBlockData::BaseBlockData(timestamp_t _begin_time, timestamp_t _end_time, block_id_t _descriptor_id)
|
|
|
|
: m_begin(_begin_time)
|
|
|
|
, m_end(_end_time)
|
|
|
|
, m_id(_descriptor_id)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-04 14:48:35 +03:00
|
|
|
Block::Block(Block&& that)
|
|
|
|
: BaseBlockData(that.m_begin, that.m_id)
|
|
|
|
, m_name(that.m_name)
|
2016-09-20 22:57:34 +03:00
|
|
|
, m_status(that.m_status)
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(that.m_isScoped)
|
2016-09-04 14:48:35 +03:00
|
|
|
{
|
|
|
|
m_end = that.m_end;
|
2017-04-17 22:27:10 +03:00
|
|
|
that.m_end = that.m_begin;
|
2016-09-04 14:48:35 +03:00
|
|
|
}
|
|
|
|
|
2016-11-20 13:42:05 +03:00
|
|
|
Block::Block(timestamp_t _begin_time, block_id_t _descriptor_id, const char* _runtimeName)
|
|
|
|
: BaseBlockData(_begin_time, _descriptor_id)
|
2016-09-11 16:57:35 +03:00
|
|
|
, m_name(_runtimeName)
|
2016-11-20 13:42:05 +03:00
|
|
|
, m_status(::profiler::ON)
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(true)
|
2016-09-04 14:48:35 +03:00
|
|
|
{
|
2016-09-20 22:57:34 +03:00
|
|
|
|
2016-09-04 14:48:35 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 23:10:14 +03:00
|
|
|
Block::Block(timestamp_t _begin_time, timestamp_t _end_time, block_id_t _descriptor_id, const char* _runtimeName)
|
|
|
|
: BaseBlockData(_begin_time, _end_time, _descriptor_id)
|
|
|
|
, m_name(_runtimeName)
|
|
|
|
, m_status(::profiler::ON)
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(true)
|
2017-04-06 23:10:14 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-17 22:27:10 +03:00
|
|
|
Block::Block(const BaseBlockDescriptor* _descriptor, const char* _runtimeName, bool _scoped)
|
2016-11-20 13:42:05 +03:00
|
|
|
: BaseBlockData(1ULL, _descriptor->id())
|
2016-09-09 00:09:47 +03:00
|
|
|
, m_name(_runtimeName)
|
2016-11-20 13:42:05 +03:00
|
|
|
, m_status(_descriptor->status())
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(_scoped)
|
2016-09-11 16:57:35 +03:00
|
|
|
{
|
2016-09-20 22:57:34 +03:00
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Block::start()
|
|
|
|
{
|
|
|
|
m_begin = getCurrentTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Block::start(timestamp_t _time)
|
2016-08-28 02:41:02 +03:00
|
|
|
{
|
2016-09-11 16:57:35 +03:00
|
|
|
m_begin = _time;
|
2016-08-28 02:41:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Block::finish()
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
2016-08-28 02:41:02 +03:00
|
|
|
m_end = getCurrentTime();
|
|
|
|
}
|
2016-02-20 05:24:12 +03:00
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
void Block::finish(timestamp_t _time)
|
2016-09-04 14:48:35 +03:00
|
|
|
{
|
2016-09-11 16:57:35 +03:00
|
|
|
m_end = _time;
|
2016-09-04 14:48:35 +03:00
|
|
|
}
|
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
Block::~Block()
|
|
|
|
{
|
2016-09-09 00:09:47 +03:00
|
|
|
if (!finished())
|
2016-08-28 02:41:02 +03:00
|
|
|
::profiler::endBlock();
|
2016-02-16 23:25:12 +03:00
|
|
|
}
|
2016-11-20 13:42:05 +03:00
|
|
|
#else
|
|
|
|
BaseBlockData::BaseBlockData(timestamp_t, block_id_t)
|
|
|
|
: m_begin(0)
|
|
|
|
, m_end(0)
|
|
|
|
, m_id(~0U)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-17 22:27:10 +03:00
|
|
|
Block::Block(Block&& that)
|
2016-11-20 13:42:05 +03:00
|
|
|
: BaseBlockData(0, ~0U)
|
|
|
|
, m_name("")
|
|
|
|
, m_status(::profiler::OFF)
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(that.m_isScoped)
|
2016-11-20 13:42:05 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::Block(timestamp_t, block_id_t, const char*)
|
|
|
|
: BaseBlockData(0, ~0U)
|
|
|
|
, m_name("")
|
|
|
|
, m_status(::profiler::OFF)
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(true)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::Block(timestamp_t, timestamp_t, block_id_t, const char*)
|
|
|
|
: BaseBlockData(0, ~0U)
|
|
|
|
, m_name("")
|
|
|
|
, m_status(::profiler::OFF)
|
|
|
|
, m_isScoped(true)
|
2016-11-20 13:42:05 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-17 22:27:10 +03:00
|
|
|
Block::Block(const BaseBlockDescriptor*, const char*, bool _scoped)
|
2016-11-20 13:42:05 +03:00
|
|
|
: BaseBlockData(0, ~0U)
|
|
|
|
, m_name("")
|
|
|
|
, m_status(::profiler::OFF)
|
2017-04-17 22:27:10 +03:00
|
|
|
, m_isScoped(_scoped)
|
2016-11-20 13:42:05 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Block::start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Block::start(timestamp_t)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Block::finish()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Block::finish(timestamp_t)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::~Block()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|