feat add profiling

This commit is contained in:
tqcq
2024-03-16 22:56:10 +08:00
parent e05c1f4894
commit 719fecd4bc
30 changed files with 4673 additions and 1 deletions

View 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

View 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);
}