Commit Graph

748 Commits

Author SHA1 Message Date
Dan Shi 67b7dd570f Remove vts10 related configs
Bug: 169582597
Test: build
Change-Id: I38e1e0f8e32b86ab14b905d040c1c62245a1a9e3
2020-10-06 13:52:44 -07:00
Tom Cherry 824ef9ade6 liblog: add pthread.h to vndk log/log.h
Too many vendors assume that this is included, and it's not worth the
effort to clean up.

Bug: 165825252
Test: build
Change-Id: Ib99f0de4aac64134c21c0ee09f7ea576ebd0fe9e
2020-10-06 10:33:17 -07:00
Tom Cherry 136e4f6da6 liblog: add unistd.h to vndk log/log.h
Too many vendors assume that this is included, and it's not worth the
effort to clean up.

Bug: 165825252
Test: build
Change-Id: I42fb32be7e5e3201dfc5c58734e3ef5b9251faf1
2020-10-05 12:19:15 -07:00
Tom Cherry 67e08784ed Merge "Use libcutils_headers for android_filesystem_config.h" 2020-09-21 15:29:41 +00:00
Tom Cherry a5edc0fbbc Use libcutils_headers for android_filesystem_config.h
android_filesystem_config.h is found since system/core/include is on
the include path for all projects and contains a symlink to the real
android_filesystem_config.h.  This is fragile and the below bug seeks
to remove this symlink and have users correctly depend on
libcutils_headers.

Bug: 165825252
Test: build
Change-Id: I1aad6a2e8fbe87635e97b0ac1be3414403353382
2020-09-18 22:48:42 +00:00
Tom Cherry b80d98dcf7 Add sdk_version: "minimum" to liblog_headers
There are libraries built with the NDK but bundled with the platform
that were otherwise directly including the header path.  It's better
for them to include liblog_headers instead.

Test: build
Change-Id: Icca3684ba5b2539789d30de9df840da4ade0dc67
2020-09-17 14:32:48 -07:00
Tom Cherry d11f2371e1 Remove android_lookupEventTagNum() and related code
This was introduced years ago but never gained any users.

Test: build
Merged-In: Id2deb6de1839f995970c6350a1970a872f0b51cf
Change-Id: Id2deb6de1839f995970c6350a1970a872f0b51cf
2020-08-17 18:04:00 +00:00
Tom Cherry c5282c2121 Reland: "liblog: use a blocking socket for sending messages to logd""
This reverts commit b1eb731197.

Test: post-submit failure now passes
Change-Id: Iabbd18ad8403dd30aa07dd73e42fcc5b233b0222
2020-08-12 10:51:27 -07:00
Tom Cherry cadeec102c Merge "Revert "liblog: use a blocking socket for sending messages to logd"" 2020-08-11 22:17:41 +00:00
Tom Cherry b1eb731197 Revert "liblog: use a blocking socket for sending messages to logd"
This reverts commit 4af349b072.

Reason for revert: post submit test logs too much fails after this
Bug: 163611679

Change-Id: If9939f3c9864dad67536d0c5481f662b9d07c58e
2020-08-11 22:15:09 +00:00
Tom Cherry 175366df44 liblog: remove android_lookupEventTag
This function has been marked deprecated for quite some time, has no
users, and isn't in liblog.map.txt.

Test: build
Change-Id: Ic3bf47c780b18a5d4f1e997b9265be76049fb824
2020-08-11 09:20:18 -07:00
Tom Cherry 4af349b072 liblog: use a blocking socket for sending messages to logd
liblog uses a non-blocking socket for sending messages to logd as a
performance/reliability trade-off, favoring not blocking processes
when they log over reliably tracking all logs.

This change asserts that the above is the wrong trade-off: that log
relability is more important than slight delays when logging. Further
points to consider:

1) The new logd implementation without chatty has lower latency and
less variance in its ::Log() function.
2) liblog also writes to /dev/pmsg0 and this call is already blocking.
3) Logging is already expensive and excess spam must be eliminated
regardless.

