Skip to content

Commit

Permalink
Threads-Log: Refine stat for sync wait, in log thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 26, 2021
1 parent 6a1d6a0 commit 2367483
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
22 changes: 0 additions & 22 deletions trunk/src/app/srs_app_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@
#include <srs_kernel_utility.hpp>
#include <srs_app_threads.hpp>

#include <srs_protocol_kbps.hpp>

SrsPps* _srs_thread_sync_10us = new SrsPps();
SrsPps* _srs_thread_sync_100us = new SrsPps();
SrsPps* _srs_thread_sync_1000us = new SrsPps();
SrsPps* _srs_thread_sync_plus = new SrsPps();

// the max size of a line of log.
#define LOG_MAX_SIZE 8192

Expand Down Expand Up @@ -235,24 +228,9 @@ void SrsFileLog::write_log(char *str_log, int size, int level)
return;
}

// It's ok to use cache, because it has been updated in generating log header.
srs_utime_t now = srs_get_system_time();

// write log to file.
if ((err = writer_->write(str_log, size, NULL)) != srs_success) {
srs_error_reset(err); // Ignore any error for log writing.
}

// Stat the sync wait of locks.
srs_utime_t elapsed = srs_update_system_time() - now;
if (elapsed <= 10) {
++_srs_thread_sync_10us->sugar;
} else if (elapsed <= 100) {
++_srs_thread_sync_100us->sugar;
} else if (elapsed <= 1000) {
++_srs_thread_sync_1000us->sugar;
} else {
++_srs_thread_sync_plus->sugar;
}
}

29 changes: 24 additions & 5 deletions trunk/src/app/srs_app_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ using namespace std;

#include <srs_protocol_kbps.hpp>

extern SrsPps* _srs_thread_sync_10us;
extern SrsPps* _srs_thread_sync_100us;
extern SrsPps* _srs_thread_sync_1000us;
extern SrsPps* _srs_thread_sync_plus;
SrsPps* _srs_thread_sync_10us = new SrsPps();
SrsPps* _srs_thread_sync_100us = new SrsPps();
SrsPps* _srs_thread_sync_1000us = new SrsPps();
SrsPps* _srs_thread_sync_plus = new SrsPps();

SrsThreadMutex::SrsThreadMutex()
{
Expand Down Expand Up @@ -310,9 +310,28 @@ srs_error_t SrsAsyncFileWriter::flush()
{
srs_error_t err = srs_success;

// The time to wait here, is the time to wait there, because they wait for the same lock
// at queue to push_back or swap all messages.
srs_utime_t now = srs_update_system_time();

vector<SrsSharedPtrMessage*> flying;
queue_->swap(flying);
if (true) {
queue_->swap(flying);
}

// Stat the sync wait of locks.
srs_utime_t elapsed = srs_update_system_time() - now;
if (elapsed <= 10) {
++_srs_thread_sync_10us->sugar;
} else if (elapsed <= 100) {
++_srs_thread_sync_100us->sugar;
} else if (elapsed <= 1000) {
++_srs_thread_sync_1000us->sugar;
} else {
++_srs_thread_sync_plus->sugar;
}

// Flush the flying messages to disk.
for (int i = 0; i < (int)flying.size(); i++) {
SrsSharedPtrMessage* msg = flying.at(i);

Expand Down

0 comments on commit 2367483

Please sign in to comment.