Skip to content

Commit

Permalink
Merge pull request #477 from beef9999/beef9999/br-13
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/release/0.7'
  • Loading branch information
beef9999 authored May 10, 2024
2 parents 265c65a + 7df590a commit d700761
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
24 changes: 5 additions & 19 deletions common/alog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void LogFormatter::put_integer_dec(ALogBuffer& buf, ALogInteger x)
__attribute__((constructor)) static void __initial_timezone() { tzset(); }
static time_t dayid = 0;
static struct tm alog_time = {0};
struct tm* alog_update_time(time_t now)
static struct tm* alog_update_time(time_t now)
{
auto now0 = now;
int sec = now % 60; now /= 60;
Expand Down Expand Up @@ -478,36 +478,22 @@ int log_output_file_close() {
return 0;
}

namespace photon
{
struct thread;
extern __thread thread* CURRENT;
}

static inline ALogInteger DEC_W2P0(uint64_t x)
{
return DEC(x).width(2).padding('0');
}

namespace photon {
struct timeval alog_update_now();
}

LogBuffer& operator << (LogBuffer& log, const Prologue& pro)
{
#ifdef LOG_BENCHMARK
auto t = &alog_time;
#else
auto ts = photon::alog_update_now();
auto t = alog_update_time(ts.tv_sec - timezone);
auto ts = photon::__update_now();
auto t = alog_update_time(ts.sec() - timezone);
#endif
#define DEC_W2P0(x) DEC(x).width(2).padding('0')
log.printf(t->tm_year, '/');
log.printf(DEC_W2P0(t->tm_mon), '/');
log.printf(DEC_W2P0(t->tm_mday), ' ');
log.printf(DEC_W2P0(t->tm_hour), ':');
log.printf(DEC_W2P0(t->tm_min), ':');
log.printf(DEC_W2P0(t->tm_sec), '.');
log.printf(DEC(ts.tv_usec).width(6).padding('0'));
log.printf(DEC(ts.usec()).width(6).padding('0'));

static const char levels[] = "|DEBUG|th=|INFO |th=|WARN |th=|ERROR|th=|FATAL|th=|TEMP |th=|AUDIT|th=";
log.level = pro.level;
Expand Down
2 changes: 0 additions & 2 deletions net/http/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ class Client : public Object {
Operation(uint16_t buf_size) : req(_buf, buf_size) {}
};

// use delete_operation() or destroy(), instead of delete
Operation* new_operation(Verb v, std::string_view url, uint16_t buf_size = UINT16_MAX) {
return Operation::create(this, v, url, buf_size);
}

// use delete_operation() or destroy(), instead of delete
Operation* new_operation(uint16_t buf_size = UINT16_MAX) {
return Operation::create(this, buf_size);
}
Expand Down
11 changes: 5 additions & 6 deletions thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,19 +1046,18 @@ R"(

volatile uint64_t now;
static std::atomic<pthread_t> ts_updater(0);
static inline struct timeval update_now()
static inline NowTime update_now()
{
#if defined(__x86_64__) && defined(__linux__) && defined(ENABLE_MIMIC_VDSO)
if (likely(__mimic_vdso_time_x86))
return photon::now = __mimic_vdso_time_x86.get_now();
#endif
struct timeval tv;
gettimeofday(&tv, NULL);
uint64_t nnow = tv.tv_sec;
nnow *= 1000 * 1000;
nnow += tv.tv_usec;
uint64_t nnow = tv.tv_sec * 1000ul * 1000ul + tv.tv_usec;
now = nnow;
return tv;
assert(tv.tv_sec <= UINT32_MAX && tv.tv_usec < 1000000);
return {nnow, ((uint64_t)tv.tv_sec << 32) | (uint32_t)tv.tv_usec};
}
__attribute__((always_inline))
static inline uint32_t _rdtsc()
Expand Down Expand Up @@ -1102,7 +1101,7 @@ R"(
update_now();
}
}
struct timeval alog_update_now() {
NowTime __update_now() {
last_tsc = _rdtsc();
return update_now();
}
Expand Down
8 changes: 7 additions & 1 deletion thread/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ namespace photon

struct thread;
extern __thread thread* CURRENT;
extern volatile uint64_t now;
extern volatile uint64_t now; // a coarse-grained timestamp in unit of us
struct NowTime {
uint64_t now, _sec_usec;
uint32_t sec() { return _sec_usec >> 32; }
uint32_t usec() { auto p = (uint32_t*)&_sec_usec; return *p; }
};
NowTime __update_now(); // update `now`

enum states
{
Expand Down

0 comments on commit d700761

Please sign in to comment.