Bug: 151654749
Bug: 155922578
Bug: 160314220
Test: No messages are dropped by this socket
Change-Id: I163b7d51aa73a10978850f1868cb9fc4bf9ead1b
2020-08-10 15:56:15 -07:00
Tom Cherry 39dc221026 Query log size properties only within logd
liblog exposed __android_logger_get_buffer_size() which queries log
size properties, but that should not be a generic library function.
Logd should be the only process that queries these properties and
other processes should query the actual used log sizes from logd via
the android_logger_get_log_*_size() functions.

Also, always use 1MB for log buffer tests, instead of just on host and
various other clean up related to improper types.

Test: log buffers are correctly sized
Merged-In: I9b7c86bf58e569618737afe9097cf1c4d4e61d95
Change-Id: I9b7c86bf58e569618737afe9097cf1c4d4e61d95
2020-08-06 20:32:45 +00:00
Tom Cherry 06e111a148 Add android_logger_get_log_consumed_size() and report it in logcat
There is an existing API, android_logger_get_log_readable_size() which
historically reported the consumed amount of data for the chatty log
buffer, since consumed and readable are synonymous with that buffer
type.

With log compression, readable and consumed are not synonymous, since
the readable log size is the uncompressed log size whereas the
consumed log size is the compressed log size.

This change adds android_logger_get_log_consumed_size() which returns
the consumed log size and makes android_logger_get_log_readable_size()
return the readable log size.  Note that these values are identical if
compression is not used.

It adds both statistics to logcat:

    main: ring buffer is 1 MiB (429 KiB consumed, 817 KiB readable)
    radio: ring buffer is 1 MiB (339 KiB consumed, 715 KiB readable)
    ...

Test: logcat prints the right values with compression and chatty
Change-Id: I8b9688a987736204e2e6026e8635fbd1a5e68bb7
2020-08-05 13:43:31 -07:00
Tom Cherry 0d847fb4cb liblog: add a timeout for logd command socket operations
Add a 2s timeout for logd command socket operations:
  android_logger_clear
  android_logger_get_log_readable_size
  android_logger_get_log_size
  android_logger_set_log_size
  android_logger_get_statistics
  android_logger_get_prune_list
  android_logger_set_prune_list

That correspond to:
  logcat -c
  logcat -g
  logcat -G
  logcat -S
  logcat -p
  logcat -P

These operations should return immediately in typical circumstances,
but if logd is stuck, they would otherwise block indefinitely.  This
allows the commands to gracefully timeout instead.

Test: kill -s STOP `pidof logd`; logcat -g (and other options)
      times out appropriately
Test: logcat -g (and other options) work successfully otherwise
Change-Id: I6c4671a9b3daa4a454c0a14ae7d0b7d3b08be77a
2020-08-04 17:41:47 -07:00
Tom Cherry 001a5df898 Merge "liblog: don't cache property size values and move to own file" 2020-08-03 22:59:03 +00:00
Tom Cherry d2743ef5c9 liblog: don't cache property size values and move to own file
Don't cache the property size values since they're only queried at the
start of logd and only once during dumpstate.  Initializing
SerializedLogBuffer, which includes all of the logd queries, takes
under 100us without the cache, certainly fast enough that this cache
is unneeded.

Move these functions to their own file in preparation for removing
them from liblog.

Test: log sizes set appropriately
Change-Id: I15a2fd687dcffb4eab2f22ee0825ca86e40cdba3
2020-08-03 13:17:12 -07:00
Tom Cherry 50d021ca7b liblog: use unique log tags for is_loggable tests
Apparently these tests are run in parallel, which causes errors since
they use the same log tag.  Use unique log tags based on pid to fix
this.

Also re-enable the previously disabled tests.

Bug: 162669552
Test: run these tests 100x+ and see that they no longer fail
Change-Id: Ib20d638e5e559bca23adec479a5dcf64075e376e
2020-08-03 11:38:59 -07:00
Tom Cherry 031d433472 liblog: disable property tag tests
Disable:
liblog_global_state.is_loggable_both_set
liblog_global_state.is_loggable_tag_log_priority_only

