正在显示
8 个修改的文件
包含
701 行增加
和
696 行删除
| @@ -128,7 +128,7 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | @@ -128,7 +128,7 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | ||
| 128 | source_ep.c_str(), dest_ep.c_str(), ret); | 128 | source_ep.c_str(), dest_ep.c_str(), ret); |
| 129 | return ret; | 129 | return ret; |
| 130 | } | 130 | } |
| 131 | - srs_trace("start forward %s to %s, stream: %s/%s", | 131 | + srs_trace("start forward %s to %s, tcUrl=%s, stream=%s", |
| 132 | source_ep.c_str(), dest_ep.c_str(), tc_url.c_str(), | 132 | source_ep.c_str(), dest_ep.c_str(), tc_url.c_str(), |
| 133 | stream_name.c_str()); | 133 | stream_name.c_str()); |
| 134 | 134 |
| @@ -36,6 +36,7 @@ using namespace std; | @@ -36,6 +36,7 @@ using namespace std; | ||
| 36 | #include <srs_app_json.hpp> | 36 | #include <srs_app_json.hpp> |
| 37 | #include <srs_app_config.hpp> | 37 | #include <srs_app_config.hpp> |
| 38 | #include <srs_kernel_utility.hpp> | 38 | #include <srs_kernel_utility.hpp> |
| 39 | +#include <srs_app_utility.hpp> | ||
| 39 | 40 | ||
| 40 | SrsApiRoot::SrsApiRoot() | 41 | SrsApiRoot::SrsApiRoot() |
| 41 | { | 42 | { |
| @@ -45,6 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -45,6 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 45 | #include <srs_app_ingest.hpp> | 45 | #include <srs_app_ingest.hpp> |
| 46 | #endif | 46 | #endif |
| 47 | #include <srs_app_source.hpp> | 47 | #include <srs_app_source.hpp> |
| 48 | +#include <srs_app_utility.hpp> | ||
| 48 | 49 | ||
| 49 | #define SERVER_LISTEN_BACKLOG 512 | 50 | #define SERVER_LISTEN_BACKLOG 512 |
| 50 | 51 |
| @@ -23,8 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -23,8 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | 23 | ||
| 24 | #include <srs_app_utility.hpp> | 24 | #include <srs_app_utility.hpp> |
| 25 | 25 | ||
| 26 | +#include <unistd.h> | ||
| 27 | + | ||
| 26 | #include <srs_kernel_log.hpp> | 28 | #include <srs_kernel_log.hpp> |
| 27 | #include <srs_app_config.hpp> | 29 | #include <srs_app_config.hpp> |
| 30 | +#include <srs_kernel_utility.hpp> | ||
| 28 | 31 | ||
| 29 | int srs_get_log_level(std::string level) | 32 | int srs_get_log_level(std::string level) |
| 30 | { | 33 | { |
| @@ -42,3 +45,393 @@ int srs_get_log_level(std::string level) | @@ -42,3 +45,393 @@ int srs_get_log_level(std::string level) | ||
| 42 | return SrsLogLevel::Trace; | 45 | return SrsLogLevel::Trace; |
| 43 | } | 46 | } |
| 44 | } | 47 | } |
| 48 | + | ||
| 49 | +static SrsRusage _srs_system_rusage; | ||
| 50 | + | ||
| 51 | +SrsRusage::SrsRusage() | ||
| 52 | +{ | ||
| 53 | + ok = false; | ||
| 54 | + sample_time = 0; | ||
| 55 | + memset(&r, 0, sizeof(rusage)); | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +SrsRusage* srs_get_system_rusage() | ||
| 59 | +{ | ||
| 60 | + return &_srs_system_rusage; | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +void srs_update_system_rusage() | ||
| 64 | +{ | ||
| 65 | + if (getrusage(RUSAGE_SELF, &_srs_system_rusage.r) < 0) { | ||
| 66 | + srs_warn("getrusage failed, ignore"); | ||
| 67 | + return; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + srs_update_system_time_ms(); | ||
| 71 | + _srs_system_rusage.sample_time = srs_get_system_time_ms(); | ||
| 72 | + | ||
| 73 | + _srs_system_rusage.ok = true; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +static SrsProcSelfStat _srs_system_cpu_self_stat; | ||
| 77 | +static SrsProcSystemStat _srs_system_cpu_system_stat; | ||
| 78 | + | ||
| 79 | +SrsProcSelfStat::SrsProcSelfStat() | ||
| 80 | +{ | ||
| 81 | + ok = false; | ||
| 82 | + sample_time = 0; | ||
| 83 | + percent = 0; | ||
| 84 | + | ||
| 85 | + pid = 0; | ||
| 86 | + memset(comm, 0, sizeof(comm)); | ||
| 87 | + state = 0; | ||
| 88 | + ppid = 0; | ||
| 89 | + pgrp = 0; | ||
| 90 | + session = 0; | ||
| 91 | + tty_nr = 0; | ||
| 92 | + tpgid = 0; | ||
| 93 | + flags = 0; | ||
| 94 | + minflt = 0; | ||
| 95 | + cminflt = 0; | ||
| 96 | + majflt = 0; | ||
| 97 | + cmajflt = 0; | ||
| 98 | + utime = 0; | ||
| 99 | + stime = 0; | ||
| 100 | + cutime = 0; | ||
| 101 | + cstime = 0; | ||
| 102 | + priority = 0; | ||
| 103 | + nice = 0; | ||
| 104 | + num_threads = 0; | ||
| 105 | + itrealvalue = 0; | ||
| 106 | + starttime = 0; | ||
| 107 | + vsize = 0; | ||
| 108 | + rss = 0; | ||
| 109 | + rsslim = 0; | ||
| 110 | + startcode = 0; | ||
| 111 | + endcode = 0; | ||
| 112 | + startstack = 0; | ||
| 113 | + kstkesp = 0; | ||
| 114 | + kstkeip = 0; | ||
| 115 | + signal = 0; | ||
| 116 | + blocked = 0; | ||
| 117 | + sigignore = 0; | ||
| 118 | + sigcatch = 0; | ||
| 119 | + wchan = 0; | ||
| 120 | + nswap = 0; | ||
| 121 | + cnswap = 0; | ||
| 122 | + exit_signal = 0; | ||
| 123 | + processor = 0; | ||
| 124 | + rt_priority = 0; | ||
| 125 | + policy = 0; | ||
| 126 | + delayacct_blkio_ticks = 0; | ||
| 127 | + guest_time = 0; | ||
| 128 | + cguest_time = 0; | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +SrsProcSystemStat::SrsProcSystemStat() | ||
| 132 | +{ | ||
| 133 | + ok = false; | ||
| 134 | + sample_time = 0; | ||
| 135 | + percent = 0; | ||
| 136 | + memset(label, 0, sizeof(label)); | ||
| 137 | + user = 0; | ||
| 138 | + nice = 0; | ||
| 139 | + sys = 0; | ||
| 140 | + idle = 0; | ||
| 141 | + iowait = 0; | ||
| 142 | + irq = 0; | ||
| 143 | + softirq = 0; | ||
| 144 | + steal = 0; | ||
| 145 | + guest = 0; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +SrsProcSelfStat* srs_get_self_proc_stat() | ||
| 149 | +{ | ||
| 150 | + return &_srs_system_cpu_self_stat; | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +SrsProcSystemStat* srs_get_system_proc_stat() | ||
| 154 | +{ | ||
| 155 | + return &_srs_system_cpu_system_stat; | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +bool get_proc_system_stat(SrsProcSystemStat& r) | ||
| 159 | +{ | ||
| 160 | + FILE* f = fopen("/proc/stat", "r"); | ||
| 161 | + if (f == NULL) { | ||
| 162 | + srs_warn("open system cpu stat failed, ignore"); | ||
| 163 | + return false; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + for (;;) { | ||
| 167 | + int ret = fscanf(f, "%4s %lu %lu %lu %lu %lu " | ||
| 168 | + "%lu %lu %lu %lu\n", | ||
| 169 | + r.label, &r.user, &r.nice, &r.sys, &r.idle, &r.iowait, | ||
| 170 | + &r.irq, &r.softirq, &r.steal, &r.guest); | ||
| 171 | + r.ok = false; | ||
| 172 | + | ||
| 173 | + if (ret == EOF) { | ||
| 174 | + break; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + if (strcmp("cpu", r.label) == 0) { | ||
| 178 | + r.ok = true; | ||
| 179 | + break; | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + fclose(f); | ||
| 184 | + | ||
| 185 | + return r.ok; | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +bool get_proc_self_stat(SrsProcSelfStat& r) | ||
| 189 | +{ | ||
| 190 | + FILE* f = fopen("/proc/self/stat", "r"); | ||
| 191 | + if (f == NULL) { | ||
| 192 | + srs_warn("open self cpu stat failed, ignore"); | ||
| 193 | + return false; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + int ret = fscanf(f, "%d %32s %c %d %d %d %d " | ||
| 197 | + "%d %u %lu %lu %lu %lu " | ||
| 198 | + "%lu %lu %ld %ld %ld %ld " | ||
| 199 | + "%ld %ld %llu %lu %ld " | ||
| 200 | + "%lu %lu %lu %lu %lu " | ||
| 201 | + "%lu %lu %lu %lu %lu " | ||
| 202 | + "%lu %lu %lu %d %d " | ||
| 203 | + "%u %u %llu " | ||
| 204 | + "%lu %ld", | ||
| 205 | + &r.pid, r.comm, &r.state, &r.ppid, &r.pgrp, &r.session, &r.tty_nr, | ||
| 206 | + &r.tpgid, &r.flags, &r.minflt, &r.cminflt, &r.majflt, &r.cmajflt, | ||
| 207 | + &r.utime, &r.stime, &r.cutime, &r.cstime, &r.priority, &r.nice, | ||
| 208 | + &r.num_threads, &r.itrealvalue, &r.starttime, &r.vsize, &r.rss, | ||
| 209 | + &r.rsslim, &r.startcode, &r.endcode, &r.startstack, &r.kstkesp, | ||
| 210 | + &r.kstkeip, &r.signal, &r.blocked, &r.sigignore, &r.sigcatch, | ||
| 211 | + &r.wchan, &r.nswap, &r.cnswap, &r.exit_signal, &r.processor, | ||
| 212 | + &r.rt_priority, &r.policy, &r.delayacct_blkio_ticks, | ||
| 213 | + &r.guest_time, &r.cguest_time); | ||
| 214 | + | ||
| 215 | + fclose(f); | ||
| 216 | + | ||
| 217 | + if (ret >= 0) { | ||
| 218 | + r.ok = true; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + return r.ok; | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | +void srs_update_proc_stat() | ||
| 225 | +{ | ||
| 226 | + srs_update_system_time_ms(); | ||
| 227 | + | ||
| 228 | + // system cpu stat | ||
| 229 | + if (true) { | ||
| 230 | + SrsProcSystemStat r; | ||
| 231 | + if (!get_proc_system_stat(r)) { | ||
| 232 | + return; | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + r.sample_time = srs_get_system_time_ms(); | ||
| 236 | + | ||
| 237 | + // calc usage in percent | ||
| 238 | + SrsProcSystemStat& o = _srs_system_cpu_system_stat; | ||
| 239 | + | ||
| 240 | + // @see: http://blog.csdn.net/nineday/article/details/1928847 | ||
| 241 | + int64_t total = (r.user + r.nice + r.sys + r.idle + r.iowait + r.irq + r.softirq + r.steal + r.guest) | ||
| 242 | + - (o.user + o.nice + o.sys + o.idle + o.iowait + o.irq + o.softirq + o.steal + o.guest); | ||
| 243 | + int64_t idle = r.idle - o.idle; | ||
| 244 | + if (total > 0) { | ||
| 245 | + r.percent = (float)(1 - idle / (double)total); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + // upate cache. | ||
| 249 | + _srs_system_cpu_system_stat = r; | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + // self cpu stat | ||
| 253 | + if (true) { | ||
| 254 | + SrsProcSelfStat r; | ||
| 255 | + if (!get_proc_self_stat(r)) { | ||
| 256 | + return; | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + srs_update_system_time_ms(); | ||
| 260 | + r.sample_time = srs_get_system_time_ms(); | ||
| 261 | + | ||
| 262 | + // calc usage in percent | ||
| 263 | + SrsProcSelfStat& o = _srs_system_cpu_self_stat; | ||
| 264 | + | ||
| 265 | + // @see: http://stackoverflow.com/questions/16011677/calculating-cpu-usage-using-proc-files | ||
| 266 | + int64_t total = r.sample_time - o.sample_time; | ||
| 267 | + int64_t usage = (r.utime + r.stime) - (o.utime + o.stime); | ||
| 268 | + if (total > 0) { | ||
| 269 | + r.percent = (float)(usage * 1000 / (double)total / 100); | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + // upate cache. | ||
| 273 | + _srs_system_cpu_self_stat = r; | ||
| 274 | + } | ||
| 275 | +} | ||
| 276 | + | ||
| 277 | +SrsMemInfo::SrsMemInfo() | ||
| 278 | +{ | ||
| 279 | + ok = false; | ||
| 280 | + sample_time = 0; | ||
| 281 | + | ||
| 282 | + percent_ram = 0; | ||
| 283 | + percent_swap = 0; | ||
| 284 | + | ||
| 285 | + MemActive = 0; | ||
| 286 | + RealInUse = 0; | ||
| 287 | + NotInUse = 0; | ||
| 288 | + MemTotal = 0; | ||
| 289 | + MemFree = 0; | ||
| 290 | + Buffers = 0; | ||
| 291 | + Cached = 0; | ||
| 292 | + SwapTotal = 0; | ||
| 293 | + SwapFree = 0; | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | +static SrsMemInfo _srs_system_meminfo; | ||
| 297 | + | ||
| 298 | +SrsMemInfo* srs_get_meminfo() | ||
| 299 | +{ | ||
| 300 | + return &_srs_system_meminfo; | ||
| 301 | +} | ||
| 302 | + | ||
| 303 | +void srs_update_meminfo() | ||
| 304 | +{ | ||
| 305 | + FILE* f = fopen("/proc/meminfo", "r"); | ||
| 306 | + if (f == NULL) { | ||
| 307 | + srs_warn("open meminfo failed, ignore"); | ||
| 308 | + return; | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + SrsMemInfo& r = _srs_system_meminfo; | ||
| 312 | + r.ok = false; | ||
| 313 | + | ||
| 314 | + for (;;) { | ||
| 315 | + static char label[64]; | ||
| 316 | + static unsigned long value; | ||
| 317 | + static char postfix[64]; | ||
| 318 | + int ret = fscanf(f, "%64s %lu %64s\n", label, &value, postfix); | ||
| 319 | + | ||
| 320 | + if (ret == EOF) { | ||
| 321 | + break; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + if (strcmp("MemTotal:", label) == 0) { | ||
| 325 | + r.MemTotal = value; | ||
| 326 | + } else if (strcmp("MemFree:", label) == 0) { | ||
| 327 | + r.MemFree = value; | ||
| 328 | + } else if (strcmp("Buffers:", label) == 0) { | ||
| 329 | + r.Buffers = value; | ||
| 330 | + } else if (strcmp("Cached:", label) == 0) { | ||
| 331 | + r.Cached = value; | ||
| 332 | + } else if (strcmp("SwapTotal:", label) == 0) { | ||
| 333 | + r.SwapTotal = value; | ||
| 334 | + } else if (strcmp("SwapFree:", label) == 0) { | ||
| 335 | + r.SwapFree = value; | ||
| 336 | + } | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + fclose(f); | ||
| 340 | + | ||
| 341 | + r.sample_time = srs_get_system_time_ms(); | ||
| 342 | + r.MemActive = r.MemTotal - r.MemFree; | ||
| 343 | + r.RealInUse = r.MemActive - r.Buffers - r.Cached; | ||
| 344 | + r.NotInUse = r.MemTotal - r.RealInUse; | ||
| 345 | + | ||
| 346 | + r.ok = true; | ||
| 347 | + if (r.MemTotal > 0) { | ||
| 348 | + r.percent_ram = (float)(r.RealInUse / (double)r.MemTotal); | ||
| 349 | + } | ||
| 350 | + if (r.SwapTotal > 0) { | ||
| 351 | + r.percent_swap = (float)((r.SwapTotal - r.SwapFree) / (double)r.SwapTotal); | ||
| 352 | + } | ||
| 353 | +} | ||
| 354 | + | ||
| 355 | +SrsCpuInfo::SrsCpuInfo() | ||
| 356 | +{ | ||
| 357 | + ok = false; | ||
| 358 | + | ||
| 359 | + nb_processors = 0; | ||
| 360 | + nb_processors_online = 0; | ||
| 361 | +} | ||
| 362 | + | ||
| 363 | +SrsCpuInfo* srs_get_cpuinfo() | ||
| 364 | +{ | ||
| 365 | + static SrsCpuInfo* cpu = NULL; | ||
| 366 | + if (cpu != NULL) { | ||
| 367 | + return cpu; | ||
| 368 | + } | ||
| 369 | + | ||
| 370 | + // initialize cpu info. | ||
| 371 | + cpu = new SrsCpuInfo(); | ||
| 372 | + cpu->ok = true; | ||
| 373 | + cpu->nb_processors = sysconf(_SC_NPROCESSORS_CONF); | ||
| 374 | + cpu->nb_processors_online = sysconf(_SC_NPROCESSORS_ONLN); | ||
| 375 | + | ||
| 376 | + return cpu; | ||
| 377 | +} | ||
| 378 | + | ||
| 379 | +SrsPlatformInfo::SrsPlatformInfo() | ||
| 380 | +{ | ||
| 381 | + ok = false; | ||
| 382 | + | ||
| 383 | + srs_startup_time = srs_get_system_time_ms(); | ||
| 384 | + | ||
| 385 | + os_uptime = 0; | ||
| 386 | + os_ilde_time = 0; | ||
| 387 | + | ||
| 388 | + load_one_minutes = 0; | ||
| 389 | + load_five_minutes = 0; | ||
| 390 | + load_fifteen_minutes = 0; | ||
| 391 | +} | ||
| 392 | + | ||
| 393 | +static SrsPlatformInfo _srs_system_platform_info; | ||
| 394 | + | ||
| 395 | +SrsPlatformInfo* srs_get_platform_info() | ||
| 396 | +{ | ||
| 397 | + return &_srs_system_platform_info; | ||
| 398 | +} | ||
| 399 | + | ||
| 400 | +void srs_update_platform_info() | ||
| 401 | +{ | ||
| 402 | + SrsPlatformInfo& r = _srs_system_platform_info; | ||
| 403 | + r.ok = true; | ||
| 404 | + | ||
| 405 | + if (true) { | ||
| 406 | + FILE* f = fopen("/proc/uptime", "r"); | ||
| 407 | + if (f == NULL) { | ||
| 408 | + srs_warn("open uptime failed, ignore"); | ||
| 409 | + return; | ||
| 410 | + } | ||
| 411 | + | ||
| 412 | + int ret = fscanf(f, "%lf %lf\n", &r.os_uptime, &r.os_ilde_time); | ||
| 413 | + | ||
| 414 | + fclose(f); | ||
| 415 | + | ||
| 416 | + if (ret < 0) { | ||
| 417 | + r.ok = false; | ||
| 418 | + } | ||
| 419 | + } | ||
| 420 | + | ||
| 421 | + if (true) { | ||
| 422 | + FILE* f = fopen("/proc/loadavg", "r"); | ||
| 423 | + if (f == NULL) { | ||
| 424 | + srs_warn("open loadavg failed, ignore"); | ||
| 425 | + return; | ||
| 426 | + } | ||
| 427 | + | ||
| 428 | + int ret = fscanf(f, "%lf %lf %lf\n", | ||
| 429 | + &r.load_one_minutes, &r.load_five_minutes, &r.load_fifteen_minutes); | ||
| 430 | + | ||
| 431 | + fclose(f); | ||
| 432 | + | ||
| 433 | + if (ret < 0) { | ||
| 434 | + r.ok = false; | ||
| 435 | + } | ||
| 436 | + } | ||
| 437 | +} |
| @@ -30,10 +30,314 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,10 +30,314 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | 30 | ||
| 31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
| 32 | 32 | ||
| 33 | +#include <sys/resource.h> | ||
| 34 | + | ||
| 33 | /** | 35 | /** |
| 34 | * convert level in string to log level in int. | 36 | * convert level in string to log level in int. |
| 35 | * @return the log level defined in SrsLogLevel. | 37 | * @return the log level defined in SrsLogLevel. |
| 36 | */ | 38 | */ |
| 37 | extern int srs_get_log_level(std::string level); | 39 | extern int srs_get_log_level(std::string level); |
| 38 | 40 | ||
| 41 | +// @see: man getrusage | ||
| 42 | +struct SrsRusage | ||
| 43 | +{ | ||
| 44 | + // whether the data is ok. | ||
| 45 | + bool ok; | ||
| 46 | + // the time in ms when sample. | ||
| 47 | + int64_t sample_time; | ||
| 48 | + | ||
| 49 | + rusage r; | ||
| 50 | + | ||
| 51 | + SrsRusage(); | ||
| 52 | +}; | ||
| 53 | + | ||
| 54 | +// get system rusage, use cache to avoid performance problem. | ||
| 55 | +extern SrsRusage* srs_get_system_rusage(); | ||
| 56 | +// the deamon st-thread will update it. | ||
| 57 | +extern void srs_update_system_rusage(); | ||
| 58 | + | ||
| 59 | +// @see: man 5 proc, /proc/[pid]/stat | ||
| 60 | +struct SrsProcSelfStat | ||
| 61 | +{ | ||
| 62 | + // whether the data is ok. | ||
| 63 | + bool ok; | ||
| 64 | + // the time in ms when sample. | ||
| 65 | + int64_t sample_time; | ||
| 66 | + // the percent of usage. 0.153 is 15.3%. | ||
| 67 | + float percent; | ||
| 68 | + | ||
| 69 | + // pid %d The process ID. | ||
| 70 | + int pid; | ||
| 71 | + // comm %s The filename of the executable, in parentheses. This is visible whether or not the executable is | ||
| 72 | + // swapped out. | ||
| 73 | + char comm[32]; | ||
| 74 | + // state %c One character from the string "RSDZTW" where R is running, S is sleeping in an interruptible wait, D | ||
| 75 | + // is waiting in uninterruptible disk sleep, Z is zombie, T is traced or stopped (on a signal), and W is | ||
| 76 | + // paging. | ||
| 77 | + char state; | ||
| 78 | + // ppid %d The PID of the parent. | ||
| 79 | + int ppid; | ||
| 80 | + // pgrp %d The process group ID of the process. | ||
| 81 | + int pgrp; | ||
| 82 | + // session %d The session ID of the process. | ||
| 83 | + int session; | ||
| 84 | + // tty_nr %d The controlling terminal of the process. (The minor device number is contained in the combination of | ||
| 85 | + // bits 31 to 20 and 7 to 0; the major device number is in bits 15 t0 8.) | ||
| 86 | + int tty_nr; | ||
| 87 | + // tpgid %d The ID of the foreground process group of the controlling terminal of the process. | ||
| 88 | + int tpgid; | ||
| 89 | + // flags %u (%lu before Linux 2.6.22) | ||
| 90 | + // The kernel flags word of the process. For bit meanings, see the PF_* defines in <linux/sched.h>. | ||
| 91 | + // Details depend on the kernel version. | ||
| 92 | + unsigned int flags; | ||
| 93 | + // minflt %lu The number of minor faults the process has made which have not required loading a memory page from | ||
| 94 | + // disk. | ||
| 95 | + unsigned long minflt; | ||
| 96 | + // cminflt %lu The number of minor faults that the process’s waited-for children have made. | ||
| 97 | + unsigned long cminflt; | ||
| 98 | + // majflt %lu The number of major faults the process has made which have required loading a memory page from disk. | ||
| 99 | + unsigned long majflt; | ||
| 100 | + // cmajflt %lu The number of major faults that the process’s waited-for children have made. | ||
| 101 | + unsigned long cmajflt; | ||
| 102 | + // utime %lu Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by | ||
| 103 | + // sysconf(_SC_CLK_TCK). This includes guest time, guest_time (time spent running a virtual CPU, see | ||
| 104 | + // below), so that applications that are not aware of the guest time field do not lose that time from | ||
| 105 | + // their calculations. | ||
| 106 | + unsigned long utime; | ||
| 107 | + // stime %lu Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by | ||
| 108 | + // sysconf(_SC_CLK_TCK). | ||
| 109 | + unsigned long stime; | ||
| 110 | + // cutime %ld Amount of time that this process’s waited-for children have been scheduled in user mode, measured in | ||
| 111 | + // clock ticks (divide by sysconf(_SC_CLK_TCK). (See also times(2).) This includes guest time, | ||
| 112 | + // cguest_time (time spent running a virtual CPU, see below). | ||
| 113 | + long cutime; | ||
| 114 | + // cstime %ld Amount of time that this process’s waited-for children have been scheduled in kernel mode, measured in | ||
| 115 | + // clock ticks (divide by sysconf(_SC_CLK_TCK). | ||
| 116 | + long cstime; | ||
| 117 | + // priority %ld | ||
| 118 | + // (Explanation for Linux 2.6) For processes running a real-time scheduling policy (policy below; see | ||
| 119 | + // sched_setscheduler(2)), this is the negated scheduling priority, minus one; that is, a number in the | ||
| 120 | + // range -2 to -100, corresponding to real-time priorities 1 to 99. For processes running under a non- | ||
| 121 | + // real-time scheduling policy, this is the raw nice value (setpriority(2)) as represented in the kernel. | ||
| 122 | + // The kernel stores nice values as numbers in the range 0 (high) to 39 (low), corresponding to the user- | ||
| 123 | + // visible nice range of -20 to 19. | ||
| 124 | + // | ||
| 125 | + // Before Linux 2.6, this was a scaled value based on the scheduler weighting given to this process. | ||
| 126 | + long priority; | ||
| 127 | + // nice %ld The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority). | ||
| 128 | + long nice; | ||
| 129 | + // num_threads %ld | ||
| 130 | + // Number of threads in this process (since Linux 2.6). Before kernel 2.6, this field was hard coded to | ||
| 131 | + // 0 as a placeholder for an earlier removed field. | ||
| 132 | + long num_threads; | ||
| 133 | + // itrealvalue %ld | ||
| 134 | + // The time in jiffies before the next SIGALRM is sent to the process due to an interval timer. Since | ||
| 135 | + // kernel 2.6.17, this field is no longer maintained, and is hard coded as 0. | ||
| 136 | + long itrealvalue; | ||
| 137 | + // starttime %llu (was %lu before Linux 2.6) | ||
| 138 | + // The time in jiffies the process started after system boot. | ||
| 139 | + long long starttime; | ||
| 140 | + // vsize %lu Virtual memory size in bytes. | ||
| 141 | + unsigned long vsize; | ||
| 142 | + // rss %ld Resident Set Size: number of pages the process has in real memory. This is just the pages which count | ||
| 143 | + // towards text, data, or stack space. This does not include pages which have not been demand-loaded in, | ||
| 144 | + // or which are swapped out. | ||
| 145 | + long rss; | ||
| 146 | + // rsslim %lu Current soft limit in bytes on the rss of the process; see the description of RLIMIT_RSS in getprior- | ||
| 147 | + // ity(2). | ||
| 148 | + unsigned long rsslim; | ||
| 149 | + // startcode %lu | ||
| 150 | + // The address above which program text can run. | ||
| 151 | + unsigned long startcode; | ||
| 152 | + // endcode %lu The address below which program text can run. | ||
| 153 | + unsigned long endcode; | ||
| 154 | + // startstack %lu | ||
| 155 | + // The address of the start (i.e., bottom) of the stack. | ||
| 156 | + unsigned long startstack; | ||
| 157 | + // kstkesp %lu The current value of ESP (stack pointer), as found in the kernel stack page for the process. | ||
| 158 | + unsigned long kstkesp; | ||
| 159 | + // kstkeip %lu The current EIP (instruction pointer). | ||
| 160 | + unsigned long kstkeip; | ||
| 161 | + // signal %lu The bitmap of pending signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 162 | + // information on real-time signals; use /proc/[pid]/status instead. | ||
| 163 | + unsigned long signal; | ||
| 164 | + // blocked %lu The bitmap of blocked signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 165 | + // information on real-time signals; use /proc/[pid]/status instead. | ||
| 166 | + unsigned long blocked; | ||
| 167 | + // sigignore %lu | ||
| 168 | + // The bitmap of ignored signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 169 | + // information on real-time signals; use /proc/[pid]/status instead. | ||
| 170 | + unsigned long sigignore; | ||
| 171 | + // sigcatch %lu | ||
| 172 | + // The bitmap of caught signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 173 | + // information on real-time signals; use /proc/[pid]/status instead. | ||
| 174 | + unsigned long sigcatch; | ||
| 175 | + // wchan %lu This is the "channel" in which the process is waiting. It is the address of a system call, and can be | ||
| 176 | + // looked up in a namelist if you need a textual name. (If you have an up-to-date /etc/psdatabase, then | ||
| 177 | + // try ps -l to see the WCHAN field in action.) | ||
| 178 | + unsigned long wchan; | ||
| 179 | + // nswap %lu Number of pages swapped (not maintained). | ||
| 180 | + unsigned long nswap; | ||
| 181 | + // cnswap %lu Cumulative nswap for child processes (not maintained). | ||
| 182 | + unsigned long cnswap; | ||
| 183 | + // exit_signal %d (since Linux 2.1.22) | ||
| 184 | + // Signal to be sent to parent when we die. | ||
| 185 | + int exit_signal; | ||
| 186 | + // processor %d (since Linux 2.2.8) | ||
| 187 | + // CPU number last executed on. | ||
| 188 | + int processor; | ||
| 189 | + // rt_priority %u (since Linux 2.5.19; was %lu before Linux 2.6.22) | ||
| 190 | + // Real-time scheduling priority, a number in the range 1 to 99 for processes scheduled under a real-time | ||
| 191 | + // policy, or 0, for non-real-time processes (see sched_setscheduler(2)). | ||
| 192 | + unsigned int rt_priority; | ||
| 193 | + // policy %u (since Linux 2.5.19; was %lu before Linux 2.6.22) | ||
| 194 | + // Scheduling policy (see sched_setscheduler(2)). Decode using the SCHED_* constants in linux/sched.h. | ||
| 195 | + unsigned int policy; | ||
| 196 | + // delayacct_blkio_ticks %llu (since Linux 2.6.18) | ||
| 197 | + // Aggregated block I/O delays, measured in clock ticks (centiseconds). | ||
| 198 | + unsigned long long delayacct_blkio_ticks; | ||
| 199 | + // guest_time %lu (since Linux 2.6.24) | ||
| 200 | + // Guest time of the process (time spent running a virtual CPU for a guest operating system), measured in | ||
| 201 | + // clock ticks (divide by sysconf(_SC_CLK_TCK). | ||
| 202 | + unsigned long guest_time; | ||
| 203 | + // cguest_time %ld (since Linux 2.6.24) | ||
| 204 | + // Guest time of the process’s children, measured in clock ticks (divide by sysconf(_SC_CLK_TCK). | ||
| 205 | + long cguest_time; | ||
| 206 | + | ||
| 207 | + SrsProcSelfStat(); | ||
| 208 | +}; | ||
| 209 | + | ||
| 210 | +// @see: man 5 proc, /proc/stat | ||
| 211 | +struct SrsProcSystemStat | ||
| 212 | +{ | ||
| 213 | + // whether the data is ok. | ||
| 214 | + bool ok; | ||
| 215 | + // the time in ms when sample. | ||
| 216 | + int64_t sample_time; | ||
| 217 | + // the percent of usage. 0.153 is 15.3%. | ||
| 218 | + float percent; | ||
| 219 | + | ||
| 220 | + // always be cpu | ||
| 221 | + char label[32]; | ||
| 222 | + | ||
| 223 | + //The amount of time, measured in units of USER_HZ (1/100ths of a second on most architectures, use | ||
| 224 | + // sysconf(_SC_CLK_TCK) to obtain the right value) | ||
| 225 | + // | ||
| 226 | + // the system spent in user mode, | ||
| 227 | + unsigned long user; | ||
| 228 | + // user mode with low priority (nice), | ||
| 229 | + unsigned long nice; | ||
| 230 | + // system mode, | ||
| 231 | + unsigned long sys; | ||
| 232 | + // and the idle task, respectively. | ||
| 233 | + unsigned long idle; | ||
| 234 | + | ||
| 235 | + // In Linux 2.6 this line includes three additional columns: | ||
| 236 | + // | ||
| 237 | + // iowait - time waiting for I/O to complete (since 2.5.41); | ||
| 238 | + unsigned long iowait; | ||
| 239 | + // irq - time servicing interrupts (since 2.6.0-test4); | ||
| 240 | + unsigned long irq; | ||
| 241 | + // softirq - time servicing softirqs (since 2.6.0-test4). | ||
| 242 | + unsigned long softirq; | ||
| 243 | + | ||
| 244 | + // Since Linux 2.6.11, there is an eighth column, | ||
| 245 | + // steal - stolen time, which is the time spent in other oper- | ||
| 246 | + // ating systems when running in a virtualized environment | ||
| 247 | + unsigned long steal; | ||
| 248 | + | ||
| 249 | + // Since Linux 2.6.24, there is a ninth column, | ||
| 250 | + // guest, which is the time spent running a virtual CPU for guest | ||
| 251 | + // operating systems under the control of the Linux kernel. | ||
| 252 | + unsigned long guest; | ||
| 253 | + | ||
| 254 | + SrsProcSystemStat(); | ||
| 255 | +}; | ||
| 256 | + | ||
| 257 | +// get system cpu stat, use cache to avoid performance problem. | ||
| 258 | +extern SrsProcSelfStat* srs_get_self_proc_stat(); | ||
| 259 | +// get system cpu stat, use cache to avoid performance problem. | ||
| 260 | +extern SrsProcSystemStat* srs_get_system_proc_stat(); | ||
| 261 | +// the deamon st-thread will update it. | ||
| 262 | +extern void srs_update_proc_stat(); | ||
| 263 | + | ||
| 264 | +// @see: cat /proc/meminfo | ||
| 265 | +struct SrsMemInfo | ||
| 266 | +{ | ||
| 267 | + // whether the data is ok. | ||
| 268 | + bool ok; | ||
| 269 | + // the time in ms when sample. | ||
| 270 | + int64_t sample_time; | ||
| 271 | + // the percent of usage. 0.153 is 15.3%. | ||
| 272 | + float percent_ram; | ||
| 273 | + float percent_swap; | ||
| 274 | + | ||
| 275 | + // MemActive = MemTotal - MemFree | ||
| 276 | + int64_t MemActive; | ||
| 277 | + // RealInUse = MemActive - Buffers - Cached | ||
| 278 | + int64_t RealInUse; | ||
| 279 | + // NotInUse = MemTotal - RealInUse | ||
| 280 | + // = MemTotal - MemActive + Buffers + Cached | ||
| 281 | + // = MemTotal - MemTotal + MemFree + Buffers + Cached | ||
| 282 | + // = MemFree + Buffers + Cached | ||
| 283 | + int64_t NotInUse; | ||
| 284 | + | ||
| 285 | + int64_t MemTotal; | ||
| 286 | + int64_t MemFree; | ||
| 287 | + int64_t Buffers; | ||
| 288 | + int64_t Cached; | ||
| 289 | + int64_t SwapTotal; | ||
| 290 | + int64_t SwapFree; | ||
| 291 | + | ||
| 292 | + SrsMemInfo(); | ||
| 293 | +}; | ||
| 294 | + | ||
| 295 | +// get system meminfo, use cache to avoid performance problem. | ||
| 296 | +extern SrsMemInfo* srs_get_meminfo(); | ||
| 297 | +// the deamon st-thread will update it. | ||
| 298 | +extern void srs_update_meminfo(); | ||
| 299 | + | ||
| 300 | +// @see: cat /proc/cpuinfo | ||
| 301 | +struct SrsCpuInfo | ||
| 302 | +{ | ||
| 303 | + // whether the data is ok. | ||
| 304 | + bool ok; | ||
| 305 | + | ||
| 306 | + // The number of processors configured. | ||
| 307 | + int nb_processors; | ||
| 308 | + // The number of processors currently online (available). | ||
| 309 | + int nb_processors_online; | ||
| 310 | + | ||
| 311 | + SrsCpuInfo(); | ||
| 312 | +}; | ||
| 313 | + | ||
| 314 | +// get system cpu info, use cache to avoid performance problem. | ||
| 315 | +extern SrsCpuInfo* srs_get_cpuinfo(); | ||
| 316 | + | ||
| 317 | +// platform(os, srs) summary | ||
| 318 | +struct SrsPlatformInfo | ||
| 319 | +{ | ||
| 320 | + // whether the data is ok. | ||
| 321 | + bool ok; | ||
| 322 | + | ||
| 323 | + // srs startup time, in ms. | ||
| 324 | + int64_t srs_startup_time; | ||
| 325 | + | ||
| 326 | + // @see: cat /proc/uptime | ||
| 327 | + double os_uptime; | ||
| 328 | + double os_ilde_time; | ||
| 329 | + | ||
| 330 | + // @see: cat /proc/loadavg | ||
| 331 | + double load_one_minutes; | ||
| 332 | + double load_five_minutes; | ||
| 333 | + double load_fifteen_minutes; | ||
| 334 | + | ||
| 335 | + SrsPlatformInfo(); | ||
| 336 | +}; | ||
| 337 | + | ||
| 338 | +// get platform info, use cache to avoid performance problem. | ||
| 339 | +extern SrsPlatformInfo* srs_get_platform_info(); | ||
| 340 | +// the deamon st-thread will update it. | ||
| 341 | +extern void srs_update_platform_info(); | ||
| 342 | + | ||
| 39 | #endif | 343 | #endif |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "98" | 34 | +#define VERSION_REVISION "99" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
| @@ -58,393 +58,3 @@ void srs_update_system_time_ms() | @@ -58,393 +58,3 @@ void srs_update_system_time_ms() | ||
| 58 | 58 | ||
| 59 | _srs_system_time_us_cache = now_us; | 59 | _srs_system_time_us_cache = now_us; |
| 60 | } | 60 | } |
| 61 | - | ||
| 62 | -static SrsRusage _srs_system_rusage; | ||
| 63 | - | ||
| 64 | -SrsRusage::SrsRusage() | ||
| 65 | -{ | ||
| 66 | - ok = false; | ||
| 67 | - sample_time = 0; | ||
| 68 | - memset(&r, 0, sizeof(rusage)); | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | -SrsRusage* srs_get_system_rusage() | ||
| 72 | -{ | ||
| 73 | - return &_srs_system_rusage; | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -void srs_update_system_rusage() | ||
| 77 | -{ | ||
| 78 | - if (getrusage(RUSAGE_SELF, &_srs_system_rusage.r) < 0) { | ||
| 79 | - srs_warn("getrusage failed, ignore"); | ||
| 80 | - return; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - srs_update_system_time_ms(); | ||
| 84 | - _srs_system_rusage.sample_time = srs_get_system_time_ms(); | ||
| 85 | - | ||
| 86 | - _srs_system_rusage.ok = true; | ||
| 87 | -} | ||
| 88 | - | ||
| 89 | -static SrsProcSelfStat _srs_system_cpu_self_stat; | ||
| 90 | -static SrsProcSystemStat _srs_system_cpu_system_stat; | ||
| 91 | - | ||
| 92 | -SrsProcSelfStat::SrsProcSelfStat() | ||
| 93 | -{ | ||
| 94 | - ok = false; | ||
| 95 | - sample_time = 0; | ||
| 96 | - percent = 0; | ||
| 97 | - | ||
| 98 | - pid = 0; | ||
| 99 | - memset(comm, 0, sizeof(comm)); | ||
| 100 | - state = 0; | ||
| 101 | - ppid = 0; | ||
| 102 | - pgrp = 0; | ||
| 103 | - session = 0; | ||
| 104 | - tty_nr = 0; | ||
| 105 | - tpgid = 0; | ||
| 106 | - flags = 0; | ||
| 107 | - minflt = 0; | ||
| 108 | - cminflt = 0; | ||
| 109 | - majflt = 0; | ||
| 110 | - cmajflt = 0; | ||
| 111 | - utime = 0; | ||
| 112 | - stime = 0; | ||
| 113 | - cutime = 0; | ||
| 114 | - cstime = 0; | ||
| 115 | - priority = 0; | ||
| 116 | - nice = 0; | ||
| 117 | - num_threads = 0; | ||
| 118 | - itrealvalue = 0; | ||
| 119 | - starttime = 0; | ||
| 120 | - vsize = 0; | ||
| 121 | - rss = 0; | ||
| 122 | - rsslim = 0; | ||
| 123 | - startcode = 0; | ||
| 124 | - endcode = 0; | ||
| 125 | - startstack = 0; | ||
| 126 | - kstkesp = 0; | ||
| 127 | - kstkeip = 0; | ||
| 128 | - signal = 0; | ||
| 129 | - blocked = 0; | ||
| 130 | - sigignore = 0; | ||
| 131 | - sigcatch = 0; | ||
| 132 | - wchan = 0; | ||
| 133 | - nswap = 0; | ||
| 134 | - cnswap = 0; | ||
| 135 | - exit_signal = 0; | ||
| 136 | - processor = 0; | ||
| 137 | - rt_priority = 0; | ||
| 138 | - policy = 0; | ||
| 139 | - delayacct_blkio_ticks = 0; | ||
| 140 | - guest_time = 0; | ||
| 141 | - cguest_time = 0; | ||
| 142 | -} | ||
| 143 | - | ||
| 144 | -SrsProcSystemStat::SrsProcSystemStat() | ||
| 145 | -{ | ||
| 146 | - ok = false; | ||
| 147 | - sample_time = 0; | ||
| 148 | - percent = 0; | ||
| 149 | - memset(label, 0, sizeof(label)); | ||
| 150 | - user = 0; | ||
| 151 | - nice = 0; | ||
| 152 | - sys = 0; | ||
| 153 | - idle = 0; | ||
| 154 | - iowait = 0; | ||
| 155 | - irq = 0; | ||
| 156 | - softirq = 0; | ||
| 157 | - steal = 0; | ||
| 158 | - guest = 0; | ||
| 159 | -} | ||
| 160 | - | ||
| 161 | -SrsProcSelfStat* srs_get_self_proc_stat() | ||
| 162 | -{ | ||
| 163 | - return &_srs_system_cpu_self_stat; | ||
| 164 | -} | ||
| 165 | - | ||
| 166 | -SrsProcSystemStat* srs_get_system_proc_stat() | ||
| 167 | -{ | ||
| 168 | - return &_srs_system_cpu_system_stat; | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -bool get_proc_system_stat(SrsProcSystemStat& r) | ||
| 172 | -{ | ||
| 173 | - FILE* f = fopen("/proc/stat", "r"); | ||
| 174 | - if (f == NULL) { | ||
| 175 | - srs_warn("open system cpu stat failed, ignore"); | ||
| 176 | - return false; | ||
| 177 | - } | ||
| 178 | - | ||
| 179 | - for (;;) { | ||
| 180 | - int ret = fscanf(f, "%4s %lu %lu %lu %lu %lu " | ||
| 181 | - "%lu %lu %lu %lu\n", | ||
| 182 | - r.label, &r.user, &r.nice, &r.sys, &r.idle, &r.iowait, | ||
| 183 | - &r.irq, &r.softirq, &r.steal, &r.guest); | ||
| 184 | - r.ok = false; | ||
| 185 | - | ||
| 186 | - if (ret == EOF) { | ||
| 187 | - break; | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | - if (strcmp("cpu", r.label) == 0) { | ||
| 191 | - r.ok = true; | ||
| 192 | - break; | ||
| 193 | - } | ||
| 194 | - } | ||
| 195 | - | ||
| 196 | - fclose(f); | ||
| 197 | - | ||
| 198 | - return r.ok; | ||
| 199 | -} | ||
| 200 | - | ||
| 201 | -bool get_proc_self_stat(SrsProcSelfStat& r) | ||
| 202 | -{ | ||
| 203 | - FILE* f = fopen("/proc/self/stat", "r"); | ||
| 204 | - if (f == NULL) { | ||
| 205 | - srs_warn("open self cpu stat failed, ignore"); | ||
| 206 | - return false; | ||
| 207 | - } | ||
| 208 | - | ||
| 209 | - int ret = fscanf(f, "%d %32s %c %d %d %d %d " | ||
| 210 | - "%d %u %lu %lu %lu %lu " | ||
| 211 | - "%lu %lu %ld %ld %ld %ld " | ||
| 212 | - "%ld %ld %llu %lu %ld " | ||
| 213 | - "%lu %lu %lu %lu %lu " | ||
| 214 | - "%lu %lu %lu %lu %lu " | ||
| 215 | - "%lu %lu %lu %d %d " | ||
| 216 | - "%u %u %llu " | ||
| 217 | - "%lu %ld", | ||
| 218 | - &r.pid, r.comm, &r.state, &r.ppid, &r.pgrp, &r.session, &r.tty_nr, | ||
| 219 | - &r.tpgid, &r.flags, &r.minflt, &r.cminflt, &r.majflt, &r.cmajflt, | ||
| 220 | - &r.utime, &r.stime, &r.cutime, &r.cstime, &r.priority, &r.nice, | ||
| 221 | - &r.num_threads, &r.itrealvalue, &r.starttime, &r.vsize, &r.rss, | ||
| 222 | - &r.rsslim, &r.startcode, &r.endcode, &r.startstack, &r.kstkesp, | ||
| 223 | - &r.kstkeip, &r.signal, &r.blocked, &r.sigignore, &r.sigcatch, | ||
| 224 | - &r.wchan, &r.nswap, &r.cnswap, &r.exit_signal, &r.processor, | ||
| 225 | - &r.rt_priority, &r.policy, &r.delayacct_blkio_ticks, | ||
| 226 | - &r.guest_time, &r.cguest_time); | ||
| 227 | - | ||
| 228 | - fclose(f); | ||
| 229 | - | ||
| 230 | - if (ret >= 0) { | ||
| 231 | - r.ok = true; | ||
| 232 | - } | ||
| 233 | - | ||
| 234 | - return r.ok; | ||
| 235 | -} | ||
| 236 | - | ||
| 237 | -void srs_update_proc_stat() | ||
| 238 | -{ | ||
| 239 | - srs_update_system_time_ms(); | ||
| 240 | - | ||
| 241 | - // system cpu stat | ||
| 242 | - if (true) { | ||
| 243 | - SrsProcSystemStat r; | ||
| 244 | - if (!get_proc_system_stat(r)) { | ||
| 245 | - return; | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - r.sample_time = srs_get_system_time_ms(); | ||
| 249 | - | ||
| 250 | - // calc usage in percent | ||
| 251 | - SrsProcSystemStat& o = _srs_system_cpu_system_stat; | ||
| 252 | - | ||
| 253 | - // @see: http://blog.csdn.net/nineday/article/details/1928847 | ||
| 254 | - int64_t total = (r.user + r.nice + r.sys + r.idle + r.iowait + r.irq + r.softirq + r.steal + r.guest) | ||
| 255 | - - (o.user + o.nice + o.sys + o.idle + o.iowait + o.irq + o.softirq + o.steal + o.guest); | ||
| 256 | - int64_t idle = r.idle - o.idle; | ||
| 257 | - if (total > 0) { | ||
| 258 | - r.percent = (float)(1 - idle / (double)total); | ||
| 259 | - } | ||
| 260 | - | ||
| 261 | - // upate cache. | ||
| 262 | - _srs_system_cpu_system_stat = r; | ||
| 263 | - } | ||
| 264 | - | ||
| 265 | - // self cpu stat | ||
| 266 | - if (true) { | ||
| 267 | - SrsProcSelfStat r; | ||
| 268 | - if (!get_proc_self_stat(r)) { | ||
| 269 | - return; | ||
| 270 | - } | ||
| 271 | - | ||
| 272 | - srs_update_system_time_ms(); | ||
| 273 | - r.sample_time = srs_get_system_time_ms(); | ||
| 274 | - | ||
| 275 | - // calc usage in percent | ||
| 276 | - SrsProcSelfStat& o = _srs_system_cpu_self_stat; | ||
| 277 | - | ||
| 278 | - // @see: http://stackoverflow.com/questions/16011677/calculating-cpu-usage-using-proc-files | ||
| 279 | - int64_t total = r.sample_time - o.sample_time; | ||
| 280 | - int64_t usage = (r.utime + r.stime) - (o.utime + o.stime); | ||
| 281 | - if (total > 0) { | ||
| 282 | - r.percent = (float)(usage * 1000 / (double)total / 100); | ||
| 283 | - } | ||
| 284 | - | ||
| 285 | - // upate cache. | ||
| 286 | - _srs_system_cpu_self_stat = r; | ||
| 287 | - } | ||
| 288 | -} | ||
| 289 | - | ||
| 290 | -SrsMemInfo::SrsMemInfo() | ||
| 291 | -{ | ||
| 292 | - ok = false; | ||
| 293 | - sample_time = 0; | ||
| 294 | - | ||
| 295 | - percent_ram = 0; | ||
| 296 | - percent_swap = 0; | ||
| 297 | - | ||
| 298 | - MemActive = 0; | ||
| 299 | - RealInUse = 0; | ||
| 300 | - NotInUse = 0; | ||
| 301 | - MemTotal = 0; | ||
| 302 | - MemFree = 0; | ||
| 303 | - Buffers = 0; | ||
| 304 | - Cached = 0; | ||
| 305 | - SwapTotal = 0; | ||
| 306 | - SwapFree = 0; | ||
| 307 | -} | ||
| 308 | - | ||
| 309 | -static SrsMemInfo _srs_system_meminfo; | ||
| 310 | - | ||
| 311 | -SrsMemInfo* srs_get_meminfo() | ||
| 312 | -{ | ||
| 313 | - return &_srs_system_meminfo; | ||
| 314 | -} | ||
| 315 | - | ||
| 316 | -void srs_update_meminfo() | ||
| 317 | -{ | ||
| 318 | - FILE* f = fopen("/proc/meminfo", "r"); | ||
| 319 | - if (f == NULL) { | ||
| 320 | - srs_warn("open meminfo failed, ignore"); | ||
| 321 | - return; | ||
| 322 | - } | ||
| 323 | - | ||
| 324 | - SrsMemInfo& r = _srs_system_meminfo; | ||
| 325 | - r.ok = false; | ||
| 326 | - | ||
| 327 | - for (;;) { | ||
| 328 | - static char label[64]; | ||
| 329 | - static unsigned long value; | ||
| 330 | - static char postfix[64]; | ||
| 331 | - int ret = fscanf(f, "%64s %lu %64s\n", label, &value, postfix); | ||
| 332 | - | ||
| 333 | - if (ret == EOF) { | ||
| 334 | - break; | ||
| 335 | - } | ||
| 336 | - | ||
| 337 | - if (strcmp("MemTotal:", label) == 0) { | ||
| 338 | - r.MemTotal = value; | ||
| 339 | - } else if (strcmp("MemFree:", label) == 0) { | ||
| 340 | - r.MemFree = value; | ||
| 341 | - } else if (strcmp("Buffers:", label) == 0) { | ||
| 342 | - r.Buffers = value; | ||
| 343 | - } else if (strcmp("Cached:", label) == 0) { | ||
| 344 | - r.Cached = value; | ||
| 345 | - } else if (strcmp("SwapTotal:", label) == 0) { | ||
| 346 | - r.SwapTotal = value; | ||
| 347 | - } else if (strcmp("SwapFree:", label) == 0) { | ||
| 348 | - r.SwapFree = value; | ||
| 349 | - } | ||
| 350 | - } | ||
| 351 | - | ||
| 352 | - fclose(f); | ||
| 353 | - | ||
| 354 | - r.sample_time = srs_get_system_time_ms(); | ||
| 355 | - r.MemActive = r.MemTotal - r.MemFree; | ||
| 356 | - r.RealInUse = r.MemActive - r.Buffers - r.Cached; | ||
| 357 | - r.NotInUse = r.MemTotal - r.RealInUse; | ||
| 358 | - | ||
| 359 | - r.ok = true; | ||
| 360 | - if (r.MemTotal > 0) { | ||
| 361 | - r.percent_ram = (float)(r.RealInUse / (double)r.MemTotal); | ||
| 362 | - } | ||
| 363 | - if (r.SwapTotal > 0) { | ||
| 364 | - r.percent_swap = (float)((r.SwapTotal - r.SwapFree) / (double)r.SwapTotal); | ||
| 365 | - } | ||
| 366 | -} | ||
| 367 | - | ||
| 368 | -SrsCpuInfo::SrsCpuInfo() | ||
| 369 | -{ | ||
| 370 | - ok = false; | ||
| 371 | - | ||
| 372 | - nb_processors = 0; | ||
| 373 | - nb_processors_online = 0; | ||
| 374 | -} | ||
| 375 | - | ||
| 376 | -SrsCpuInfo* srs_get_cpuinfo() | ||
| 377 | -{ | ||
| 378 | - static SrsCpuInfo* cpu = NULL; | ||
| 379 | - if (cpu != NULL) { | ||
| 380 | - return cpu; | ||
| 381 | - } | ||
| 382 | - | ||
| 383 | - // initialize cpu info. | ||
| 384 | - cpu = new SrsCpuInfo(); | ||
| 385 | - cpu->ok = true; | ||
| 386 | - cpu->nb_processors = sysconf(_SC_NPROCESSORS_CONF); | ||
| 387 | - cpu->nb_processors_online = sysconf(_SC_NPROCESSORS_ONLN); | ||
| 388 | - | ||
| 389 | - return cpu; | ||
| 390 | -} | ||
| 391 | - | ||
| 392 | -SrsPlatformInfo::SrsPlatformInfo() | ||
| 393 | -{ | ||
| 394 | - ok = false; | ||
| 395 | - | ||
| 396 | - srs_startup_time = srs_get_system_time_ms(); | ||
| 397 | - | ||
| 398 | - os_uptime = 0; | ||
| 399 | - os_ilde_time = 0; | ||
| 400 | - | ||
| 401 | - load_one_minutes = 0; | ||
| 402 | - load_five_minutes = 0; | ||
| 403 | - load_fifteen_minutes = 0; | ||
| 404 | -} | ||
| 405 | - | ||
| 406 | -static SrsPlatformInfo _srs_system_platform_info; | ||
| 407 | - | ||
| 408 | -SrsPlatformInfo* srs_get_platform_info() | ||
| 409 | -{ | ||
| 410 | - return &_srs_system_platform_info; | ||
| 411 | -} | ||
| 412 | - | ||
| 413 | -void srs_update_platform_info() | ||
| 414 | -{ | ||
| 415 | - SrsPlatformInfo& r = _srs_system_platform_info; | ||
| 416 | - r.ok = true; | ||
| 417 | - | ||
| 418 | - if (true) { | ||
| 419 | - FILE* f = fopen("/proc/uptime", "r"); | ||
| 420 | - if (f == NULL) { | ||
| 421 | - srs_warn("open uptime failed, ignore"); | ||
| 422 | - return; | ||
| 423 | - } | ||
| 424 | - | ||
| 425 | - int ret = fscanf(f, "%lf %lf\n", &r.os_uptime, &r.os_ilde_time); | ||
| 426 | - | ||
| 427 | - fclose(f); | ||
| 428 | - | ||
| 429 | - if (ret < 0) { | ||
| 430 | - r.ok = false; | ||
| 431 | - } | ||
| 432 | - } | ||
| 433 | - | ||
| 434 | - if (true) { | ||
| 435 | - FILE* f = fopen("/proc/loadavg", "r"); | ||
| 436 | - if (f == NULL) { | ||
| 437 | - srs_warn("open loadavg failed, ignore"); | ||
| 438 | - return; | ||
| 439 | - } | ||
| 440 | - | ||
| 441 | - int ret = fscanf(f, "%lf %lf %lf\n", | ||
| 442 | - &r.load_one_minutes, &r.load_five_minutes, &r.load_fifteen_minutes); | ||
| 443 | - | ||
| 444 | - fclose(f); | ||
| 445 | - | ||
| 446 | - if (ret < 0) { | ||
| 447 | - r.ok = false; | ||
| 448 | - } | ||
| 449 | - } | ||
| 450 | -} |
| @@ -30,313 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,313 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | 30 | ||
| 31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
| 32 | 32 | ||
| 33 | -#include <sys/resource.h> | ||
| 34 | - | ||
| 35 | // get current system time in ms, use cache to avoid performance problem | 33 | // get current system time in ms, use cache to avoid performance problem |
| 36 | extern int64_t srs_get_system_time_ms(); | 34 | extern int64_t srs_get_system_time_ms(); |
| 37 | // the deamon st-thread will update it. | 35 | // the deamon st-thread will update it. |
| 38 | extern void srs_update_system_time_ms(); | 36 | extern void srs_update_system_time_ms(); |
| 39 | 37 | ||
| 40 | -// @see: man getrusage | ||
| 41 | -struct SrsRusage | ||
| 42 | -{ | ||
| 43 | - // whether the data is ok. | ||
| 44 | - bool ok; | ||
| 45 | - // the time in ms when sample. | ||
| 46 | - int64_t sample_time; | ||
| 47 | - | ||
| 48 | - rusage r; | ||
| 49 | - | ||
| 50 | - SrsRusage(); | ||
| 51 | -}; | ||
| 52 | - | ||
| 53 | -// get system rusage, use cache to avoid performance problem. | ||
| 54 | -extern SrsRusage* srs_get_system_rusage(); | ||
| 55 | -// the deamon st-thread will update it. | ||
| 56 | -extern void srs_update_system_rusage(); | ||
| 57 | - | ||
| 58 | -// @see: man 5 proc, /proc/[pid]/stat | ||
| 59 | -struct SrsProcSelfStat | ||
| 60 | -{ | ||
| 61 | - // whether the data is ok. | ||
| 62 | - bool ok; | ||
| 63 | - // the time in ms when sample. | ||
| 64 | - int64_t sample_time; | ||
| 65 | - // the percent of usage. 0.153 is 15.3%. | ||
| 66 | - float percent; | ||
| 67 | - | ||
| 68 | - // pid %d The process ID. | ||
| 69 | - int pid; | ||
| 70 | - // comm %s The filename of the executable, in parentheses. This is visible whether or not the executable is | ||
| 71 | - // swapped out. | ||
| 72 | - char comm[32]; | ||
| 73 | - // state %c One character from the string "RSDZTW" where R is running, S is sleeping in an interruptible wait, D | ||
| 74 | - // is waiting in uninterruptible disk sleep, Z is zombie, T is traced or stopped (on a signal), and W is | ||
| 75 | - // paging. | ||
| 76 | - char state; | ||
| 77 | - // ppid %d The PID of the parent. | ||
| 78 | - int ppid; | ||
| 79 | - // pgrp %d The process group ID of the process. | ||
| 80 | - int pgrp; | ||
| 81 | - // session %d The session ID of the process. | ||
| 82 | - int session; | ||
| 83 | - // tty_nr %d The controlling terminal of the process. (The minor device number is contained in the combination of | ||
| 84 | - // bits 31 to 20 and 7 to 0; the major device number is in bits 15 t0 8.) | ||
| 85 | - int tty_nr; | ||
| 86 | - // tpgid %d The ID of the foreground process group of the controlling terminal of the process. | ||
| 87 | - int tpgid; | ||
| 88 | - // flags %u (%lu before Linux 2.6.22) | ||
| 89 | - // The kernel flags word of the process. For bit meanings, see the PF_* defines in <linux/sched.h>. | ||
| 90 | - // Details depend on the kernel version. | ||
| 91 | - unsigned int flags; | ||
| 92 | - // minflt %lu The number of minor faults the process has made which have not required loading a memory page from | ||
| 93 | - // disk. | ||
| 94 | - unsigned long minflt; | ||
| 95 | - // cminflt %lu The number of minor faults that the process’s waited-for children have made. | ||
| 96 | - unsigned long cminflt; | ||
| 97 | - // majflt %lu The number of major faults the process has made which have required loading a memory page from disk. | ||
| 98 | - unsigned long majflt; | ||
| 99 | - // cmajflt %lu The number of major faults that the process’s waited-for children have made. | ||
| 100 | - unsigned long cmajflt; | ||
| 101 | - // utime %lu Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by | ||
| 102 | - // sysconf(_SC_CLK_TCK). This includes guest time, guest_time (time spent running a virtual CPU, see | ||
| 103 | - // below), so that applications that are not aware of the guest time field do not lose that time from | ||
| 104 | - // their calculations. | ||
| 105 | - unsigned long utime; | ||
| 106 | - // stime %lu Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by | ||
| 107 | - // sysconf(_SC_CLK_TCK). | ||
| 108 | - unsigned long stime; | ||
| 109 | - // cutime %ld Amount of time that this process’s waited-for children have been scheduled in user mode, measured in | ||
| 110 | - // clock ticks (divide by sysconf(_SC_CLK_TCK). (See also times(2).) This includes guest time, | ||
| 111 | - // cguest_time (time spent running a virtual CPU, see below). | ||
| 112 | - long cutime; | ||
| 113 | - // cstime %ld Amount of time that this process’s waited-for children have been scheduled in kernel mode, measured in | ||
| 114 | - // clock ticks (divide by sysconf(_SC_CLK_TCK). | ||
| 115 | - long cstime; | ||
| 116 | - // priority %ld | ||
| 117 | - // (Explanation for Linux 2.6) For processes running a real-time scheduling policy (policy below; see | ||
| 118 | - // sched_setscheduler(2)), this is the negated scheduling priority, minus one; that is, a number in the | ||
| 119 | - // range -2 to -100, corresponding to real-time priorities 1 to 99. For processes running under a non- | ||
| 120 | - // real-time scheduling policy, this is the raw nice value (setpriority(2)) as represented in the kernel. | ||
| 121 | - // The kernel stores nice values as numbers in the range 0 (high) to 39 (low), corresponding to the user- | ||
| 122 | - // visible nice range of -20 to 19. | ||
| 123 | - // | ||
| 124 | - // Before Linux 2.6, this was a scaled value based on the scheduler weighting given to this process. | ||
| 125 | - long priority; | ||
| 126 | - // nice %ld The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority). | ||
| 127 | - long nice; | ||
| 128 | - // num_threads %ld | ||
| 129 | - // Number of threads in this process (since Linux 2.6). Before kernel 2.6, this field was hard coded to | ||
| 130 | - // 0 as a placeholder for an earlier removed field. | ||
| 131 | - long num_threads; | ||
| 132 | - // itrealvalue %ld | ||
| 133 | - // The time in jiffies before the next SIGALRM is sent to the process due to an interval timer. Since | ||
| 134 | - // kernel 2.6.17, this field is no longer maintained, and is hard coded as 0. | ||
| 135 | - long itrealvalue; | ||
| 136 | - // starttime %llu (was %lu before Linux 2.6) | ||
| 137 | - // The time in jiffies the process started after system boot. | ||
| 138 | - long long starttime; | ||
| 139 | - // vsize %lu Virtual memory size in bytes. | ||
| 140 | - unsigned long vsize; | ||
| 141 | - // rss %ld Resident Set Size: number of pages the process has in real memory. This is just the pages which count | ||
| 142 | - // towards text, data, or stack space. This does not include pages which have not been demand-loaded in, | ||
| 143 | - // or which are swapped out. | ||
| 144 | - long rss; | ||
| 145 | - // rsslim %lu Current soft limit in bytes on the rss of the process; see the description of RLIMIT_RSS in getprior- | ||
| 146 | - // ity(2). | ||
| 147 | - unsigned long rsslim; | ||
| 148 | - // startcode %lu | ||
| 149 | - // The address above which program text can run. | ||
| 150 | - unsigned long startcode; | ||
| 151 | - // endcode %lu The address below which program text can run. | ||
| 152 | - unsigned long endcode; | ||
| 153 | - // startstack %lu | ||
| 154 | - // The address of the start (i.e., bottom) of the stack. | ||
| 155 | - unsigned long startstack; | ||
| 156 | - // kstkesp %lu The current value of ESP (stack pointer), as found in the kernel stack page for the process. | ||
| 157 | - unsigned long kstkesp; | ||
| 158 | - // kstkeip %lu The current EIP (instruction pointer). | ||
| 159 | - unsigned long kstkeip; | ||
| 160 | - // signal %lu The bitmap of pending signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 161 | - // information on real-time signals; use /proc/[pid]/status instead. | ||
| 162 | - unsigned long signal; | ||
| 163 | - // blocked %lu The bitmap of blocked signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 164 | - // information on real-time signals; use /proc/[pid]/status instead. | ||
| 165 | - unsigned long blocked; | ||
| 166 | - // sigignore %lu | ||
| 167 | - // The bitmap of ignored signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 168 | - // information on real-time signals; use /proc/[pid]/status instead. | ||
| 169 | - unsigned long sigignore; | ||
| 170 | - // sigcatch %lu | ||
| 171 | - // The bitmap of caught signals, displayed as a decimal number. Obsolete, because it does not provide | ||
| 172 | - // information on real-time signals; use /proc/[pid]/status instead. | ||
| 173 | - unsigned long sigcatch; | ||
| 174 | - // wchan %lu This is the "channel" in which the process is waiting. It is the address of a system call, and can be | ||
| 175 | - // looked up in a namelist if you need a textual name. (If you have an up-to-date /etc/psdatabase, then | ||
| 176 | - // try ps -l to see the WCHAN field in action.) | ||
| 177 | - unsigned long wchan; | ||
| 178 | - // nswap %lu Number of pages swapped (not maintained). | ||
| 179 | - unsigned long nswap; | ||
| 180 | - // cnswap %lu Cumulative nswap for child processes (not maintained). | ||
| 181 | - unsigned long cnswap; | ||
| 182 | - // exit_signal %d (since Linux 2.1.22) | ||
| 183 | - // Signal to be sent to parent when we die. | ||
| 184 | - int exit_signal; | ||
| 185 | - // processor %d (since Linux 2.2.8) | ||
| 186 | - // CPU number last executed on. | ||
| 187 | - int processor; | ||
| 188 | - // rt_priority %u (since Linux 2.5.19; was %lu before Linux 2.6.22) | ||
| 189 | - // Real-time scheduling priority, a number in the range 1 to 99 for processes scheduled under a real-time | ||
| 190 | - // policy, or 0, for non-real-time processes (see sched_setscheduler(2)). | ||
| 191 | - unsigned int rt_priority; | ||
| 192 | - // policy %u (since Linux 2.5.19; was %lu before Linux 2.6.22) | ||
| 193 | - // Scheduling policy (see sched_setscheduler(2)). Decode using the SCHED_* constants in linux/sched.h. | ||
| 194 | - unsigned int policy; | ||
| 195 | - // delayacct_blkio_ticks %llu (since Linux 2.6.18) | ||
| 196 | - // Aggregated block I/O delays, measured in clock ticks (centiseconds). | ||
| 197 | - unsigned long long delayacct_blkio_ticks; | ||
| 198 | - // guest_time %lu (since Linux 2.6.24) | ||
| 199 | - // Guest time of the process (time spent running a virtual CPU for a guest operating system), measured in | ||
| 200 | - // clock ticks (divide by sysconf(_SC_CLK_TCK). | ||
| 201 | - unsigned long guest_time; | ||
| 202 | - // cguest_time %ld (since Linux 2.6.24) | ||
| 203 | - // Guest time of the process’s children, measured in clock ticks (divide by sysconf(_SC_CLK_TCK). | ||
| 204 | - long cguest_time; | ||
| 205 | - | ||
| 206 | - SrsProcSelfStat(); | ||
| 207 | -}; | ||
| 208 | - | ||
| 209 | -// @see: man 5 proc, /proc/stat | ||
| 210 | -struct SrsProcSystemStat | ||
| 211 | -{ | ||
| 212 | - // whether the data is ok. | ||
| 213 | - bool ok; | ||
| 214 | - // the time in ms when sample. | ||
| 215 | - int64_t sample_time; | ||
| 216 | - // the percent of usage. 0.153 is 15.3%. | ||
| 217 | - float percent; | ||
| 218 | - | ||
| 219 | - // always be cpu | ||
| 220 | - char label[32]; | ||
| 221 | - | ||
| 222 | - //The amount of time, measured in units of USER_HZ (1/100ths of a second on most architectures, use | ||
| 223 | - // sysconf(_SC_CLK_TCK) to obtain the right value) | ||
| 224 | - // | ||
| 225 | - // the system spent in user mode, | ||
| 226 | - unsigned long user; | ||
| 227 | - // user mode with low priority (nice), | ||
| 228 | - unsigned long nice; | ||
| 229 | - // system mode, | ||
| 230 | - unsigned long sys; | ||
| 231 | - // and the idle task, respectively. | ||
| 232 | - unsigned long idle; | ||
| 233 | - | ||
| 234 | - // In Linux 2.6 this line includes three additional columns: | ||
| 235 | - // | ||
| 236 | - // iowait - time waiting for I/O to complete (since 2.5.41); | ||
| 237 | - unsigned long iowait; | ||
| 238 | - // irq - time servicing interrupts (since 2.6.0-test4); | ||
| 239 | - unsigned long irq; | ||
| 240 | - // softirq - time servicing softirqs (since 2.6.0-test4). | ||
| 241 | - unsigned long softirq; | ||
| 242 | - | ||
| 243 | - // Since Linux 2.6.11, there is an eighth column, | ||
| 244 | - // steal - stolen time, which is the time spent in other oper- | ||
| 245 | - // ating systems when running in a virtualized environment | ||
| 246 | - unsigned long steal; | ||
| 247 | - | ||
| 248 | - // Since Linux 2.6.24, there is a ninth column, | ||
| 249 | - // guest, which is the time spent running a virtual CPU for guest | ||
| 250 | - // operating systems under the control of the Linux kernel. | ||
| 251 | - unsigned long guest; | ||
| 252 | - | ||
| 253 | - SrsProcSystemStat(); | ||
| 254 | -}; | ||
| 255 | - | ||
| 256 | -// get system cpu stat, use cache to avoid performance problem. | ||
| 257 | -extern SrsProcSelfStat* srs_get_self_proc_stat(); | ||
| 258 | -// get system cpu stat, use cache to avoid performance problem. | ||
| 259 | -extern SrsProcSystemStat* srs_get_system_proc_stat(); | ||
| 260 | -// the deamon st-thread will update it. | ||
| 261 | -extern void srs_update_proc_stat(); | ||
| 262 | - | ||
| 263 | -// @see: cat /proc/meminfo | ||
| 264 | -struct SrsMemInfo | ||
| 265 | -{ | ||
| 266 | - // whether the data is ok. | ||
| 267 | - bool ok; | ||
| 268 | - // the time in ms when sample. | ||
| 269 | - int64_t sample_time; | ||
| 270 | - // the percent of usage. 0.153 is 15.3%. | ||
| 271 | - float percent_ram; | ||
| 272 | - float percent_swap; | ||
| 273 | - | ||
| 274 | - // MemActive = MemTotal - MemFree | ||
| 275 | - int64_t MemActive; | ||
| 276 | - // RealInUse = MemActive - Buffers - Cached | ||
| 277 | - int64_t RealInUse; | ||
| 278 | - // NotInUse = MemTotal - RealInUse | ||
| 279 | - // = MemTotal - MemActive + Buffers + Cached | ||
| 280 | - // = MemTotal - MemTotal + MemFree + Buffers + Cached | ||
| 281 | - // = MemFree + Buffers + Cached | ||
| 282 | - int64_t NotInUse; | ||
| 283 | - | ||
| 284 | - int64_t MemTotal; | ||
| 285 | - int64_t MemFree; | ||
| 286 | - int64_t Buffers; | ||
| 287 | - int64_t Cached; | ||
| 288 | - int64_t SwapTotal; | ||
| 289 | - int64_t SwapFree; | ||
| 290 | - | ||
| 291 | - SrsMemInfo(); | ||
| 292 | -}; | ||
| 293 | - | ||
| 294 | -// get system meminfo, use cache to avoid performance problem. | ||
| 295 | -extern SrsMemInfo* srs_get_meminfo(); | ||
| 296 | -// the deamon st-thread will update it. | ||
| 297 | -extern void srs_update_meminfo(); | ||
| 298 | - | ||
| 299 | -// @see: cat /proc/cpuinfo | ||
| 300 | -struct SrsCpuInfo | ||
| 301 | -{ | ||
| 302 | - // whether the data is ok. | ||
| 303 | - bool ok; | ||
| 304 | - | ||
| 305 | - // The number of processors configured. | ||
| 306 | - int nb_processors; | ||
| 307 | - // The number of processors currently online (available). | ||
| 308 | - int nb_processors_online; | ||
| 309 | - | ||
| 310 | - SrsCpuInfo(); | ||
| 311 | -}; | ||
| 312 | - | ||
| 313 | -// get system cpu info, use cache to avoid performance problem. | ||
| 314 | -extern SrsCpuInfo* srs_get_cpuinfo(); | ||
| 315 | - | ||
| 316 | -// platform(os, srs) summary | ||
| 317 | -struct SrsPlatformInfo | ||
| 318 | -{ | ||
| 319 | - // whether the data is ok. | ||
| 320 | - bool ok; | ||
| 321 | - | ||
| 322 | - // srs startup time, in ms. | ||
| 323 | - int64_t srs_startup_time; | ||
| 324 | - | ||
| 325 | - // @see: cat /proc/uptime | ||
| 326 | - double os_uptime; | ||
| 327 | - double os_ilde_time; | ||
| 328 | - | ||
| 329 | - // @see: cat /proc/loadavg | ||
| 330 | - double load_one_minutes; | ||
| 331 | - double load_five_minutes; | ||
| 332 | - double load_fifteen_minutes; | ||
| 333 | - | ||
| 334 | - SrsPlatformInfo(); | ||
| 335 | -}; | ||
| 336 | - | ||
| 337 | -// get platform info, use cache to avoid performance problem. | ||
| 338 | -extern SrsPlatformInfo* srs_get_platform_info(); | ||
| 339 | -// the deamon st-thread will update it. | ||
| 340 | -extern void srs_update_platform_info(); | ||
| 341 | - | ||
| 342 | #endif | 38 | #endif |
-
请 注册 或 登录 后发表评论