Skip to content

Commit

Permalink
ST: Support /api/v1/valgrind for leaking check.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 20, 2024
1 parent 61516ad commit 43a4d2a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ if [ $SRS_SANITIZER_LOG == YES ]; then
else
srs_undefine_macro "SRS_SANITIZER_LOG" $SRS_AUTO_HEADERS_H
fi
if [ $SRS_VALGRIND == YES ]; then
srs_define_macro "SRS_VALGRIND" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_VALGRIND" $SRS_AUTO_HEADERS_H
fi

#####################################################################################
# for embeded.
Expand Down
29 changes: 29 additions & 0 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
urls->set("clusters", SrsJsonAny::str("origin cluster server API"));
urls->set("perf", SrsJsonAny::str("System performance stat"));
urls->set("tcmalloc", SrsJsonAny::str("tcmalloc api with params ?page=summary|api"));
urls->set("valgrind", SrsJsonAny::str("valgrind api to call VALGRIND_DO_LEAK_CHECK"));

SrsJsonObject* tests = SrsJsonAny::object();
obj->set("tests", tests);
Expand Down Expand Up @@ -1090,6 +1091,34 @@ srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
}
#endif

#ifdef SRS_VALGRIND
#include <valgrind/valgrind.h>
#include <valgrind/memcheck.h>

SrsGoApiValgrind::SrsGoApiValgrind()
{
}

SrsGoApiValgrind::~SrsGoApiValgrind()
{
}

srs_error_t SrsGoApiValgrind::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
srs_error_t err = srs_success;

// By default, response the json style response.
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());

obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("data", SrsJsonAny::null());

// Does a full memory check right now.
VALGRIND_DO_LEAK_CHECK;

return srs_api_response(w, r, obj->dumps());
}
#endif

SrsGoApiMetrics::SrsGoApiMetrics()
{
Expand Down
11 changes: 11 additions & 0 deletions trunk/src/app/srs_app_http_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,17 @@ class SrsGoApiTcmalloc : public ISrsHttpHandler
};
#endif

#ifdef SRS_VALGRIND
class SrsGoApiValgrind : public ISrsHttpHandler
{
public:
SrsGoApiValgrind();
virtual ~SrsGoApiValgrind();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
#endif

class SrsGoApiMetrics : public ISrsHttpHandler
{
private:
Expand Down
10 changes: 9 additions & 1 deletion trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,17 @@ srs_error_t SrsServer::http_handle()
// The test api for get tcmalloc stats.
// @see Memory Introspection in https://gperftools.github.io/gperftools/tcmalloc.html
if ((err = http_api_mux->handle("/api/v1/tcmalloc", new SrsGoApiTcmalloc())) != srs_success) {
return srs_error_wrap(err, "handle tests errors");
return srs_error_wrap(err, "handle tcmalloc errors");
}
#endif

#ifdef SRS_VALGRIND
// The test api for valgrind. See VALGRIND_DO_LEAK_CHECK in https://valgrind.org/docs/manual/mc-manual.html
if ((err = http_api_mux->handle("/api/v1/valgrind", new SrsGoApiValgrind())) != srs_success) {
return srs_error_wrap(err, "handle valgrind errors");
}
#endif

// metrics by prometheus
if ((err = http_api_mux->handle("/metrics", new SrsGoApiMetrics())) != srs_success) {
return srs_error_wrap(err, "handle tests errors");
Expand Down

0 comments on commit 43a4d2a

Please sign in to comment.