Bug: 162633089
Bug: 162669552
Test: these tests don't run
Change-Id: I82b8e6685a321ae03374e86ffbe845608aec93b5
2020-08-03 08:27:54 -07:00
Tom Cherry f83640d65e liblog: don't use a cache for __android_log_is_debuggable()
ro.debuggable is set by init before other processes would possibly
call __android_log_is_debuggable(), so this property can be checked
once and stored without liblog's property caching mechanisms.

Test: this function returns accurately
Change-Id: Idb1e5e10e53ca809b7f9a75164a4982f39827d4e
2020-07-29 14:49:54 -07:00
Tom Cherry 3b8b444fce Merge "liblog: remove __android_logger_property_get_bool()" 2020-07-29 21:22:38 +00:00
Tom Cherry 62068bfb4a liblog: remove __android_logger_property_get_bool()
All users have been moved to other, more suitable, interfaces.

Test: build
Merged-In: Ic4eb1f0ed6e35d8d6f7e63b80546f4e8bbe163e2
Change-Id: Ic4eb1f0ed6e35d8d6f7e63b80546f4e8bbe163e2
2020-07-29 19:58:30 +00:00
Tom Cherry b4bc99e873 Run liblog and logd CTS tests in presubmit
And sort the rest of the CTS tests.

Test: these tests run
Change-Id: I8eeb7b8acac2ed658b36da8463112fe1da8437a9
2020-07-29 08:02:52 -07:00
Tom Cherry 68261eec24 logd: remove users of __android_logger_property_get_bool()
__android_logger_property_get_bool() has a clunky API and doesn't
belong in liblog, since a vast majority of liblog users will never
query this property.

Specifically
1) Replace with GetBoolProperty() when completely equivalent.
2) Remove checking if property values are 'eng' or 'svelte', since
   there's no evidence that those values were ever used.
3) Remove checking 'persist.logd.statistics' and 'ro.logd.statistics',
   since there's no evidence that those values were ever used.
4) Set ro.logd.kernel explicitly, so other processes don't need to
   replicate the defaults that logd uses.

Test: build
Change-Id: I7c37af64ba7754e839185f46da66bf077f09d9c3
2020-07-28 13:16:11 -07:00
Tom Cherry 2d451663be Cleanup for #inclusivefixit.
Test: build
Change-Id: If11a32c130367560394eccf442de95d941918073
2020-07-27 11:37:19 -07:00
Tom Cherry 0315b29497 liblog: remove faulty logic in __android_logger_valid_buffer_size
In testing, I saw that the 'main' and 'events' log buffers were set to
incorrect sizes when they were intended to be >= 4MB.  The bug is
tracked down to an invalid line in
__android_logger_valid_buffer_size():

  /* maximum memory impact a somewhat arbitrary ~3% */
  pages = (pages + 31) / 32;

There are two issues with this line:
1) That is not the right calculation for 3%.
2) `pages` is a static variable, so it repeatedly is decremented until
   reaching 1.

The consequence is that this function gives invalid results for the
first few calls, then returns true as long as the input is between
LOG_BUFFER_MIN_SIZE and LOG_BUFFER_MAX_SIZE.  That check is enough, so
the rest of this logic is removed.

Test: buffers are set to the right sizes.
Change-Id: I4d19b1d0fdbd83843d2d61a484ac083d571ef37b
2020-07-09 20:39:17 -07:00
Treehugger Robot 7382be402a Merge "Use standard colors in logcat color output" 2020-06-22 21:43:14 +00:00
Peter Kalauskas 8b477b6d10 Use standard colors in logcat color output
Previously, colors were specified from the 216 additional colors, which
typically specify an exact RGB color value. Instead, use escape codes
for standard colors (default foreground, red, green, yellow, etc.),
which are commonly adjusted by terminal emulators user preferences.

Bug: 159503129
Test: adb logcat --format color
Test: atest liblog
Change-Id: I0b10a70a76a29d896d04d6c49e716b09cb09b19a
2020-06-20 03:26:12 +00:00
Tom Cherry 34d7bd98ad liblog: fix reading pmsg
d3ecc66b9c "liblog: support extended logger_entry headers" removed
the logger_entry::msg variable and instead uses hdr_size as an offset
from logger_entry to where the message starts in parent log_msg
buffer.

