1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00
srs/trunk/src/app/srs_app_http_api.hpp
Winlin 0d76081430
API: Support new HTTP API for VALGRIND. v6.0.149 v7.0.6 (#4150)
New features for valgrind:

1. ST: Support /api/v1/valgrind for leaking check.
2. ST: Support /api/v1/valgrind?check=full|added|changed|new|quick

To use Valgrind to detect memory leaks in SRS, even though Valgrind
hooks are supported in ST, there are still many false positives. A more
reasonable approach is to have Valgrind report incremental memory leaks.
This way, global and static variables can be avoided, and detection can
be achieved without exiting the program. Follow these steps:

1. Compile SRS with Valgrind support: `./configure --valgrind=on &&
make`
2. Start SRS with memory leak detection enabled: `valgrind
--leak-check=full ./objs/srs -c conf/console.conf`
3. Trigger memory detection by using curl to access the API and generate
calibration data. There will still be many false positives, but these
can be ignored: `curl http://127.0.0.1:1985/api/v1/valgrind?check=added`
4. Perform load testing or test the suspected leaking functionality,
such as RTMP streaming: `ffmpeg -re -i doc/source.flv -c copy -f flv
rtmp://127.0.0.1/live/livestream`
5. Stop streaming and wait for SRS to clean up the Source memory,
approximately 30 seconds.
6. Perform incremental memory leak detection. The reported leaks will be
very accurate at this point: `curl
http://127.0.0.1:1985/api/v1/valgrind?check=added`

> Note: To avoid interference from the HTTP request itself on Valgrind,
SRS uses a separate coroutine to perform periodic checks. Therefore,
after accessing the API, you may need to wait a few seconds for the
detection to be triggered.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
2024-08-21 15:39:01 +08:00

250 lines
5.7 KiB
C++

//
// Copyright (c) 2013-2024 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_HTTP_API_HPP
#define SRS_APP_HTTP_API_HPP
#include <srs_core.hpp>
class ISrsHttpMessage;
class SrsHttpParser;
class SrsHttpHandler;
class SrsServer;
class SrsRtcServer;
class SrsJsonObject;
class SrsSdp;
class SrsRequest;
class ISrsHttpResponseWriter;
class SrsHttpConn;
#include <string>
#include <srs_app_st.hpp>
#include <srs_app_conn.hpp>
#include <srs_protocol_http_stack.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_http_conn.hpp>
extern srs_error_t srs_api_response(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string json);
extern srs_error_t srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, int code);
extern srs_error_t srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, srs_error_t code);
// For http root.
class SrsGoApiRoot : public ISrsHttpHandler
{
public:
SrsGoApiRoot();
virtual ~SrsGoApiRoot();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiApi : public ISrsHttpHandler
{
public:
SrsGoApiApi();
virtual ~SrsGoApiApi();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiV1 : public ISrsHttpHandler
{
public:
SrsGoApiV1();
virtual ~SrsGoApiV1();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiVersion : public ISrsHttpHandler
{
public:
SrsGoApiVersion();
virtual ~SrsGoApiVersion();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiSummaries : public ISrsHttpHandler
{
public:
SrsGoApiSummaries();
virtual ~SrsGoApiSummaries();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiRusages : public ISrsHttpHandler
{
public:
SrsGoApiRusages();
virtual ~SrsGoApiRusages();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiSelfProcStats : public ISrsHttpHandler
{
public:
SrsGoApiSelfProcStats();
virtual ~SrsGoApiSelfProcStats();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiSystemProcStats : public ISrsHttpHandler
{
public:
SrsGoApiSystemProcStats();
virtual ~SrsGoApiSystemProcStats();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiMemInfos : public ISrsHttpHandler
{
public:
SrsGoApiMemInfos();
virtual ~SrsGoApiMemInfos();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiAuthors : public ISrsHttpHandler
{
public:
SrsGoApiAuthors();
virtual ~SrsGoApiAuthors();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiFeatures : public ISrsHttpHandler
{
public:
SrsGoApiFeatures();
virtual ~SrsGoApiFeatures();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiRequests : public ISrsHttpHandler
{
public:
SrsGoApiRequests();
virtual ~SrsGoApiRequests();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiVhosts : public ISrsHttpHandler
{
public:
SrsGoApiVhosts();
virtual ~SrsGoApiVhosts();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiStreams : public ISrsHttpHandler
{
public:
SrsGoApiStreams();
virtual ~SrsGoApiStreams();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiClients : public ISrsHttpHandler
{
public:
SrsGoApiClients();
virtual ~SrsGoApiClients();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiRaw : public ISrsHttpHandler, public ISrsReloadHandler
{
private:
SrsServer* server;
private:
bool raw_api;
bool allow_reload;
bool allow_query;
bool allow_update;
public:
SrsGoApiRaw(SrsServer* svr);
virtual ~SrsGoApiRaw();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
// Interface ISrsReloadHandler
public:
virtual srs_error_t on_reload_http_api_raw_api();
};
class SrsGoApiClusters : public ISrsHttpHandler
{
public:
SrsGoApiClusters();
virtual ~SrsGoApiClusters();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiError : public ISrsHttpHandler
{
public:
SrsGoApiError();
virtual ~SrsGoApiError();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
#ifdef SRS_GPERF
class SrsGoApiTcmalloc : public ISrsHttpHandler
{
public:
SrsGoApiTcmalloc();
virtual ~SrsGoApiTcmalloc();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
#endif
#ifdef SRS_VALGRIND
class SrsGoApiValgrind : public ISrsHttpHandler, public ISrsCoroutineHandler
{
private:
SrsCoroutine* trd_;
std::string task_;
public:
SrsGoApiValgrind();
virtual ~SrsGoApiValgrind();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
// Interface ISrsCoroutineHandler
public:
virtual srs_error_t cycle();
};
#endif
class SrsGoApiMetrics : public ISrsHttpHandler
{
private:
bool enabled_;
std::string label_;
std::string tag_;
public:
SrsGoApiMetrics();
virtual ~SrsGoApiMetrics();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
#endif