feat add profiling
This commit is contained in:
72
src/profiling/profiling.cc
Normal file
72
src/profiling/profiling.cc
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "sled/profiling/profiling.h"
|
||||
#include <uprofile.h>
|
||||
|
||||
namespace sled {
|
||||
Profiling *
|
||||
Profiling::Instance()
|
||||
{
|
||||
static Profiling instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
bool
|
||||
Profiling::Start(const std::string &file)
|
||||
{
|
||||
uprofile::start(file.c_str());
|
||||
started_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::Stop()
|
||||
{
|
||||
uprofile::stop();
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::TimeBegin(const std::string &name)
|
||||
{
|
||||
if (!started_) return;
|
||||
uprofile::timeBegin(name);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::TimeEnd(const std::string &name)
|
||||
{
|
||||
if (!started_) return;
|
||||
uprofile::timeEnd(name);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::StartProcessMemoryMonitoring(int period_ms)
|
||||
{
|
||||
if (!started_) return;
|
||||
uprofile::startProcessMemoryMonitoring(period_ms);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::StartSystemMemoryMonitoring(int period_ms)
|
||||
{
|
||||
if (!started_) return;
|
||||
uprofile::startSystemMemoryMonitoring(period_ms);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::StartCPUUsageMonitoring(int period_ms)
|
||||
{
|
||||
if (!started_) return;
|
||||
uprofile::startCPUUsageMonitoring(period_ms);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::GetSystemMemory(int &total_mem, int &available_mem, int &free_mem)
|
||||
{
|
||||
uprofile::getSystemMemory(total_mem, available_mem, free_mem);
|
||||
}
|
||||
|
||||
void
|
||||
Profiling::GetProcessMemory(int &rss, int &shared)
|
||||
{
|
||||
uprofile::getProcessMemory(rss, shared);
|
||||
}
|
||||
}// namespace sled
|
20
src/profiling/profiling_test.cc
Normal file
20
src/profiling/profiling_test.cc
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <sled/log/log.h>
|
||||
#include <sled/profiling/profiling.h>
|
||||
|
||||
TEST(Profiling, GetProcessMemory)
|
||||
{
|
||||
int rss, shared;
|
||||
sled::Profiling::GetProcessMemory(rss, shared);
|
||||
EXPECT_GT(rss, 0);
|
||||
EXPECT_GE(shared, 0);
|
||||
}
|
||||
|
||||
TEST(Profiling, GetSystemMemory)
|
||||
{
|
||||
int total_mem, available_mem, free_mem;
|
||||
sled::Profiling::GetSystemMemory(total_mem, available_mem, free_mem);
|
||||
EXPECT_GE(total_mem, 0);
|
||||
EXPECT_GE(available_mem, 0);
|
||||
EXPECT_GE(free_mem, 0);
|
||||
}
|
Reference in New Issue
Block a user