In pmsg, hdr_size is not recorded and therefore uninitialized when it
was referenced, causing corruption when reading last logcat.  This
change uses sizeof(log_msg->entry) instead.

Bug: 158263230
Test: last logcat works
Change-Id: Ic01e73bf4d8ba8419cc770138565aa1210a6078b
2020-06-17 09:34:51 -07:00
Tom Cherry bd80e5678f liblog: remove unused log_time functions, inline the others
One of the reasons that logcat and logd statically include liblog is
to access the symbols in log_time.cpp, which we do not expose
otherwise.  Except for strptime(), which will be handled in a separate
CL, these symbols are either small enough to inline in the header or
unused and can be removed.

Test: logging unit tests
Change-Id: I1f8cfbb779aef79fc7d5b6d0050438fe5f0e0e2c
2020-05-18 15:40:26 -07:00
Tom Cherry 6a391e9eda liblog: remove useless #define
Neither android_logger_free nor android_logger_close exist.

Test: build
Change-Id: Ieb4d740c234b54db9278a21f07b0533c28b76baf
2020-05-12 10:44:22 -07:00
Tom Cherry f2c2746aba Remove the monotonic option for logging
This has been around for ~5 years but there has been roughly no
adoption, so remove this as we clean up the logging code.

Future efforts may track the monotonic timestamp in all cases.

Test: logging unit tests
Change-Id: I55ed565669f923988e741f6b384141bba893630d
2020-05-06 13:37:33 -07:00
Tom Cherry 20d4d23f8c liblog: mark tests as require_root: true
Some tests require root to be run, so we require_root to run all of
them.

Test: tests pass as root
Change-Id: I5b3ca4f08e41f16e81c5d5995043ab55d379a882
2020-04-30 14:39:10 -07:00
Tom Cherry 710825ce47 liblog: require root for multi_connect_dgram_socket test
Bug: 65062446
Test: multi_connect_dgram_socket is skipped for non-root
Test: multi_connect_dgram_socket passes for root
Change-Id: I610bed5987580e0c5a01952efc2e32e7d8cdf9b4
2020-04-30 14:28:13 -07:00
Tom Cherry 09eae5024e Merge "liblog: clean up log_id.h includes" 2020-04-29 18:43:15 +00:00
Tom Cherry da399f3a47 Merge "liblog: fix header copyrights" 2020-04-28 22:09:24 +00:00
Tom Cherry 3e86e250bb Merge "liblog: remove Rwlocks for logd_socket and pmsg_fd" 2020-04-28 21:10:29 +00:00
Tom Cherry dd1d42664f liblog: clean up log_id.h includes
This header is not needed in many of the places it is included.  It
contains functions that are duplicated from the <android/log.h>
header.

Test: build
Change-Id: I6ba41d596bcc956cfed13f1d3b21e023591bce0f
2020-04-28 12:34:45 -07:00
Tom Cherry b629ed9679 liblog: fix header copyrights
There is no reason to dual license this.

Test: builds
Change-Id: I93e6f75758edc32dbeeb55354cf0b1b327561716
2020-04-28 09:52:33 -07:00
Tom Cherry 7acfba274c liblog: remove Rwlocks for logd_socket and pmsg_fd
These historically used atomics to manage their lifetime.  They were
unfortunately unsafe and later replace with a RwLock.  A lock is
also problematic as it is too heavy weight for the typical use case
and implies that logging is neither async nor fork safe.

This change returns us to using atomics with two key changes:
1) compare_exchange_strong() is used instead of atomic_exchange().
   The latter has a race condition where a separate thread could have
   read the atomic value into a register, while the thread performing
   the atomic_exchange closes that FD.  The new code only changes the
   FD in the atomic if it is uninitialized.
2) Using the fact that DGRAM sockets can have connect() called on them
   multiple times, it uses a single logd_socket for the duration of
   the program.

These sockets are thread/async/fork safely created and accessed.

