Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
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
brpc
Commits
6fdeeac2
Commit
6fdeeac2
authored
Sep 11, 2017
by
chenzhangyi01
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
butil/logging could be overwritten by glog
Change-Id: I14cf8724175d1fb5237fe20228f822afdd8521cc
parent
52afeebd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
256 additions
and
166 deletions
+256
-166
Makefile
Makefile
+4
-4
config_brpc.sh
config_brpc.sh
+45
-2
acceptor.cpp
src/brpc/acceptor.cpp
+1
-0
amf.h
src/brpc/amf.h
+1
-0
hotspots_service.cpp
src/brpc/builtin/hotspots_service.cpp
+7
-6
pprof_service.cpp
src/brpc/builtin/pprof_service.cpp
+22
-16
vlog_service.cpp
src/brpc/builtin/vlog_service.cpp
+5
-1
vlog_service.h
src/brpc/builtin/vlog_service.h
+2
-0
channel.cpp
src/brpc/channel.cpp
+1
-0
naming_service_thread.cpp
src/brpc/details/naming_service_thread.cpp
+6
-5
global.cpp
src/brpc/global.cpp
+5
-5
protocol.cpp
src/brpc/protocol.cpp
+4
-4
server.cpp
src/brpc/server.cpp
+14
-8
socket_map.cpp
src/brpc/socket_map.cpp
+4
-3
leak_tracker.h
src/butil/debug/leak_tracker.h
+2
-4
proc_maps_linux.cc
src/butil/debug/proc_maps_linux.cc
+1
-1
endpoint.cpp
src/butil/endpoint.cpp
+1
-0
logging.cc
src/butil/logging.cc
+26
-22
logging.h
src/butil/logging.h
+0
-0
file_descriptor_shuffle.cc
src/butil/posix/file_descriptor_shuffle.cc
+1
-1
launch_posix.cc
src/butil/process/launch_posix.cc
+4
-4
safe_sprintf.cc
src/butil/strings/safe_sprintf.cc
+25
-25
prtime.cc
src/butil/third_party/nspr/prtime.cc
+1
-0
thread_local.cpp
src/butil/thread_local.cpp
+3
-2
sampler.cpp
src/bvar/detail/sampler.cpp
+0
-2
recorder.h
src/bvar/recorder.h
+11
-10
Makefile
test/Makefile
+2
-2
brpc_builtin_service_unittest.cpp
test/brpc_builtin_service_unittest.cpp
+3
-1
brpc_load_balancer_unittest.cpp
test/brpc_load_balancer_unittest.cpp
+1
-1
brpc_server_unittest.cpp
test/brpc_server_unittest.cpp
+6
-0
brpc_socket_map_unittest.cpp
test/brpc_socket_map_unittest.cpp
+1
-1
bthread_id_unittest.cpp
test/bthread_id_unittest.cpp
+1
-1
bthread_timer_thread_unittest.cpp
test/bthread_timer_thread_unittest.cpp
+2
-6
butil_unittest_main.cpp
test/butil_unittest_main.cpp
+2
-0
bvar_reducer_unittest.cpp
test/bvar_reducer_unittest.cpp
+4
-0
bvar_sampler_unittest.cpp
test/bvar_sampler_unittest.cpp
+8
-0
class_name_unittest.cpp
test/class_name_unittest.cpp
+1
-1
file_watcher_unittest.cpp
test/file_watcher_unittest.cpp
+0
-2
logging_unittest.cc
test/logging_unittest.cc
+26
-23
rand_util_unittest.cc
test/rand_util_unittest.cc
+3
-3
No files found.
Makefile
View file @
6fdeeac2
...
...
@@ -6,9 +6,9 @@ include config.mk
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
# 3. Removed -Werror: Not block compilation for non-vital warnings, especially when the
# code is tested on newer systems. If the code is used in production, add -Werror back
CPPFLAGS
=
-DBTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
-DBRPC_REVISION
=
\"
$(
shell
git rev-parse
--short
HEAD
)
\"
CXXFLAGS
=
$(CPPFLAGS)
-g
-O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
CFLAGS
=
$(CPPFLAGS)
-g
-O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-unused-parameter
-fno-omit-frame-pointer
CPPFLAGS
+
=
-DBTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
-DBRPC_REVISION
=
\"
$(
shell
git rev-parse
--short
HEAD
)
\"
CXXFLAGS
+
=
$(CPPFLAGS)
-g
-O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
CFLAGS
+
=
$(CPPFLAGS)
-g
-O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-unused-parameter
-fno-omit-frame-pointer
HDRPATHS
=
-I
./src
$
(
addprefix
-I
,
$(HDRS)
)
LIBPATHS
=
$
(
addprefix
-L
,
$(LIBS)
)
COMMA
=
,
...
...
@@ -270,7 +270,7 @@ output/bin:protoc-gen-mcpack
%.dbg.o
:
%.cpp
@
echo
"Compiling
$@
"
@
$(CXX)
-c
$(HDRPATHS)
$(CXXFLAGS)
$<
-o
$@
@
$(CXX)
-c
$(HDRPATHS)
$(CXXFLAGS)
-DBVAR_NOT_LINK_DEFAULT_VARIABLES
$<
-o
$@
%.o
:
%.cc
@
echo
"Compiling
$@
"
...
...
config_brpc.sh
View file @
6fdeeac2
...
...
@@ -5,7 +5,8 @@ else
fi
# NOTE: This requires GNU getopt. On Mac OS X and FreeBSD, you have to install this
# separately; see below.
TEMP
=
`
getopt
-o
v:
--long
headers:,libs:,cc:,cxx:
-n
'config_brpc'
--
"
$@
"
`
TEMP
=
`
getopt
-o
v:
--long
headers:,libs:,cc:,cxx:,with-glog
-n
'config_brpc'
--
"
$@
"
`
WITH_GLOG
=
0
if
[
$?
!=
0
]
;
then
>
&2
$ECHO
"Terminating..."
;
exit
1
;
fi
...
...
@@ -19,10 +20,12 @@ while true; do
--libs
)
LIBS_IN
=
"
$(
readlink
-f
$2
)
"
;
shift
2
;;
--cc
)
CC
=
$2
;
shift
2
;;
--cxx
)
CXX
=
$2
;
shift
2
;;
--with-glog
)
WITH_GLOG
=
1
;
shift
1
;;
--
)
shift
;
break
;;
*
)
break
;;
esac
done
if
[
-z
"
$CC
"
]
;
then
if
[
!
-z
"
$CXX
"
]
;
then
>
&2
$ECHO
"--cc and --cxx must be both set or unset"
...
...
@@ -82,8 +85,17 @@ find_bin_or_die() {
find_dir_of_header
()
{
find
${
HDRS_IN
}
-path
"*/
$1
"
|
head
-n1
|
sed
"s|
$1
||g"
}
find_dir_of_header_excluding
()
{
find
${
HDRS_IN
}
-path
"*/
$1
"
|
grep
-v
"
$2
\$
"
|
head
-n1
|
sed
"s|
$1
||g"
}
find_dir_of_header_or_die
()
{
local dir
=
$(
find_dir_of_header
$1
)
if
[
-z
"
$2
"
]
;
then
local dir
=
$(
find_dir_of_header
$1
)
else
local dir
=
$(
find_dir_of_header_excluding
$1
$2
)
fi
if
[
-z
"
$dir
"
]
;
then
>
&2
$ECHO
"Fail to find
$1
from --headers"
exit
1
...
...
@@ -243,6 +255,23 @@ else
fi
append_to_output
"endif"
if
[
$WITH_GLOG
!=
0
]
;
then
GLOG_LIB
=
$(
find_dir_of_lib glog
)
GLOG_HDR
=
$(
find_dir_of_header_or_die glog/logging.h windows/glog/logging.h
)
append_to_output_headers
"
$GLOG_HDR
"
" "
if
[
-z
"
$GLOG_LIB
"
]
;
then
append_to_output
"
\$
(error
\"
Fail to find glog
\"
)"
else
append_to_output_libs
"
$GLOG_LIB
"
" "
if
[
-f
$GLOG_LIB
/libglog.a
]
;
then
append_to_output
" STATIC_LINKINGS+=-lglog"
else
append_to_output
" DYNAMIC_LINKINGS+=-lglog"
fi
fi
fi
append_to_output
"CPPFLAGS+=-DBRPC_WITH_GLOG=
$WITH_GLOG
"
# required by UT
#gtest
GTEST_LIB
=
$(
find_dir_of_lib gtest
)
...
...
@@ -276,5 +305,19 @@ else
fi
append_to_output
"endif"
# generate src/butil/config.h
cat
<<
EOF
> src/butil/config.h
// This file is auto-generated by
$(
basename
"
$0
"
)
. DON'T edit it!
#ifndef BUTIL_CONFIG_H
#define BUTIL_CONFIG_H
#ifdef BRPC_WITH_GLOG
#undef BRPC_WITH_GLOG
#endif
#define BRPC_WITH_GLOG
$WITH_GLOG
#endif // BUTIL_CONFIG_H
EOF
# write to config.mk
$ECHO
"
$OUTPUT_CONTENT
"
>
config.mk
src/brpc/acceptor.cpp
View file @
6fdeeac2
...
...
@@ -15,6 +15,7 @@
// Authors: Rujie Jiang(jiangrujie@baidu.com)
// Ge,Jun(gejun@baidu.com)
#include <inttypes.h>
#include <gflags/gflags.h>
#include "butil/fd_guard.h" // fd_guard
#include "butil/fd_utility.h" // make_close_on_exec
...
...
src/brpc/amf.h
View file @
6fdeeac2
...
...
@@ -22,6 +22,7 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/message.h>
#include "butil/sys_byteorder.h"
#include "butil/strings/string_piece.h"
namespace
brpc
{
...
...
src/brpc/builtin/hotspots_service.cpp
View file @
6fdeeac2
...
...
@@ -547,17 +547,18 @@ static void DoProfiling(ProfilingType type,
}
// Log requester
LOG
(
INFO
)
<<
cntl
->
remote_side
()
<<
noflush
;
std
::
ostringstream
client_info
;
client_info
<<
cntl
->
remote_side
();
if
(
cntl
->
auth_context
())
{
LOG
(
INFO
)
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
<<
noflush
;
client_info
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
;
}
else
{
LOG
(
INFO
)
<<
"(no auth)"
<<
noflush
;
client_info
<<
"(no auth)"
;
}
LOG
(
INFO
)
<<
" requests for profiling "
<<
ProfilingType2String
(
type
)
<<
noflush
;
client_info
<<
" requests for profiling "
<<
ProfilingType2String
(
type
)
;
if
(
type
==
PROFILING_CPU
||
type
==
PROFILING_CONTENTION
)
{
LOG
(
INFO
)
<<
" for "
<<
seconds
<<
" seconds"
;
LOG
(
INFO
)
<<
client_info
.
str
()
<<
" for "
<<
seconds
<<
" seconds"
;
}
else
{
LOG
(
INFO
);
LOG
(
INFO
)
<<
client_info
.
str
()
;
}
int64_t
prof_id
=
0
;
const
std
::
string
*
prof_id_str
=
...
...
src/brpc/builtin/pprof_service.cpp
View file @
6fdeeac2
...
...
@@ -108,13 +108,15 @@ void PProfService::profile(
return
;
}
// Log requester
LOG
(
INFO
)
<<
cntl
->
remote_side
()
<<
noflush
;
std
::
ostringstream
client_info
;
client_info
<<
cntl
->
remote_side
();
if
(
cntl
->
auth_context
())
{
LOG
(
INFO
)
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
<<
noflush
;
client_info
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
;
}
else
{
LOG
(
INFO
)
<<
"(no auth)"
<<
noflush
;
client_info
<<
"(no auth)"
;
}
LOG
(
INFO
)
<<
" requests for cpu profile for "
<<
sleep_sec
<<
" seconds"
;
LOG
(
INFO
)
<<
client_info
.
str
()
<<
" requests for cpu profile for "
<<
sleep_sec
<<
" seconds"
;
char
prof_name
[
256
];
if
(
MakeProfName
(
PROFILING_CPU
,
prof_name
,
sizeof
(
prof_name
))
!=
0
)
{
...
...
@@ -163,13 +165,15 @@ void PProfService::contention(
return
;
}
// Log requester
LOG
(
INFO
)
<<
cntl
->
remote_side
()
<<
noflush
;
std
::
ostringstream
client_info
;
client_info
<<
cntl
->
remote_side
();
if
(
cntl
->
auth_context
())
{
LOG
(
INFO
)
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
<<
noflush
;
client_info
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
;
}
else
{
LOG
(
INFO
)
<<
"(no auth)"
<<
noflush
;
client_info
<<
"(no auth)"
;
}
LOG
(
INFO
)
<<
" requests for contention profile for "
<<
sleep_sec
<<
" seconds"
;
LOG
(
INFO
)
<<
client_info
.
str
()
<<
" requests for contention profile for "
<<
sleep_sec
<<
" seconds"
;
char
prof_name
[
256
];
if
(
MakeProfName
(
PROFILING_CONTENTION
,
prof_name
,
sizeof
(
prof_name
))
!=
0
)
{
...
...
@@ -210,13 +214,14 @@ void PProfService::heap(
return
;
}
// Log requester
LOG
(
INFO
)
<<
cntl
->
remote_side
()
<<
noflush
;
std
::
ostringstream
client_info
;
client_info
<<
cntl
->
remote_side
();
if
(
cntl
->
auth_context
())
{
LOG
(
INFO
)
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
<<
noflush
;
client_info
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
;
}
else
{
LOG
(
INFO
)
<<
"(no auth)"
<<
noflush
;
client_info
<<
"(no auth)"
;
}
LOG
(
INFO
)
<<
" requests for heap profile"
;
LOG
(
INFO
)
<<
client_info
.
str
()
<<
" requests for heap profile"
;
std
::
string
obj
;
malloc_ext
->
GetHeapSample
(
&
obj
);
...
...
@@ -239,13 +244,14 @@ void PProfService::growth(
return
;
}
// Log requester
LOG
(
INFO
)
<<
cntl
->
remote_side
()
<<
noflush
;
std
::
ostringstream
client_info
;
client_info
<<
cntl
->
remote_side
();
if
(
cntl
->
auth_context
())
{
LOG
(
INFO
)
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
<<
noflush
;
client_info
<<
"(auth="
<<
cntl
->
auth_context
()
->
user
()
<<
')'
;
}
else
{
LOG
(
INFO
)
<<
"(no auth)"
<<
noflush
;
client_info
<<
"(no auth)"
;
}
LOG
(
INFO
)
<<
" requests for growth profile"
;
LOG
(
INFO
)
<<
client_info
.
str
()
<<
" requests for growth profile"
;
std
::
string
obj
;
malloc_ext
->
GetHeapGrowthStacks
(
&
obj
);
...
...
src/brpc/builtin/vlog_service.cpp
View file @
6fdeeac2
...
...
@@ -14,13 +14,14 @@
// Authors: Ge,Jun (gejun@baidu.com)
#if !BRPC_WITH_GLOG
#include "brpc/log.h"
#include "brpc/controller.h" // Controller
#include "brpc/closure_guard.h" // ClosureGuard
#include "brpc/builtin/vlog_service.h"
#include "brpc/builtin/common.h"
namespace
brpc
{
class
VLogPrinter
:
public
VLogSitePrinter
{
...
...
@@ -91,3 +92,6 @@ void VLogService::default_method(::google::protobuf::RpcController* cntl_base,
}
}
// namespace brpc
#endif
src/brpc/builtin/vlog_service.h
View file @
6fdeeac2
...
...
@@ -17,6 +17,7 @@
#ifndef BRPC_VLOG_SERVICE_H
#define BRPC_VLOG_SERVICE_H
#if !BRPC_WITH_GLOG
#include <ostream>
#include "brpc/builtin_service.pb.h"
...
...
@@ -34,5 +35,6 @@ public:
}
// namespace brpc
#endif // BRPC_WITH_GLOG
#endif //BRPC_VLOG_SERVICE_H
src/brpc/channel.cpp
View file @
6fdeeac2
...
...
@@ -16,6 +16,7 @@
// Rujie Jiang(jiangrujie@baidu.com)
// Zhangyi Chen(chenzhangyi01@baidu.com)
#include <inttypes.h>
#include <google/protobuf/descriptor.h>
#include <gflags/gflags.h>
#include "butil/time.h" // milliseconds_from_now
...
...
src/brpc/details/naming_service_thread.cpp
View file @
6fdeeac2
...
...
@@ -168,15 +168,16 @@ void NamingServiceThread::Actions::ResetServers(
}
if
(
!
_removed
.
empty
()
||
!
_added
.
empty
())
{
LOG
(
INFO
)
<<
butil
::
class_name_str
(
*
_owner
->
_ns
)
<<
"(
\"
"
<<
_owner
->
_service_name
<<
"
\"
):"
<<
noflush
;
std
::
ostringstream
info
;
info
<<
butil
::
class_name_str
(
*
_owner
->
_ns
)
<<
"(
\"
"
<<
_owner
->
_service_name
<<
"
\"
):"
;
if
(
!
_added
.
empty
())
{
LOG
(
INFO
)
<<
" added "
<<
_added
.
size
()
<<
noflush
;
info
<<
" added "
<<
_added
.
size
()
;
}
if
(
!
_removed
.
empty
())
{
LOG
(
INFO
)
<<
" removed "
<<
_removed
.
size
()
<<
noflush
;
info
<<
" removed "
<<
_removed
.
size
()
;
}
LOG
(
INFO
);
LOG
(
INFO
)
<<
info
.
str
()
;
}
EndWait
(
servers
.
empty
()
?
ENODATA
:
0
);
...
...
src/brpc/global.cpp
View file @
6fdeeac2
...
...
@@ -228,19 +228,19 @@ static void BaiduStreamingLogHandler(google::protobuf::LogLevel level,
const
std
::
string
&
message
)
{
switch
(
level
)
{
case
google
:
:
protobuf
::
LOGLEVEL_INFO
:
LOG
_AT
(
INFO
,
filename
,
line
)
<<
message
;
LOG
(
INFO
)
<<
filename
<<
':'
<<
line
<<
' '
<<
message
;
return
;
case
google
:
:
protobuf
::
LOGLEVEL_WARNING
:
LOG
_AT
(
WARNING
,
filename
,
line
)
<<
message
;
LOG
(
WARNING
)
<<
filename
<<
':'
<<
line
<<
' '
<<
message
;
return
;
case
google
:
:
protobuf
::
LOGLEVEL_ERROR
:
LOG
_AT
(
ERROR
,
filename
,
line
)
<<
message
;
LOG
(
ERROR
)
<<
filename
<<
':'
<<
line
<<
' '
<<
message
;
return
;
case
google
:
:
protobuf
::
LOGLEVEL_FATAL
:
LOG
_AT
(
FATAL
,
filename
,
line
)
<<
message
;
LOG
(
FATAL
)
<<
filename
<<
':'
<<
line
<<
' '
<<
message
;
return
;
}
LOG_AT
(
FATAL
,
filename
,
line
)
<<
message
;
CHECK
(
false
)
<<
filename
<<
':'
<<
line
<<
' '
<<
message
;
}
static
void
GlobalInitializeOrDieImpl
()
{
...
...
src/brpc/protocol.cpp
View file @
6fdeeac2
...
...
@@ -171,14 +171,14 @@ ProtocolType StringToProtocolType(const butil::StringPiece& name,
// "channel doesn't support protocol=unknown"
// Some callsite may not need this log, so we keep a flag.
if
(
print_log_on_unknown
)
{
LOG
(
ERROR
)
<<
"Unknown protocol `"
<<
name
<<
"', supported protocols:"
<<
noflush
;
std
::
ostringstream
err
;
err
<<
"Unknown protocol `"
<<
name
<<
"', supported protocols:"
;
for
(
size_t
i
=
0
;
i
<
MAX_PROTOCOL_SIZE
;
++
i
)
{
if
(
protocol_map
[
i
].
valid
.
load
(
butil
::
memory_order_acquire
))
{
LOG
(
ERROR
)
<<
' '
<<
protocol_map
[
i
].
protocol
.
name
<<
noflush
;
err
<<
' '
<<
protocol_map
[
i
].
protocol
.
name
;
}
}
LOG
(
ERROR
);
LOG
(
ERROR
)
<<
err
.
str
()
;
}
return
PROTOCOL_UNKNOWN
;
}
...
...
src/brpc/server.cpp
View file @
6fdeeac2
...
...
@@ -491,10 +491,14 @@ int Server::AddBuiltinServices() {
LOG
(
ERROR
)
<<
"Fail to add ThreadsService"
;
return
-
1
;
}
#if !BRPC_WITH_GLOG
if
(
AddBuiltinService
(
new
(
std
::
nothrow
)
VLogService
))
{
LOG
(
ERROR
)
<<
"Fail to add VLogService"
;
return
-
1
;
}
#endif
if
(
AddBuiltinService
(
new
(
std
::
nothrow
)
PProfService
))
{
LOG
(
ERROR
)
<<
"Fail to add PProfService"
;
return
-
1
;
...
...
@@ -578,14 +582,15 @@ Acceptor* Server::BuildAcceptor() {
}
}
if
(
!
whitelist
.
empty
())
{
LOG
(
ERROR
)
<<
"ServerOptions.enabled_protocols has unknown protocols=`"
<<
noflush
;
std
::
ostringstream
err
;
err
<<
"ServerOptions.enabled_protocols has unknown protocols=`"
;
for
(
std
::
set
<
std
::
string
>::
const_iterator
it
=
whitelist
.
begin
();
it
!=
whitelist
.
end
();
++
it
)
{
LOG
(
ERROR
)
<<
*
it
<<
' '
<<
noflush
;
err
<<
*
it
<<
' '
;
}
LOG
(
ERROR
)
<<
'\''
;
err
<<
'\''
;
delete
acceptor
;
LOG
(
ERROR
)
<<
err
.
str
();
return
NULL
;
}
return
acceptor
;
...
...
@@ -950,13 +955,14 @@ int Server::StartInternal(const butil::ip_t& ip,
// Print tips to server launcher.
int
http_port
=
_listen_addr
.
port
;
LOG
(
INFO
)
<<
"Server["
<<
version
()
<<
"] is serving on port="
<<
_listen_addr
.
port
<<
noflush
;
std
::
ostringstream
server_info
;
server_info
<<
"Server["
<<
version
()
<<
"] is serving on port="
<<
_listen_addr
.
port
;
if
(
_options
.
internal_port
>=
0
&&
_options
.
has_builtin_services
)
{
http_port
=
_options
.
internal_port
;
LOG
(
INFO
)
<<
" and internal_port="
<<
_options
.
internal_port
<<
noflush
;
server_info
<<
" and internal_port="
<<
_options
.
internal_port
;
}
LOG
(
INFO
)
<<
'.'
;
LOG
(
INFO
)
<<
server_info
.
str
()
<<
'.'
;
if
(
_options
.
has_builtin_services
)
{
LOG
(
INFO
)
<<
"Check out http://"
<<
butil
::
my_hostname
()
<<
':'
...
...
src/brpc/socket_map.cpp
View file @
6fdeeac2
...
...
@@ -138,6 +138,7 @@ SocketMap::~SocketMap() {
bthread_join
(
_close_idle_thread
,
NULL
);
}
if
(
!
_map
.
empty
())
{
std
::
ostringstream
err
;
int
nleft
=
0
;
for
(
Map
::
iterator
it
=
_map
.
begin
();
it
!=
_map
.
end
();
++
it
)
{
SingleConnection
*
sc
=
&
it
->
second
;
...
...
@@ -146,13 +147,13 @@ SocketMap::~SocketMap() {
sc
->
ref_count
!=
0
)
{
++
nleft
;
if
(
nleft
==
0
)
{
LOG
(
ERROR
)
<<
"Left in SocketMap("
<<
this
<<
"):"
<<
noflush
;
err
<<
"Left in SocketMap("
<<
this
<<
"):"
;
}
LOG
(
ERROR
)
<<
' '
<<
*
sc
->
socket
<<
noflush
;
err
<<
' '
<<
*
sc
->
socket
;
}
}
if
(
nleft
)
{
LOG
(
ERROR
);
LOG
(
ERROR
)
<<
err
.
str
()
;
}
}
if
(
_this_map_bvar
)
{
...
...
src/butil/debug/leak_tracker.h
View file @
6fdeeac2
...
...
@@ -93,10 +93,8 @@ class LeakTracker : public LinkNode<LeakTracker<T> > {
stacktraces
[
count
]
=
allocation_stack
;
++
count
;
if
(
LOG_IS_ON
(
ERROR
))
{
LOG_STREAM
(
ERROR
)
<<
"Leaked "
<<
node
<<
" which was allocated by:"
;
allocation_stack
.
OutputToStream
(
&
LOG_STREAM
(
ERROR
));
}
LOG
(
ERROR
)
<<
"Leaked "
<<
node
<<
" which was allocated by:"
;
//allocation_stack.OutputToStream(&LOG_STREAM(ERROR));
}
CHECK_EQ
(
0u
,
count
);
...
...
src/butil/debug/proc_maps_linux.cc
View file @
6fdeeac2
...
...
@@ -103,7 +103,7 @@ bool ParseProcMaps(const std::string& input,
// Due to splitting on '\n' the last line should be empty.
if
(
i
==
lines
.
size
()
-
1
)
{
if
(
!
lines
[
i
].
empty
())
{
DLOG
(
WARNING
)
<<
"Last line not empty"
;
D
P
LOG
(
WARNING
)
<<
"Last line not empty"
;
return
false
;
}
break
;
...
...
src/butil/endpoint.cpp
View file @
6fdeeac2
...
...
@@ -26,6 +26,7 @@
#include "butil/endpoint.h" // ip_t
#include "butil/logging.h"
#include "butil/memory/singleton_on_pthread_once.h"
#include "butil/strings/string_piece.h"
__BEGIN_DECLS
int
BAIDU_WEAK
bthread_connect
(
...
...
src/butil/logging.cc
View file @
6fdeeac2
...
...
@@ -17,6 +17,8 @@
#include "butil/logging.h"
#if !BRPC_WITH_GLOG
#if defined(OS_WIN)
#include <io.h>
#include <windows.h>
...
...
@@ -116,17 +118,17 @@ DEFINE_bool(crash_on_fatal_log, false,
DEFINE_bool
(
print_stack_on_check
,
true
,
"Print the stack trace when a CHECK was failed"
);
DEFINE_int32
(
v
erbose
,
0
,
"Show all VLOG(m) messages for m <= this."
" Overridable by --v
erbose_
module."
);
DEFINE_string
(
v
erbose_
module
,
""
,
"per-module verbose level."
DEFINE_int32
(
v
,
0
,
"Show all VLOG(m) messages for m <= this."
" Overridable by --vmodule."
);
DEFINE_string
(
vmodule
,
""
,
"per-module verbose level."
" Argument is a comma-separated list of MODULE_NAME=LOG_LEVEL."
" MODULE_NAME is a glob pattern, matched against the filename base"
" (that is, name ignoring .cpp/.h)."
" LOG_LEVEL overrides any value given by --v
erbose
."
);
" LOG_LEVEL overrides any value given by --v."
);
DEFINE_bool
(
log_process_id
,
false
,
"Log process id"
);
DEFINE_int32
(
min
_log_
level
,
0
,
"Any log at or above this level will be "
DEFINE_int32
(
min
log
level
,
0
,
"Any log at or above this level will be "
"displayed. Anything below this level will be silently ignored. "
"0=INFO 1=NOTICE 2=WARNING 3=ERROR 4=FATAL"
);
...
...
@@ -432,11 +434,11 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
}
void
SetMinLogLevel
(
int
level
)
{
FLAGS_min
_log_
level
=
std
::
min
(
BLOG_FATAL
,
level
);
FLAGS_min
log
level
=
std
::
min
(
BLOG_FATAL
,
level
);
}
int
GetMinLogLevel
()
{
return
FLAGS_min
_log_
level
;
return
FLAGS_min
log
level
;
}
void
SetShowErrorDialogs
(
bool
enable_dialogs
)
{
...
...
@@ -1019,7 +1021,7 @@ void CloseLogFile() {
}
void
RawLog
(
int
level
,
const
char
*
message
)
{
if
(
level
>=
FLAGS_min
_log_
level
)
{
if
(
level
>=
FLAGS_min
log
level
)
{
size_t
bytes_written
=
0
;
const
size_t
message_len
=
strlen
(
message
);
int
rv
;
...
...
@@ -1126,7 +1128,7 @@ private:
// Next site in the list. NULL means no next.
butil
::
subtle
::
AtomicWord
_next
;
// --v
erbose_module > --verbose
// --v
module > --v
int
_v
;
// vlog is on iff _v >= _required_v
...
...
@@ -1270,12 +1272,12 @@ private:
// vlog_site_list. To keep the critical area small, we use optimistic
// locking : Assign local site w/o locking, then insert the site into
// global list w/ locking, if local_module_list != global_vmodule_list or
// local_default_v != FLAGS_v
erbose
, repeat the assigment.
// local_default_v != FLAGS_v, repeat the assigment.
// An important property of vlog_site_list is that: It does not remove sites.
// When we need to iterate the list, we don't have to hold the lock. What we
// do is to get the head of the list inside lock and iterate the list w/o
// lock. If new sites is inserted during the iteration, it should see and
// use the updated vmodule_list and FLAGS_v
erbose
, nothing will be missed.
// use the updated vmodule_list and FLAGS_v, nothing will be missed.
static
int
vlog_site_list_add
(
VLogSite
*
site
,
VModuleList
**
expected_module_list
,
...
...
@@ -1285,8 +1287,8 @@ static int vlog_site_list_add(VLogSite* site,
*
expected_module_list
=
vmodule_list
;
return
-
1
;
}
if
(
*
expected_default_v
!=
FLAGS_v
erbose
)
{
*
expected_default_v
=
FLAGS_v
erbose
;
if
(
*
expected_default_v
!=
FLAGS_v
)
{
*
expected_default_v
=
FLAGS_v
;
return
-
1
;
}
site
->
set_next
(
vlog_site_list
);
...
...
@@ -1301,7 +1303,7 @@ bool add_vlog_site(const int** v, const char* filename, int line_no,
return
false
;
}
VModuleList
*
module_list
=
vmodule_list
;
int
default_v
=
FLAGS_v
erbose
;
int
default_v
=
FLAGS_v
;
do
{
site
->
v
()
=
default_v
;
if
(
module_list
)
{
...
...
@@ -1329,8 +1331,8 @@ void print_vlog_sites(VLogSitePrinter* printer) {
}
}
// [Thread-safe] Reset FLAGS_v
erbose_
module.
static
int
on_reset_v
erbose_
module
(
const
char
*
vmodule
)
{
// [Thread-safe] Reset FLAGS_vmodule.
static
int
on_reset_vmodule
(
const
char
*
vmodule
)
{
// resetting must be serialized.
BAIDU_SCOPED_LOCK
(
reset_vmodule_and_v_mutex
);
...
...
@@ -1355,7 +1357,7 @@ static int on_reset_verbose_module(const char* vmodule) {
old_vlog_site_list
=
vlog_site_list
;
}
for
(
VLogSite
*
p
=
old_vlog_site_list
;
p
;
p
=
p
->
next
())
{
p
->
v
()
=
FLAGS_v
erbose
;
p
->
v
()
=
FLAGS_v
;
module_list
->
find_verbose_level
(
p
->
module
(),
p
->
full_module
(),
&
p
->
v
());
}
...
...
@@ -1380,13 +1382,13 @@ static int on_reset_verbose_module(const char* vmodule) {
}
static
bool
validate_vmodule
(
const
char
*
,
const
std
::
string
&
vmodule
)
{
return
on_reset_v
erbose_
module
(
vmodule
.
c_str
())
==
0
;
return
on_reset_vmodule
(
vmodule
.
c_str
())
==
0
;
}
const
bool
ALLOW_UNUSED
validate_vmodule_dummy
=
google
::
RegisterFlagValidator
(
&
FLAGS_v
erbose_
module
,
&
validate_vmodule
);
&
FLAGS_vmodule
,
&
validate_vmodule
);
// [Thread-safe] Reset FLAGS_v
erbose
.
// [Thread-safe] Reset FLAGS_v.
static
void
on_reset_verbose
(
int
default_v
)
{
VModuleList
*
cur_module_list
=
NULL
;
VLogSite
*
cur_vlog_site_list
=
NULL
;
...
...
@@ -1414,7 +1416,7 @@ static bool validate_v(const char*, int32_t v) {
}
const
bool
ALLOW_UNUSED
validate_v_dummy
=
google
::
RegisterFlagValidator
(
&
FLAGS_v
erbose
,
&
validate_v
);
&
FLAGS_v
,
&
validate_v
);
static
bool
PassValidate
(
const
char
*
,
bool
)
{
return
true
;
...
...
@@ -1431,10 +1433,12 @@ static bool NonNegativeInteger(const char*, int32_t v) {
}
const
bool
ALLOW_UNUSED
validate_min_log_level
=
google
::
RegisterFlagValidator
(
&
FLAGS_min
_log_
level
,
NonNegativeInteger
);
&
FLAGS_min
log
level
,
NonNegativeInteger
);
}
// namespace logging
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
wchar_t
*
wstr
)
{
return
out
<<
butil
::
WideToUTF8
(
std
::
wstring
(
wstr
));
}
#endif // BRPC_WITH_GLOG
src/butil/logging.h
View file @
6fdeeac2
This diff is collapsed.
Click to expand it.
src/butil/posix/file_descriptor_shuffle.cc
View file @
6fdeeac2
...
...
@@ -94,7 +94,7 @@ bool FileDescriptorTableInjection::Move(int src, int dest) {
void
FileDescriptorTableInjection
::
Close
(
int
fd
)
{
int
ret
=
IGNORE_EINTR
(
close
(
fd
));
D
P
CHECK
(
ret
==
0
);
DCHECK
(
ret
==
0
);
}
}
// namespace butil
src/butil/process/launch_posix.cc
View file @
6fdeeac2
...
...
@@ -91,9 +91,9 @@ sigset_t SetSignalMask(const sigset_t& new_sigmask) {
// but Android's pthread_sigmask() was broken until 4.1:
// https://code.google.com/p/android/issues/detail?id=15337
// http://stackoverflow.com/questions/13777109/pthread-sigmask-on-android-not-working
RAW_CHECK
(
sigprocmask
(
SIG_SETMASK
,
&
new_sigmask
,
&
old_sigmask
)
==
0
);
RAW_CHECK
(
sigprocmask
(
SIG_SETMASK
,
&
new_sigmask
,
&
old_sigmask
)
==
0
,
""
);
#else
RAW_CHECK
(
pthread_sigmask
(
SIG_SETMASK
,
&
new_sigmask
,
&
old_sigmask
)
==
0
);
RAW_CHECK
(
pthread_sigmask
(
SIG_SETMASK
,
&
new_sigmask
,
&
old_sigmask
)
==
0
,
""
);
#endif
return
old_sigmask
;
}
...
...
@@ -157,7 +157,7 @@ void ResetChildSignalHandlersToDefaults(void) {
// If the number of signals in the Linux kernel changes, someone should
// look at this code.
const
int
kNumberOfSignals
=
64
;
RAW_CHECK
(
signum
==
kNumberOfSignals
+
1
);
RAW_CHECK
(
signum
==
kNumberOfSignals
+
1
,
""
);
#endif // !defined(NDEBUG)
break
;
}
...
...
@@ -311,7 +311,7 @@ bool LaunchProcess(const std::vector<std::string>& argv,
// process, so we check that a thread is not being created by mistake
// and that signal handling follows the process-creation rules.
RAW_CHECK
(
!
(
options
.
clone_flags
&
(
CLONE_SIGHAND
|
CLONE_THREAD
|
CLONE_VM
)));
!
(
options
.
clone_flags
&
(
CLONE_SIGHAND
|
CLONE_THREAD
|
CLONE_VM
))
,
""
);
pid
=
syscall
(
__NR_clone
,
options
.
clone_flags
,
0
,
0
,
0
);
}
else
#endif
...
...
src/butil/strings/safe_sprintf.cc
View file @
6fdeeac2
...
...
@@ -16,7 +16,7 @@
// and we should _never_ include any logging code that is active in production
// builds. Most notably, we should not include these logging functions in
// unofficial release builds, even though those builds would otherwise have
// DCHECKS() enabled.
// D
EBUG_
CHECKS() enabled.
// In other words; please do not remove the #ifdef around this #include.
// Instead, in production builds we opt for returning a degraded result,
// whenever an error is encountered.
...
...
@@ -31,7 +31,7 @@
#include "butil/logging.h"
#define DEBUG_CHECK RAW_CHECK
#else
#define DEBUG_CHECK(x) do { if (x) { } } while (0)
#define DEBUG_CHECK(x
, msg
) do { if (x) { } } while (0)
#endif
namespace
butil
{
...
...
@@ -118,8 +118,8 @@ class Buffer {
static_cast
<
size_t
>
(
std
::
numeric_limits
<
ssize_t
>::
max
()),
kSSizeMax_is_the_max_value_of_an_ssize_t
);
#endif
DEBUG_CHECK
(
size
>
0
);
DEBUG_CHECK
(
size
<=
kSSizeMax
);
DEBUG_CHECK
(
size
>
0
,
""
);
DEBUG_CHECK
(
size
<=
kSSizeMax
,
""
);
}
~
Buffer
()
{
...
...
@@ -144,7 +144,7 @@ class Buffer {
// |size_|, if the caller provided an insufficiently large output buffer.
// But it will never be bigger than |kSSizeMax-1|.
inline
ssize_t
GetCount
()
const
{
DEBUG_CHECK
(
count_
<
kSSizeMax
);
DEBUG_CHECK
(
count_
<
kSSizeMax
,
""
);
return
static_cast
<
ssize_t
>
(
count_
);
}
...
...
@@ -173,8 +173,8 @@ class Buffer {
// Returns "false", iff the the |buffer_| filled up (i.e. |count_|
// overflowed |size_|) at any time during padding.
inline
bool
Pad
(
char
pad
,
size_t
padding
,
size_t
len
)
{
DEBUG_CHECK
(
pad
);
DEBUG_CHECK
(
padding
<=
kSSizeMax
);
DEBUG_CHECK
(
pad
,
""
);
DEBUG_CHECK
(
padding
<=
kSSizeMax
,
""
);
for
(;
padding
>
len
;
--
padding
)
{
if
(
!
Out
(
pad
))
{
if
(
--
padding
)
{
...
...
@@ -229,7 +229,7 @@ class Buffer {
// the range 1..kSSizeMax-1.
// This allows us to compute "kSSizeMax - 1 - inc" without incurring any
// integer overflows.
DEBUG_CHECK
(
inc
<=
kSSizeMax
-
1
);
DEBUG_CHECK
(
inc
<=
kSSizeMax
-
1
,
""
);
if
(
count_
>
kSSizeMax
-
1
-
inc
)
{
count_
=
kSSizeMax
-
1
;
return
false
;
...
...
@@ -276,12 +276,12 @@ bool Buffer::IToASCII(bool sign, bool upcase, int64_t i, int base,
char
pad
,
size_t
padding
,
const
char
*
prefix
)
{
// Sanity check for parameters. None of these should ever fail, but see
// above for the rationale why we can't call CHECK().
DEBUG_CHECK
(
base
>=
2
);
DEBUG_CHECK
(
base
<=
16
);
DEBUG_CHECK
(
!
sign
||
base
==
10
);
DEBUG_CHECK
(
pad
==
'0'
||
pad
==
' '
);
DEBUG_CHECK
(
padding
<=
kSSizeMax
);
DEBUG_CHECK
(
!
(
sign
&&
prefix
&&
*
prefix
));
DEBUG_CHECK
(
base
>=
2
,
""
);
DEBUG_CHECK
(
base
<=
16
,
""
);
DEBUG_CHECK
(
!
sign
||
base
==
10
,
""
);
DEBUG_CHECK
(
pad
==
'0'
||
pad
==
' '
,
""
);
DEBUG_CHECK
(
padding
<=
kSSizeMax
,
""
);
DEBUG_CHECK
(
!
(
sign
&&
prefix
&&
*
prefix
)
,
""
);
// Handle negative numbers, if the caller indicated that |i| should be
// treated as a signed number; otherwise treat |i| as unsigned (even if the
...
...
@@ -461,7 +461,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
if
(
padding
>
max_padding
/
10
||
10
*
padding
>
max_padding
-
(
ch
-
'0'
))
{
DEBUG_CHECK
(
padding
<=
max_padding
/
10
&&
10
*
padding
<=
max_padding
-
(
ch
-
'0'
));
10
*
padding
<=
max_padding
-
(
ch
-
'0'
)
,
""
);
// Integer overflow detected. Skip the rest of the width until
// we find the format character, then do the normal error handling.
padding_overflow
:
...
...
@@ -479,7 +479,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
// kSSizeMax gets smaller than about 10, our earlier range checks
// are incomplete. Unittests do trigger this artificial corner
// case.
DEBUG_CHECK
(
padding
<=
max_padding
);
DEBUG_CHECK
(
padding
<=
max_padding
,
""
);
goto
padding_overflow
;
}
ch
=
*
fmt
++
;
...
...
@@ -493,14 +493,14 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
case
'c'
:
{
// Output an ASCII character.
// Check that there are arguments left to be inserted.
if
(
cur_arg
>=
max_args
)
{
DEBUG_CHECK
(
cur_arg
<
max_args
);
DEBUG_CHECK
(
cur_arg
<
max_args
,
""
);
goto
fail_to_expand
;
}
// Check that the argument has the expected type.
const
Arg
&
arg
=
args
[
cur_arg
++
];
if
(
arg
.
type
!=
Arg
::
INT
&&
arg
.
type
!=
Arg
::
UINT
)
{
DEBUG_CHECK
(
arg
.
type
==
Arg
::
INT
||
arg
.
type
==
Arg
::
UINT
);
DEBUG_CHECK
(
arg
.
type
==
Arg
::
INT
||
arg
.
type
==
Arg
::
UINT
,
""
);
goto
fail_to_expand
;
}
...
...
@@ -521,7 +521,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
case
'p'
:
{
// Output a pointer value.
// Check that there are arguments left to be inserted.
if
(
cur_arg
>=
max_args
)
{
DEBUG_CHECK
(
cur_arg
<
max_args
);
DEBUG_CHECK
(
cur_arg
<
max_args
,
""
);
goto
fail_to_expand
;
}
...
...
@@ -531,7 +531,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
if
(
ch
!=
'p'
)
{
// Check that the argument has the expected type.
if
(
arg
.
type
!=
Arg
::
INT
&&
arg
.
type
!=
Arg
::
UINT
)
{
DEBUG_CHECK
(
arg
.
type
==
Arg
::
INT
||
arg
.
type
==
Arg
::
UINT
);
DEBUG_CHECK
(
arg
.
type
==
Arg
::
INT
||
arg
.
type
==
Arg
::
UINT
,
""
);
goto
fail_to_expand
;
}
i
=
arg
.
i
;
...
...
@@ -558,7 +558,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
arg
.
i
==
0
)
{
// Allow C++'s version of NULL
i
=
0
;
}
else
{
DEBUG_CHECK
(
arg
.
type
==
Arg
::
POINTER
||
arg
.
type
==
Arg
::
STRING
);
DEBUG_CHECK
(
arg
.
type
==
Arg
::
POINTER
||
arg
.
type
==
Arg
::
STRING
,
""
);
goto
fail_to_expand
;
}
...
...
@@ -579,7 +579,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
case
's'
:
{
// Check that there are arguments left to be inserted.
if
(
cur_arg
>=
max_args
)
{
DEBUG_CHECK
(
cur_arg
<
max_args
);
DEBUG_CHECK
(
cur_arg
<
max_args
,
""
);
goto
fail_to_expand
;
}
...
...
@@ -592,7 +592,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
arg
.
i
==
0
)
{
// Allow C++'s version of NULL
s
=
"<NULL>"
;
}
else
{
DEBUG_CHECK
(
arg
.
type
==
Arg
::
STRING
);
DEBUG_CHECK
(
arg
.
type
==
Arg
::
STRING
,
""
);
goto
fail_to_expand
;
}
...
...
@@ -631,7 +631,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, const Arg* args,
// Unknown or unsupported format character. Just copy verbatim to
// output.
buffer
.
Out
(
'%'
);
DEBUG_CHECK
(
ch
);
DEBUG_CHECK
(
ch
,
""
);
if
(
!
ch
)
{
goto
end_of_format_string
;
}
...
...
@@ -670,7 +670,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt) {
const
char
*
src
=
fmt
;
for
(;
*
src
;
++
src
)
{
buffer
.
Out
(
*
src
);
DEBUG_CHECK
(
src
[
0
]
!=
'%'
||
src
[
1
]
==
'%'
);
DEBUG_CHECK
(
src
[
0
]
!=
'%'
||
src
[
1
]
==
'%'
,
""
);
if
(
src
[
0
]
==
'%'
&&
src
[
1
]
==
'%'
)
{
++
src
;
}
...
...
src/butil/third_party/nspr/prtime.cc
View file @
6fdeeac2
...
...
@@ -81,6 +81,7 @@
#endif
#include <errno.h>
/* for EINVAL */
#include <time.h>
#include <limits.h>
/* INT_MAX */
/* Implements the Unix localtime_r() function for windows */
#if defined(OS_WIN)
...
...
src/butil/thread_local.cpp
View file @
6fdeeac2
...
...
@@ -16,9 +16,10 @@
// Date: Mon. Nov 7 14:47:36 CST 2011
#include <errno.h> // errno
#include <vector> // std::vector
#include <algorithm> // std::find
#include <pthread.h> // pthread_key_t
#include <stdio.h>
#include <algorithm> // std::find
#include <vector> // std::vector
namespace
butil
{
namespace
detail
{
...
...
src/bvar/detail/sampler.cpp
View file @
6fdeeac2
...
...
@@ -65,7 +65,6 @@ public:
}
}
~
SamplerCollector
()
{
VLOG
(
99
)
<<
"SamplerCollector is quiting"
;
if
(
_created
)
{
_stop
=
true
;
pthread_join
(
_tid
,
NULL
);
...
...
@@ -93,7 +92,6 @@ private:
};
void
SamplerCollector
::
run
()
{
VLOG
(
99
)
<<
"SamplerCollector starts to run"
;
butil
::
LinkNode
<
Sampler
>
root
;
int
consecutive_nosleep
=
0
;
PassiveStatus
<
double
>
cumulated_time
(
get_cumulated_time
,
this
);
...
...
src/bvar/recorder.h
View file @
6fdeeac2
...
...
@@ -232,24 +232,25 @@ private:
inline
IntRecorder
&
IntRecorder
::
operator
<<
(
int64_t
sample
)
{
if
(
BAIDU_UNLIKELY
((
int64_t
)(
int
)
sample
!=
sample
))
{
const
char
*
reason
=
NULL
;
if
(
sample
>
std
::
numeric_limits
<
int
>::
max
())
{
reason
=
"overflows"
;
sample
=
std
::
numeric_limits
<
int
>::
max
();
}
else
{
reason
=
"underflows"
;
sample
=
std
::
numeric_limits
<
int
>::
min
();
}
// Truncate to be max or min of int. We're using 44 bits to store the
// sum thus following aggregations are not likely to be over/underflow.
if
(
!
name
().
empty
())
{
LOG
(
WARNING
)
<<
"Input="
<<
sample
<<
" to `"
<<
name
()
<<
'\''
<<
noflush
;
<<
"
\'
"
<<
reason
;
}
else
if
(
!
_debug_name
.
empty
())
{
LOG
(
WARNING
)
<<
"Input="
<<
sample
<<
" to `"
<<
_debug_name
<<
'\''
<<
noflush
;
<<
"
\'
"
<<
reason
;
}
else
{
LOG
(
WARNING
)
<<
"Input="
<<
sample
<<
" to IntRecorder("
<<
(
void
*
)
this
<<
')'
<<
noflush
;
}
if
(
sample
>
std
::
numeric_limits
<
int
>::
max
())
{
LOG
(
WARNING
)
<<
" overflows"
;
sample
=
std
::
numeric_limits
<
int
>::
max
();
}
else
{
LOG
(
WARNING
)
<<
" underflows"
;
sample
=
std
::
numeric_limits
<
int
>::
min
();
<<
(
void
*
)
this
<<
") "
<<
reason
;
}
}
agent_type
*
agent
=
_combiner
.
get_or_create_tls_agent
();
...
...
test/Makefile
View file @
6fdeeac2
...
...
@@ -2,9 +2,9 @@ NEED_GPERFTOOLS=1
NEED_GTEST
=
1
NEED_GMOCK
=
1
include
../config.mk
CPPFLAGS
=
-DBTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
CPPFLAGS
+
=
-DBTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
CPPFLAGS
+=
-DUNIT_TEST
-Dprivate
=
public
-Dprotected
=
public
-DBVAR_NOT_LINK_DEFAULT_VARIABLES
CXXFLAGS
=
$(CPPFLAGS)
-g
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
CXXFLAGS
+
=
$(CPPFLAGS)
-g
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
#required by butil/crc32.cc to boost performance for 10x
ifeq
($(shell
test
$(GCC_VERSION)
-ge
40400;
echo
$$?),0)
...
...
test/brpc_builtin_service_unittest.cpp
View file @
6fdeeac2
...
...
@@ -8,7 +8,7 @@
#include <sys/socket.h>
#include <fstream>
#include <gtest/gtest.h>
#include <g
oogle
/gflags.h>
#include <g
flags
/gflags.h>
#include <gperftools/profiler.h>
#include <google/protobuf/descriptor.h>
#include "butil/time.h"
...
...
@@ -182,6 +182,7 @@ protected:
}
void
TestVLog
(
bool
use_html
)
{
#if !BRPC_WITH_GLOG
std
::
string
expect_type
=
(
use_html
?
"text/html"
:
"text/plain"
);
brpc
::
VLogService
service
;
brpc
::
VLogRequest
req
;
...
...
@@ -194,6 +195,7 @@ protected:
EXPECT_FALSE
(
cntl
.
Failed
());
EXPECT_EQ
(
expect_type
,
cntl
.
http_response
().
content_type
());
CheckContent
(
cntl
,
"test_builtin_service"
);
#endif
}
void
TestConnections
(
bool
use_html
)
{
...
...
test/brpc_load_balancer_unittest.cpp
View file @
6fdeeac2
...
...
@@ -218,7 +218,7 @@ void* select_server(void* arg) {
}
++
(
*
selected_count
)[
ptr
->
id
()];
}
LOG_IF
(
TRACE
,
ret
!=
0
)
<<
"select_server["
<<
pthread_self
()
LOG_IF
(
INFO
,
ret
!=
0
)
<<
"select_server["
<<
pthread_self
()
<<
"] quits before of "
<<
berror
(
ret
);
return
selected_count
;
}
...
...
test/brpc_server_unittest.cpp
View file @
6fdeeac2
...
...
@@ -1194,7 +1194,9 @@ TEST_F(ServerTest, add_builtin_service) {
if
(
brpc
::
FLAGS_enable_threads_service
)
{
TestAddBuiltinService
(
brpc
::
ThreadsService
::
descriptor
());
}
#if !BRPC_WITH_GLOG
TestAddBuiltinService
(
brpc
::
VLogService
::
descriptor
());
#endif
TestAddBuiltinService
(
brpc
::
FlagsService
::
descriptor
());
TestAddBuiltinService
(
brpc
::
VarsService
::
descriptor
());
TestAddBuiltinService
(
brpc
::
RpczService
::
descriptor
());
...
...
@@ -1247,8 +1249,10 @@ TEST_F(ServerTest, too_big_message) {
brpc
::
SERVER_DOESNT_OWN_SERVICE
));
ASSERT_EQ
(
0
,
server
.
Start
(
8613
,
NULL
));
#if !BRPC_WITH_GLOG
logging
::
StringSink
log_str
;
logging
::
LogSink
*
old_sink
=
logging
::
SetLogSink
(
&
log_str
);
#endif
brpc
::
Channel
chan
;
ASSERT_EQ
(
0
,
chan
.
Init
(
"localhost:8613"
,
NULL
));
...
...
@@ -1260,12 +1264,14 @@ TEST_F(ServerTest, too_big_message) {
stub
.
Echo
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_TRUE
(
cntl
.
Failed
());
#if !BRPC_WITH_GLOG
ASSERT_EQ
(
&
log_str
,
logging
::
SetLogSink
(
old_sink
));
std
::
ostringstream
expected_log
;
expected_log
<<
" is bigger than "
<<
brpc
::
FLAGS_max_body_size
<<
" bytes, the connection will be closed."
" Set max_body_size to allow bigger messages"
;
ASSERT_NE
(
std
::
string
::
npos
,
log_str
.
find
(
expected_log
.
str
()));
#endif
server
.
Stop
(
0
);
server
.
Join
();
...
...
test/brpc_socket_map_unittest.cpp
View file @
6fdeeac2
...
...
@@ -4,7 +4,7 @@
// Date: Sun Jul 13 15:04:18 CST 2014
#include <gtest/gtest.h>
#include <g
oogle
/gflags.h>
#include <g
flags
/gflags.h>
#include <gperftools/profiler.h>
#include "brpc/socket.h"
#include "brpc/socket_map.h"
...
...
test/bthread_id_unittest.cpp
View file @
6fdeeac2
...
...
@@ -207,7 +207,7 @@ static void* locker(void* arg) {
bthread_usleep
(
2000
);
EXPECT_EQ
(
0
,
bthread_id_unlock
(
id
));
tm
.
stop
();
LOG
(
TRACE
)
<<
"Unlocked, tm="
<<
tm
.
u_elapsed
();
LOG
(
INFO
)
<<
"Unlocked, tm="
<<
tm
.
u_elapsed
();
return
NULL
;
}
...
...
test/bthread_timer_thread_unittest.cpp
View file @
6fdeeac2
...
...
@@ -53,12 +53,8 @@ public:
_sleep_ms
=
0
;
bthread
::
futex_wake_private
(
&
_sleep_ms
,
1
);
}
else
{
LOG
(
ERROR
)
<<
"No need to wakeup "
<<
noflush
;
if
(
_name
)
{
LOG
(
ERROR
)
<<
"`"
<<
_name
<<
"' task_id="
<<
_task_id
;
}
else
{
LOG
(
ERROR
)
<<
"task_id="
<<
_task_id
;
}
LOG
(
ERROR
)
<<
"No need to wakeup "
<<
(
_name
?
_name
:
""
)
<<
" task_id="
<<
_task_id
;
}
}
...
...
test/butil_unittest_main.cpp
View file @
6fdeeac2
...
...
@@ -33,6 +33,8 @@ int main(int argc, char** argv) {
core_limit
.
rlim_max
=
0
;
setrlimit
(
RLIMIT_CORE
,
&
core_limit
);
}
#if !BRPC_WITH_GLOG
CHECK
(
!
google
::
SetCommandLineOption
(
"crash_on_fatal_log"
,
"true"
).
empty
());
#endif
return
RUN_ALL_TESTS
();
}
test/bvar_reducer_unittest.cpp
View file @
6fdeeac2
...
...
@@ -192,6 +192,7 @@ void ReducerTest_window() {
bvar
::
Window
<
bvar
::
Miner
<
int
>
>
w8
(
&
c3
,
2
);
bvar
::
Window
<
bvar
::
Miner
<
int
>
>
w9
(
&
c3
,
3
);
#if !BRPC_WITH_GLOG
logging
::
StringSink
log_str
;
logging
::
LogSink
*
old_sink
=
logging
::
SetLogSink
(
&
log_str
);
c2
.
get_value
();
...
...
@@ -200,6 +201,7 @@ void ReducerTest_window() {
"You should not call Reducer<int, bvar::detail::MaxTo<int>>"
"::get_value() when a Window<> is used because the operator"
" does not have inverse."
));
#endif
const
int
N
=
6000
;
int
count
=
0
;
int
total_count
=
0
;
...
...
@@ -233,6 +235,7 @@ void ReducerTest_window() {
}
TEST_F
(
ReducerTest
,
window
)
{
#if !BRPC_WITH_GLOG
ReducerTest_window
();
logging
::
StringSink
log_str
;
logging
::
LogSink
*
old_sink
=
logging
::
SetLogSink
(
&
log_str
);
...
...
@@ -241,6 +244,7 @@ TEST_F(ReducerTest, window) {
if
(
log_str
.
find
(
"Removed "
)
!=
std
::
string
::
npos
)
{
ASSERT_NE
(
std
::
string
::
npos
,
log_str
.
find
(
"Removed 3, sampled 0"
))
<<
log_str
;
}
#endif
}
struct
Foo
{
...
...
test/bvar_sampler_unittest.cpp
View file @
6fdeeac2
...
...
@@ -51,8 +51,10 @@ private:
int
DebugSampler
::
_s_ndestroy
=
0
;
TEST
(
SamplerTest
,
single_threaded
)
{
#if !BRPC_WITH_GLOG
logging
::
StringSink
log_str
;
logging
::
LogSink
*
old_sink
=
logging
::
SetLogSink
(
&
log_str
);
#endif
const
int
N
=
100
;
DebugSampler
*
s
[
N
];
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
...
...
@@ -69,11 +71,13 @@ TEST(SamplerTest, single_threaded) {
}
usleep
(
1010000
);
EXPECT_EQ
(
N
,
DebugSampler
::
_s_ndestroy
);
#if !BRPC_WITH_GLOG
ASSERT_EQ
(
&
log_str
,
logging
::
SetLogSink
(
old_sink
));
if
(
log_str
.
find
(
"Removed "
)
!=
std
::
string
::
npos
)
{
ASSERT_NE
(
std
::
string
::
npos
,
log_str
.
find
(
"Removed 0, sampled 100"
));
ASSERT_NE
(
std
::
string
::
npos
,
log_str
.
find
(
"Removed 100, sampled 0"
));
}
#endif
}
void
*
check
(
void
*
)
{
...
...
@@ -94,8 +98,10 @@ void* check(void*) {
}
TEST
(
SamplerTest
,
multi_threaded
)
{
#if !BRPC_WITH_GLOG
logging
::
StringSink
log_str
;
logging
::
LogSink
*
old_sink
=
logging
::
SetLogSink
(
&
log_str
);
#endif
pthread_t
th
[
10
];
DebugSampler
::
_s_ndestroy
=
0
;
for
(
size_t
i
=
0
;
i
<
arraysize
(
th
);
++
i
)
{
...
...
@@ -106,10 +112,12 @@ TEST(SamplerTest, multi_threaded) {
}
sleep
(
1
);
EXPECT_EQ
(
100
*
arraysize
(
th
),
(
size_t
)
DebugSampler
::
_s_ndestroy
);
#if !BRPC_WITH_GLOG
ASSERT_EQ
(
&
log_str
,
logging
::
SetLogSink
(
old_sink
));
if
(
log_str
.
find
(
"Removed "
)
!=
std
::
string
::
npos
)
{
ASSERT_NE
(
std
::
string
::
npos
,
log_str
.
find
(
"Removed 0, sampled 1000"
));
ASSERT_NE
(
std
::
string
::
npos
,
log_str
.
find
(
"Removed 1000, sampled 0"
));
}
#endif
}
}
// namespace
test/class_name_unittest.cpp
View file @
6fdeeac2
...
...
@@ -24,7 +24,7 @@ protected:
TEST_F
(
ClassNameTest
,
demangle
)
{
ASSERT_EQ
(
"add_something"
,
butil
::
demangle
(
"add_something"
));
ASSERT_EQ
(
"guard variable for butil::my_ip()::ip"
,
butil
::
demangle
(
"_ZGVZN
4base
5my_ipEvE2ip"
));
butil
::
demangle
(
"_ZGVZN
5butil
5my_ipEvE2ip"
));
ASSERT_EQ
(
"dp::FiberPBCommand<proto::PbRouteTable, proto::PbRouteAck>::marshal(dp::ParamWriter*)::__FUNCTION__"
,
butil
::
demangle
(
"_ZZN2dp14FiberPBCommandIN5proto12PbRouteTableENS1_10PbRouteAckEE7marshalEPNS_11ParamWriterEE12__FUNCTION__"
));
ASSERT_EQ
(
"7&8"
,
butil
::
demangle
(
"7&8"
));
...
...
test/file_watcher_unittest.cpp
View file @
6fdeeac2
...
...
@@ -23,7 +23,6 @@ TEST_F(FileWatcherTest, random_op)
for
(
int
i
=
0
;
i
<
30
;
++
i
)
{
if
(
rand
()
%
2
)
{
LOG
(
INFO
)
<<
"watch: "
<<
noflush
;
const
butil
::
FileWatcher
::
Change
ret
=
fw
.
check_and_consume
();
switch
(
ret
)
{
case
butil
:
:
FileWatcher
::
UPDATED
:
...
...
@@ -39,7 +38,6 @@ TEST_F(FileWatcherTest, random_op)
LOG
(
INFO
)
<<
fw
.
filepath
()
<<
" does not change or still not exist"
;
break
;
}
LOG
(
INFO
);
}
switch
(
rand
()
%
2
)
{
...
...
test/logging_unittest.cc
View file @
6fdeeac2
...
...
@@ -9,9 +9,11 @@
#include <gtest/gtest.h>
#include <gflags/gflags.h>
#if !BRPC_WITH_GLOG
namespace
logging
{
DECLARE_bool
(
crash_on_fatal_log
);
DECLARE_int32
(
v
erbose
);
DECLARE_int32
(
v
);
namespace
{
...
...
@@ -52,10 +54,10 @@ public:
}
virtual
void
TearDown
()
{
::
logging
::
FLAGS_crash_on_fatal_log
=
_old_crash_on_fatal_log
;
if
(
::
logging
::
FLAGS_v
erbose
!=
0
)
{
if
(
::
logging
::
FLAGS_v
!=
0
)
{
// Clear -verbose to avoid affecting other tests.
ASSERT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose
"
,
"0"
).
empty
());
ASSERT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
""
).
empty
());
ASSERT_FALSE
(
google
::
SetCommandLineOption
(
"v"
,
"0"
).
empty
());
ASSERT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
""
).
empty
());
}
}
private
:
...
...
@@ -203,7 +205,7 @@ TEST_F(LoggingTest, DebugLoggingReleaseBehavior) {
TEST_F
(
LoggingTest
,
DcheckStreamsAreLazy
)
{
MockLogSource
mock_log_source
;
EXPECT_CALL
(
mock_log_source
,
Log
()).
Times
(
0
);
#if DCHECK_IS_ON
#if DCHECK_IS_ON
()
DCHECK
(
true
)
<<
mock_log_source
.
Log
();
DCHECK_EQ
(
0
,
0
)
<<
mock_log_source
.
Log
();
#else
...
...
@@ -218,27 +220,27 @@ TEST_F(LoggingTest, DcheckStreamsAreLazy) {
TEST_F
(
LoggingTest
,
Dcheck
)
{
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
// Release build.
EXPECT_FALSE
(
DCHECK_IS_ON
);
EXPECT_FALSE
(
DCHECK_IS_ON
()
);
EXPECT_FALSE
(
DLOG_IS_ON
(
DCHECK
));
#elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
// Release build with real DCHECKS.
SetLogAssertHandler
(
&
LogSink
);
EXPECT_TRUE
(
DCHECK_IS_ON
);
EXPECT_TRUE
(
DCHECK_IS_ON
()
);
EXPECT_FALSE
(
DLOG_IS_ON
(
DCHECK
));
#else
// Debug build.
SetLogAssertHandler
(
&
LogSink
);
EXPECT_TRUE
(
DCHECK_IS_ON
);
EXPECT_TRUE
(
DCHECK_IS_ON
()
);
EXPECT_TRUE
(
DLOG_IS_ON
(
DCHECK
));
#endif
EXPECT_EQ
(
0
,
log_sink_call_count
);
DCHECK
(
false
);
EXPECT_EQ
(
DCHECK_IS_ON
?
1
:
0
,
log_sink_call_count
);
EXPECT_EQ
(
DCHECK_IS_ON
()
?
1
:
0
,
log_sink_call_count
);
DPCHECK
(
false
);
EXPECT_EQ
(
DCHECK_IS_ON
?
2
:
0
,
log_sink_call_count
);
EXPECT_EQ
(
DCHECK_IS_ON
()
?
2
:
0
,
log_sink_call_count
);
DCHECK_EQ
(
0
,
1
);
EXPECT_EQ
(
DCHECK_IS_ON
?
3
:
0
,
log_sink_call_count
);
EXPECT_EQ
(
DCHECK_IS_ON
()
?
3
:
0
,
log_sink_call_count
);
}
TEST_F
(
LoggingTest
,
DcheckReleaseBehavior
)
{
...
...
@@ -312,11 +314,11 @@ TEST_F(LoggingTest, log_at) {
TEST_F
(
LoggingTest
,
vlog_sanity
)
{
::
logging
::
FLAGS_crash_on_fatal_log
=
false
;
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose
"
,
"1"
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v"
,
"1"
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"logging_unittest=1"
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"logging_UNITTEST=2"
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
...
...
@@ -332,7 +334,7 @@ TEST_F(LoggingTest, vlog_sanity) {
VLOG_NE
(
0
)
<<
"always on"
;
EXPECT_EQ
(
"always on"
,
LOG_STREAM
(
INFO
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"logging_unittest=0"
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
VLOG_NE
(
i
)
<<
"vlog "
<<
i
;
...
...
@@ -340,7 +342,7 @@ TEST_F(LoggingTest, vlog_sanity) {
EXPECT_EQ
(
""
,
LOG_STREAM
(
VERBOSE
).
content_str
());
EXPECT_EQ
(
"vlog 0"
,
LOG_STREAM
(
INFO
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"logging_unittest=0,logging_unittest=1"
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
VLOG_NE
(
i
)
<<
"vlog "
<<
i
;
...
...
@@ -348,7 +350,7 @@ TEST_F(LoggingTest, vlog_sanity) {
EXPECT_EQ
(
"vlog 1"
,
LOG_STREAM
(
VERBOSE
).
content_str
());
EXPECT_EQ
(
"vlog 0"
,
LOG_STREAM
(
INFO
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"logging_unittest=1,logging_unittest=0"
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
VLOG_NE
(
i
)
<<
"vlog "
<<
i
;
...
...
@@ -356,14 +358,14 @@ TEST_F(LoggingTest, vlog_sanity) {
EXPECT_EQ
(
""
,
LOG_STREAM
(
VERBOSE
).
content_str
());
EXPECT_EQ
(
"vlog 0"
,
LOG_STREAM
(
INFO
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
""
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
""
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
VLOG_NE
(
i
)
<<
"vlog "
<<
i
;
}
EXPECT_EQ
(
"vlog 1"
,
LOG_STREAM
(
VERBOSE
).
content_str
());
EXPECT_EQ
(
"vlog 0"
,
LOG_STREAM
(
INFO
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"logg?ng_*=2"
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
VLOG_NE
(
i
)
<<
"vlog "
<<
i
;
...
...
@@ -371,7 +373,7 @@ TEST_F(LoggingTest, vlog_sanity) {
EXPECT_EQ
(
"vlog 1vlog 2"
,
LOG_STREAM
(
VERBOSE
).
content_str
());
EXPECT_EQ
(
"vlog 0"
,
LOG_STREAM
(
INFO
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
"foo=3,logging_unittest=3, logg?ng_*=2 , logging_*=1 "
).
empty
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
VLOG_NE
(
i
)
<<
"vlog "
<<
i
;
...
...
@@ -385,7 +387,7 @@ TEST_F(LoggingTest, vlog_sanity) {
EXPECT_EQ
(
"vlog 1vlog 3"
,
LOG_STREAM
(
VERBOSE
).
content_str
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
"vmodule"
,
"foo/bar0/0=2,foo/bar/1=3, 2=4, foo/*/3=5, */ba?/4=6,"
"/5=7,/foo/bar/6=8,foo2/bar/7=9,foo/bar/8=9"
).
empty
());
VLOG2_NE
(
"foo/bar/0"
,
2
)
<<
" vlog0"
;
...
...
@@ -461,8 +463,8 @@ TEST_F(LoggingTest, debug_level) {
DLOG
(
NOTICE
)
<<
foo
(
&
run_foo
);
DLOG
(
DEBUG
)
<<
foo
(
&
run_foo
);
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose_
module"
,
""
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v
erbose
"
,
"1"
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"vmodule"
,
""
).
empty
());
EXPECT_FALSE
(
google
::
SetCommandLineOption
(
"v"
,
"1"
).
empty
());
DVLOG
(
1
)
<<
foo
(
&
run_foo
);
DVLOG2
(
"a/b/c"
,
1
)
<<
foo
(
&
run_foo
);
...
...
@@ -522,3 +524,4 @@ TEST_F(LoggingTest, limited_logging) {
}
// namespace
}
// namespace logging
#endif
test/rand_util_unittest.cc
View file @
6fdeeac2
...
...
@@ -209,10 +209,10 @@ TEST(RandUtilTest, fast_rand_perf) {
}
tm
.
stop
();
LOG
(
INFO
)
<<
"Each fast_rand_less_than took "
<<
tm
.
n_elapsed
()
/
kTestIterations
<<
" ns, "
<<
s
<<
noflush
;
<<
" ns, "
#if !defined(NDEBUG)
LOG
(
INFO
)
<<
" (debugging version)"
;
<<
" (debugging version)"
;
#else
LOG
(
INFO
)
;
;
#endif
}
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