mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Support macOS OSX
This commit is contained in:
parent
b3b76b0ca6
commit
c339542ce0
13 changed files with 312 additions and 51 deletions
|
@ -30,7 +30,9 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#ifndef SRS_AUTO_OSX
|
||||
#include <sys/inotify.h>
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
@ -478,6 +480,7 @@ srs_error_t SrsInotifyWorker::start()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
// Whether enable auto reload config.
|
||||
bool auto_reload = _srs_config->inotify_auto_reload();
|
||||
if (!auto_reload && _srs_in_docker && _srs_config->auto_reload_for_docker()) {
|
||||
|
@ -548,6 +551,7 @@ srs_error_t SrsInotifyWorker::start()
|
|||
if ((err = trd->start()) != srs_success) {
|
||||
return srs_error_wrap(err, "inotify");
|
||||
}
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -556,6 +560,7 @@ srs_error_t SrsInotifyWorker::cycle()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
string config_path = _srs_config->config();
|
||||
string config_file = srs_path_basename(config_path);
|
||||
string k8s_file = "..data";
|
||||
|
@ -595,6 +600,7 @@ srs_error_t SrsInotifyWorker::cycle()
|
|||
|
||||
srs_usleep(3000 * SRS_UTIME_MILLISECONDS);
|
||||
}
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -763,7 +769,7 @@ srs_error_t SrsServer::initialize_st()
|
|||
if ((err = srs_st_init()) != srs_success) {
|
||||
return srs_error_wrap(err, "initialize st failed");
|
||||
}
|
||||
|
||||
|
||||
// @remark, st alloc segment use mmap, which only support 32757 threads,
|
||||
// if need to support more, for instance, 100k threads, define the macro MALLOC_STACK.
|
||||
// TODO: FIXME: maybe can use "sysctl vm.max_map_count" to refine.
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
#include <sys/time.h>
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#ifdef SRS_AUTO_OSX
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
@ -326,6 +329,7 @@ SrsProcSystemStat* srs_get_system_proc_stat()
|
|||
|
||||
bool get_proc_system_stat(SrsProcSystemStat& r)
|
||||
{
|
||||
#ifndef SRS_AUTO_OSX
|
||||
FILE* f = fopen("/proc/stat", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open system cpu stat failed, ignore");
|
||||
|
@ -355,6 +359,7 @@ bool get_proc_system_stat(SrsProcSystemStat& r)
|
|||
}
|
||||
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
r.ok = true;
|
||||
|
||||
|
@ -363,6 +368,7 @@ bool get_proc_system_stat(SrsProcSystemStat& r)
|
|||
|
||||
bool get_proc_self_stat(SrsProcSelfStat& r)
|
||||
{
|
||||
#ifndef SRS_AUTO_OSX
|
||||
FILE* f = fopen("/proc/self/stat", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open self cpu stat failed, ignore");
|
||||
|
@ -389,6 +395,7 @@ bool get_proc_self_stat(SrsProcSelfStat& r)
|
|||
&r.guest_time, &r.cguest_time);
|
||||
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
r.ok = true;
|
||||
|
||||
|
@ -484,6 +491,7 @@ SrsDiskStat* srs_get_disk_stat()
|
|||
|
||||
bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
|
||||
{
|
||||
#ifndef SRS_AUTO_OSX
|
||||
FILE* f = fopen("/proc/vmstat", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open vmstat failed, ignore");
|
||||
|
@ -503,6 +511,7 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
|
|||
}
|
||||
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
r.ok = true;
|
||||
|
||||
|
@ -513,13 +522,14 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
|
|||
{
|
||||
r.ok = true;
|
||||
r.sample_time = srsu2ms(srs_get_system_time());
|
||||
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
// if disabled, ignore all devices.
|
||||
SrsConfDirective* conf = _srs_config->get_stats_disk_device();
|
||||
if (conf == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
FILE* f = fopen("/proc/diskstats", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open vmstat failed, ignore");
|
||||
|
@ -584,6 +594,7 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
|
|||
}
|
||||
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
r.ok = true;
|
||||
|
||||
|
@ -675,7 +686,8 @@ SrsMemInfo* srs_get_meminfo()
|
|||
void srs_update_meminfo()
|
||||
{
|
||||
SrsMemInfo& r = _srs_system_meminfo;
|
||||
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
FILE* f = fopen("/proc/meminfo", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open meminfo failed, ignore");
|
||||
|
@ -701,6 +713,7 @@ void srs_update_meminfo()
|
|||
}
|
||||
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
r.sample_time = srsu2ms(srs_get_system_time());
|
||||
r.MemActive = r.MemTotal - r.MemFree;
|
||||
|
@ -767,7 +780,8 @@ void srs_update_platform_info()
|
|||
SrsPlatformInfo& r = _srs_system_platform_info;
|
||||
|
||||
r.srs_startup_time = srsu2ms(srs_get_system_startup_time());
|
||||
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
if (true) {
|
||||
FILE* f = fopen("/proc/uptime", "r");
|
||||
if (f == NULL) {
|
||||
|
@ -796,7 +810,44 @@ void srs_update_platform_info()
|
|||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
#else
|
||||
// man 3 sysctl
|
||||
if (true) {
|
||||
struct timeval tv;
|
||||
size_t len = sizeof(timeval);
|
||||
|
||||
int mib[2];
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_BOOTTIME;
|
||||
if (sysctl(mib, 2, &tv, &len, NULL, 0) < 0) {
|
||||
srs_warn("sysctl boottime failed, ignore");
|
||||
return;
|
||||
}
|
||||
|
||||
time_t bsec = tv.tv_sec;
|
||||
time_t csec = ::time(NULL);
|
||||
r.os_uptime = difftime(csec, bsec);
|
||||
}
|
||||
|
||||
// man 3 sysctl
|
||||
if (true) {
|
||||
struct loadavg la;
|
||||
size_t len = sizeof(loadavg);
|
||||
|
||||
int mib[2];
|
||||
mib[0] = CTL_VM;
|
||||
mib[1] = VM_LOADAVG;
|
||||
if (sysctl(mib, 2, &la, &len, NULL, 0) < 0) {
|
||||
srs_warn("sysctl loadavg failed, ignore");
|
||||
return;
|
||||
}
|
||||
|
||||
r.load_one_minutes = (double)la.ldavg[0] / la.fscale;
|
||||
r.load_five_minutes = (double)la.ldavg[1] / la.fscale;
|
||||
r.load_fifteen_minutes = (double)la.ldavg[2] / la.fscale;
|
||||
}
|
||||
#endif
|
||||
|
||||
r.ok = true;
|
||||
}
|
||||
|
||||
|
@ -842,6 +893,7 @@ int srs_get_network_devices_count()
|
|||
|
||||
void srs_update_network_devices()
|
||||
{
|
||||
#ifndef SRS_AUTO_OSX
|
||||
if (true) {
|
||||
FILE* f = fopen("/proc/net/dev", "r");
|
||||
if (f == NULL) {
|
||||
|
@ -878,6 +930,7 @@ void srs_update_network_devices()
|
|||
|
||||
fclose(f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SrsNetworkRtmpServer::SrsNetworkRtmpServer()
|
||||
|
@ -924,7 +977,8 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
|
|||
int nb_tcp_total = 0;
|
||||
int nb_tcp_mem = 0;
|
||||
int nb_udp4 = 0;
|
||||
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
if (true) {
|
||||
FILE* f = fopen("/proc/net/sockstat", "r");
|
||||
if (f == NULL) {
|
||||
|
@ -954,9 +1008,20 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
|
|||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
#else
|
||||
// TODO: FIXME: impelments it.
|
||||
nb_socks = 0;
|
||||
nb_tcp4_hashed = 0;
|
||||
nb_tcp_orphans = 0;
|
||||
nb_tcp_tws = 0;
|
||||
nb_tcp_total = 0;
|
||||
nb_tcp_mem = 0;
|
||||
nb_udp4 = 0;
|
||||
#endif
|
||||
|
||||
int nb_tcp_estab = 0;
|
||||
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
if (true) {
|
||||
FILE* f = fopen("/proc/net/snmp", "r");
|
||||
if (f == NULL) {
|
||||
|
@ -986,6 +1051,7 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
|
|||
|
||||
fclose(f);
|
||||
}
|
||||
#endif
|
||||
|
||||
// @see: https://github.com/shemminger/iproute2/blob/master/misc/ss.c
|
||||
// TODO: FIXME: ignore the slabstat, @see: get_slabstat()
|
||||
|
|
|
@ -124,7 +124,9 @@ srs_utime_t srs_get_system_startup_time()
|
|||
}
|
||||
|
||||
// For utest to mock it.
|
||||
#ifndef SRS_AUTO_OSX
|
||||
_srs_gettimeofday_t _srs_gettimeofday = ::gettimeofday;
|
||||
#endif
|
||||
|
||||
srs_utime_t srs_update_system_time()
|
||||
{
|
||||
|
|
|
@ -166,7 +166,11 @@ extern int srs_chunk_header_c3(int perfer_cid, uint32_t timestamp, char* cache,
|
|||
|
||||
// For utest to mock it.
|
||||
#include <sys/time.h>
|
||||
typedef int (*_srs_gettimeofday_t)(struct timeval* tv, struct timezone* tz);
|
||||
#ifdef SRS_AUTO_OSX
|
||||
#define _srs_gettimeofday gettimeofday
|
||||
#else
|
||||
typedef int (*_srs_gettimeofday_t) (struct timeval* tv, struct timezone* tz);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -121,8 +121,8 @@ srs_error_t do_main(int argc, char** argv)
|
|||
// config already applied to log.
|
||||
srs_trace("%s, %s", RTMP_SIG_SRS_SERVER, RTMP_SIG_SRS_LICENSE);
|
||||
srs_trace("contributors: %s", SRS_AUTO_CONSTRIBUTORS);
|
||||
srs_trace("cwd=%s, work_dir=%s, build: %s, configure: %s, uname: %s",
|
||||
_srs_config->cwd().c_str(), cwd.c_str(), SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME);
|
||||
srs_trace("cwd=%s, work_dir=%s, build: %s, configure: %s, uname: %s, osx: %d",
|
||||
_srs_config->cwd().c_str(), cwd.c_str(), SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME, SRS_AUTO_OSX_BOOL);
|
||||
srs_trace("configure detail: " SRS_AUTO_CONFIGURE);
|
||||
#ifdef SRS_AUTO_EMBEDED_TOOL_CHAIN
|
||||
srs_trace("crossbuild tool chain: " SRS_AUTO_EMBEDED_TOOL_CHAIN);
|
||||
|
|
|
@ -46,7 +46,7 @@ int SrsThreadContext::generate_id()
|
|||
static int id = 0;
|
||||
|
||||
if (id == 0) {
|
||||
id = (100 + ((int)(int64_t)this)%1000);
|
||||
id = (100 + ((uint32_t)(int64_t)this)%1000);
|
||||
}
|
||||
|
||||
int gid = id++;
|
||||
|
|
|
@ -4208,6 +4208,7 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef SRS_AUTO_OSX
|
||||
extern _srs_gettimeofday_t _srs_gettimeofday;
|
||||
int mock_gettimeofday(struct timeval* /*tp*/, struct timezone* /*tzp*/) {
|
||||
return -1;
|
||||
|
@ -4238,6 +4239,7 @@ VOID TEST(KernelUtilityTest, CoverTimeSpecial)
|
|||
EXPECT_TRUE(-1 == srs_update_system_time());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int64_t _srs_system_time_startup_time;
|
||||
extern int64_t _srs_system_time_us_cache;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue