Skip to content

Commit

Permalink
fix dir
Browse files Browse the repository at this point in the history
  • Loading branch information
cyshi committed Jan 23, 2016
1 parent b0aba70 commit 5c4b53d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
43 changes: 29 additions & 14 deletions src/sofa/pbrpc/profiling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,31 @@ static std::string exec(const std::string& cmd)

void Profiling::CpuProfilingFunc()
{
bool ret = Mkdir("./rpc_profiling");
// TODO
bool ret = Mkdir(_dir.path + "/rpc_profiling");
if (ret == false)
{
return;
}
ProfilerStart("./rpc_profiling/test.prof");
std::string path = _dir.path + "/rpc_profiling/test.prof";
ProfilerStart(path.c_str());
sleep(10);
ProfilerStop();
_is_profiling = false;
}

void Profiling::MemoryProfilingFunc()
{
bool ret = Mkdir("./rpc_profiling");
if (ret == false)
{
return;
}
ProfilerStart("./rpc_profiling/test.prof");
// TODO
sleep(10);
ProfilerStop();
// bool ret = Mkdir("./rpc_profiling");
// if (ret == false)
// {
// return;
// }
// ProfilerStart("./rpc_profiling/test.prof");
// // TODO
// sleep(10);
// ProfilerStop();
}

Profiling::Profiling()
Expand All @@ -121,11 +124,21 @@ int Profiling::Init()
return -1;
}

// _self_path.resize(PATH_MAX);
char buf[PATH_MAX];
memset(buf, 0, PATH_MAX);
const char* link = "/proc/self/exe";
readlink(link, buf, PATH_MAX);
_self_path = buf;

// TODO
std::string path(buf);
int pos = path.rfind("/");
if (pos < 0)
{
return -1;
}
_dir.path = path.substr(0, pos);
_dir.name = path.substr(pos + 1, path.size());

_is_initialized = true;
return 0;
}
Expand All @@ -146,7 +159,8 @@ std::string Profiling::ProfilingPage(Type type)
if (type == GRAPH)
{
// TODO perl exist
std::string dot = exec("perl ./rpc_profiling/pprof.perl --dot " + _self_path + " ./rpc_profiling/test.prof");
std::string dot = exec("perl " + _dir.path + "/rpc_profiling/pprof.perl --dot "
+ _dir.path + "/"+ _dir.name + " " + _dir.path + "/rpc_profiling/test.prof");
oss << dot;
return oss.str();
}
Expand Down Expand Up @@ -241,7 +255,8 @@ std::string Profiling::ShowResult()
oss << "</script>";
oss << "</head>";

oss << "<div> exec path:[" << _self_path << "]</div>";
oss << "<div> exec path:[" << _dir.path << "]</div>";
oss << "<div> exec binary:[" << _dir.name << "]</div>";

// std::string dot = exec("perl ./rpc_profiling/pprof.perl --dot " + _self_path + " ./rpc_profiling/test.prof");

Expand Down
8 changes: 7 additions & 1 deletion src/sofa/pbrpc/profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ class Profiling

static void DestroyProfiling();

struct EXEDir
{
std::string path;
std::string name;
};

private:
boost::atomic<bool> _is_profiling;

boost::atomic<bool> _is_initialized;

ThreadGroupImplPtr _profiling_thread_group;

std::string _self_path;
EXEDir _dir;

static pthread_once_t _init_once;

Expand Down

0 comments on commit 5c4b53d

Please sign in to comment.