File memory_monitor_api.cpp¶
File List > base > memory_monitor_api.cpp
Go to the documentation of this file
/*
*
* Copyright 2016 CUBRID Corporation
*
* Licensed under 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
*
* 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.
*
*/
/*
* memory_monitor_api.cpp - Implementation of memory monitor APIs
*/
#if !defined(WINDOWS)
#include <cassert>
#include "error_manager.h"
#include "system_parameter.h"
#include "memory_monitor_sr.hpp"
namespace cubmem
{
memory_monitor *mmon_Gl = nullptr;
}
using namespace cubmem;
int mmon_initialize (const char *server_name)
{
int error = NO_ERROR;
assert (mmon_Gl == nullptr && mmon_disabled == true);
assert (server_name != nullptr);
if (prm_get_bool_value (PRM_ID_ENABLE_MEMORY_MONITORING))
{
mmon_Gl = new (std::nothrow) memory_monitor (server_name);
if (mmon_Gl == nullptr)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, sizeof (memory_monitor));
error = ER_OUT_OF_VIRTUAL_MEMORY;
return error;
}
mmon_disabled = false;
}
return error;
}
void mmon_finalize ()
{
if (mmon_Gl != nullptr)
{
#if !defined (NDEBUG)
mmon_Gl->finalize_dump ();
#endif
#if (MMON_DEBUG_LEVEL == 1) || (MMON_DEBUG_LEVEL == 3)
mmon_Gl->print_debug_result ();
#endif
delete mmon_Gl;
mmon_Gl = nullptr;
mmon_disabled = true;
}
}
size_t mmon_get_allocated_size (char *ptr)
{
return mmon_Gl->get_allocated_size (ptr);
}
void mmon_aggregate_server_info (MMON_SERVER_INFO &server_info)
{
mmon_Gl->aggregate_server_info (server_info);
}
#endif // !WINDOWS