The one caveat is __android_log_close(), which is intended only to be
used by zygote when it is single threaded and is therefore not thread
safe.  It will close this socket and reset the underlying variable,
such that the next log message will go through the above
initialization.

Bug: 65062446
Test: logging works, logging unit tests
Test: new unit test
Change-Id: Ia4dbf7479dbe50683d124558ab2f83bff53b8f5f
2020-04-27 18:24:38 -07:00
Jooyung Han 8c2056f747 Merge "libbase/liblog: set min_sdk_version" 2020-04-27 23:00:58 +00:00
Tom Cherry efe9defc65 Merge "Don't include log/log_read.h in log/log.h" 2020-04-23 14:58:44 +00:00
Jooyung Han 3851f7e836 libbase/liblog: set min_sdk_version
Modules contributing mainline modules (APK/APEX) should set
min_sdk_version as well as apex_available.

For now setting min_sdk_version doesn't change build outputs.
But build-time checks will be added soon.

Bug: 152655956
Test: m
Change-Id: If4ff1fbc31e5be3f5611a4713ae4032aba4ee5f2
2020-04-23 23:40:14 +09:00
Treehugger Robot 7d503c5bc9 Merge changes I9f382dab,I97225d4b,Iad113f44
* changes:
  Fix doxygen links in log.h.
  Fix docs for __android_log_is_loggable.
  Fix doxygen comments for __android_log_message.
2020-04-23 04:00:22 +00:00
Dan Albert 1891b863f8 Fix doxygen links in log.h.
`@{link blah}` != `{@link blah}`. The latter defines a link to blah,
the former defines a custom group that is never closed. This was doing
really exciting things to devsite.

Most identifiers do not need to be explicitly linked. The two in the
struct do need to be for some reason (maybe typedef vs function, or
maybe because it's a struct, idk). I've left those two but removed all
the ones that work implicitly.

Test: staged to devsite
Bug: None
Change-Id: I9f382dab499abb27945d178e17ae8c810c619898
2020-04-22 17:09:21 -07:00
Dan Albert 6e0eead1df Fix docs for __android_log_is_loggable.
len is not a parameter for the function this comment was attached to.
It seems to be that the documentation was meant to apply to both
functions, so copy it and remove the incorrect parameter from the one
that does not take it.

Test: build_ndk_docs.py
Bug: None
Change-Id: I97225d4ba925a33c73b6c7f81bb7b18def363489
2020-04-22 17:09:21 -07:00
Dan Albert 9e9a35e066 Fix doxygen comments for __android_log_message.
There's a different syntax for putting the comments _after_ the
members, but IMO more readable to just move them before the member.

Test: development/tools/ndk/build_ndk_docs.py
Bug: None
Change-Id: Iad113f449f9cb0996efc4b9d184d8e5b0ed5da85
2020-04-22 17:09:17 -07:00
Tom Cherry 538bac2e97 Merge "Remove thread safety from libbase logging / liblog" 2020-04-22 23:17:57 +00:00
Tom Cherry 53d301c29b Remove thread safety from libbase logging / liblog
There are no libbase users that require thread safety for SetLogger,
SetAborter, or SetDefaultTag  and the equivalent liblog symbols are
unreleased, thus have effectively no users.

It is hard to imagine a scenario where a user would need to use these
functions in a multi-threaded program, and it is unreasonable for all
users to pay for thread safety for a vast minority of potential
scenarios. Thread safety implies less efficiency and necessarily means
that these functions are neither fork safe nor async-signal safe, and
we do have users who depend on those characteristics.

It is always possible for users of the non-thread safe versions of
these functions to build thread safe versions on top of them.  For
example, if a user needs a thread safe SetLogger(), they can use the
non-thread safe SetLogger at the start of their program to register a
logger that has its own lock and pointer to a logger function.

Bug: 119867234
Test: logging unit tests
Change-Id: I8afffec1a6957d3bda95502a4c59493e0c5049ce
2020-04-22 13:12:11 -07:00
Tom Cherry 576e83429c liblog: remove more unneeded #define's
Test: build
Change-Id: I44f1d051e5438e38d7c14f79a7e72dd18cd3df83
2020-04-20 13:17:02 -07:00