Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
glog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
glog
Commits
dda88128
Commit
dda88128
authored
May 21, 2020
by
zhaoyunfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localtime_r用cpu计算的方式代替
parent
0a2e5931
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
1 deletion
+53
-1
logging.cc
src/logging.cc
+2
-1
utilities.cc
src/utilities.cc
+48
-0
utilities.h
src/utilities.h
+3
-0
No files found.
src/logging.cc
View file @
dda88128
...
...
@@ -1418,7 +1418,8 @@ void LogMessage::Init(const char* file,
data_
->
outvec_
=
NULL
;
WallTime
now
=
WallTime_Now
();
data_
->
timestamp_
=
static_cast
<
time_t
>
(
now
);
localtime_r
(
&
data_
->
timestamp_
,
&
data_
->
tm_time_
);
// localtime_r(&data_->timestamp_, &data_->tm_time_);
FastSecondToDate
(
data_
->
timestamp_
,
&
data_
->
tm_time_
,
GetCurTimeZone
());
data_
->
usecs_
=
static_cast
<
int32
>
((
now
-
data_
->
timestamp_
)
*
1000000
);
data_
->
num_chars_to_log_
=
0
;
...
...
src/utilities.cc
View file @
dda88128
...
...
@@ -220,6 +220,54 @@ WallTime WallTime_Now() {
return
CycleClock_Now
()
*
0.000001
;
}
int
_GetCurTimeZone
(){
int
timezone
=
0
;
time_t
t1
,
t2
;
struct
tm
*
tm_local
,
*
tm_utc
;
time
(
&
t1
);
t2
=
t1
;
tm_local
=
localtime
(
&
t1
);
t1
=
mktime
(
tm_local
)
;
tm_utc
=
gmtime
(
&
t2
);
t2
=
mktime
(
tm_utc
);
timezone
=
int
((
t1
-
t2
)
/
3600
);
return
timezone
;
}
static
int32
g_timezone
=
_GetCurTimeZone
();
int32_t
GetCurTimeZone
(){
return
g_timezone
;
}
int
FastSecondToDate
(
const
time_t
&
unix_sec
,
struct
tm
*
tm
,
int
time_zone
)
{
static
const
int
kHoursInDay
=
24
;
static
const
int
kMinutesInHour
=
60
;
static
const
int
kDaysFromUnixTime
=
2472632
;
static
const
int
kDaysFromYear
=
153
;
static
const
int
kMagicUnkonwnFirst
=
146097
;
static
const
int
kMagicUnkonwnSec
=
1461
;
tm
->
tm_sec
=
unix_sec
%
kMinutesInHour
;
int
i
=
(
unix_sec
/
kMinutesInHour
);
tm
->
tm_min
=
i
%
kMinutesInHour
;
//nn
i
/=
kMinutesInHour
;
tm
->
tm_hour
=
(
i
+
time_zone
)
%
kHoursInDay
;
// hh
tm
->
tm_mday
=
(
i
+
time_zone
)
/
kHoursInDay
;
int
a
=
tm
->
tm_mday
+
kDaysFromUnixTime
;
int
b
=
(
a
*
4
+
3
)
/
kMagicUnkonwnFirst
;
int
c
=
(
-
b
*
kMagicUnkonwnFirst
)
/
4
+
a
;
int
d
=
((
c
*
4
+
3
)
/
kMagicUnkonwnSec
);
int
e
=
-
d
*
kMagicUnkonwnSec
;
e
=
e
/
4
+
c
;
int
m
=
(
5
*
e
+
2
)
/
kDaysFromYear
;
tm
->
tm_mday
=
-
(
kDaysFromYear
*
m
+
2
)
/
5
+
e
+
1
;
tm
->
tm_mon
=
(
-
m
/
10
)
*
12
+
m
+
2
;
tm
->
tm_year
=
b
*
100
+
d
-
6700
+
(
m
/
10
);
return
0
;
}
static
int32
g_main_thread_pid
=
getpid
();
int32
GetMainThreadPid
()
{
return
g_main_thread_pid
;
...
...
src/utilities.h
View file @
dda88128
...
...
@@ -170,6 +170,9 @@ int64 UsecToCycles(int64 usec);
typedef
double
WallTime
;
WallTime
WallTime_Now
();
int32_t
GetCurTimeZone
();
int32_t
FastSecondToDate
(
const
time_t
&
unix_sec
,
struct
tm
*
tm
,
int
time_zone
);
int32
GetMainThreadPid
();
bool
PidHasChanged
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment