Commit graph

61 commits

Author SHA1 Message Date
Mark Salyzyn
5768d3d976 liblog: logprint supports number of seconds time event field
Add s to report time in seconds.  The time could be a period, duration
or monotonic, expanded to seconds, minutes, hours and days.  gTest has
to acquire a dynamic tag allocation as there are no users of this
feature yet.

Looking to the future, audio media logging has binary content similar
to the binary events structures Android logging uses and they have
a definition of a duration field in their internal binary logging, so
may be of use when we unify the logs.

Test: gTest logcat-unit-tests --gtest_filter=*.descriptive
Bug: 31456426
Change-Id: I262c03775983b3bc7b1b00227ce2bb2b0f357bec
2017-04-14 12:54:25 -07:00
Mark Salyzyn
2ed51d708e liblog: specify clang format
Switch coding style to match

SideEffects: None
Test: compile
Bug: 27405083
Change-Id: Id426d5c5e3b18f2ceec22b31bbc9781aabf6bcca
2017-03-09 09:36:19 -08:00
Mark Salyzyn
b1d150bc42 liblog: logprint, error return and truncated data
android_log_processBinaryLogBuffer and android_log_processLogBuffer
error return should have message and messageLen fields set to zero,
or to a valid-but-truncated buffer so that we can discern the
difference.  This will resolve an issue with reporting content from
an uninitialized field in liblogcat should caller add --debug flag.

To enhance the debugging capability, truncated string events because
of the logger limits are provided rather than dropping the field, but
still with an error return.

Some minor coding style issues resolved. Add required, or remove
extraneous spaces.  Use C-style comments only.

Test: gtest liblog-unit-tests
Bug: 27405083
Bug: 35326290
Change-Id: I4a7ddd7278fb1c582f921e1ba10e0765fadb791b
2017-03-03 11:10:11 -08:00
Mark Salyzyn
8dcd94b2cd liblog: logprint followup
Add comment and braces to add maintenance clarity.

Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: Ie25b42faba19ae3cf52d4c6cefc4fc539ec23e79
2017-02-22 14:16:31 -08:00
Mark Salyzyn
62d0d2d683 liblog: add logprint to host build
- cleanup of some style issues
- resolve a few minor bugs
- add -lrt for host so that clock_gettime can be issued
- enable write-only logging, logprint and event list
  handling tests for host consumption.

NB: CtsLiblogTestCases_list is only outlet for host testing of
    the interfaces, but it is not part of any automated testing

Test: gTest liblog-unit-tests, liblog-benchmarks and
      CtsLiblogTestCases_list && build mmma system/core/liblog
Bug: 27405083
Change-Id: I13db1f45f67569407587a5a909248de33809b8cf
2017-02-08 13:37:44 -08:00
Mark Salyzyn
9b4d7e1c38 logcat: test: inject() tuning
Add a hidden -v nsec flag to logcat (actually logprint in liblog.so)
so that we can do more exacting tests of logcat.tail_time.  Halve the
spam pressure of logcat.tail_* in inject() routine, and give us a few
more retries at the higher counts.  Add instrumentation to
logcat.logrotate failures.  Add inject for logcat.year test.

Test: gTest logcat-unit-tests
Bug: 34454772
Change-Id: If6f3bd21892c8a2b9ccee8c8bbf592a1ae0b2a57
2017-01-30 15:42:56 -08:00
Mark Salyzyn
538bc12c08 logcat: add hidden --debug flag and cleanup
Allow us to debug corrupted log messages. Fix liblog to propagate
errors correctly and repair a gtest that failed.

Test: liblog-unit-tests --gtest_filter=liblog.__android_log_bswrite_and_print___max
      logcat -b events --debug -t 50
Bug: 32903864
Change-Id: Ib4eb9f466777cd23b8b54728d36354590d07869a
2016-11-16 15:46:42 -08:00
Mark Salyzyn
1a57ae3a7d liblog: logprint: report truncated event log contents if error
We need to accept that a log tag can contain no payload.  For those
that are corrupted, and to aid debugging, report what we did manage
to interpret.  Report last character as a ! for corruption, and ^
for truncation.  Fix a few Android Coding standard issues.

Test: gTest logcat-unit-tests
Bug: 32903864
Change-Id: Id11bef3a7b6569305c51701dd66c45d2038d6628
2016-11-15 14:46:34 -08:00
Mark Salyzyn
4fd0507b20 liblog: logcat: logprint support -v descriptive
Expand logprint feature to pull out the log tag description
fields, parse them and merge into the logging content.  Add
-v descriptive, -v colour(british, hidden) and -v help. Also
added a unit test for the descriptive format borrowing from
event tags that have been unchanged since 2009.

Had to add -v help because we have too many undocumented
formats and format adverbs.

Test: gTest logcat-unit-tests --gtest_filter=logcat.descriptive
Bug: 31456426
Change-Id: I93a1c003b7a3f4c332544946fdedb7277919cec3
2016-11-04 15:22:52 -07:00
Mark Salyzyn
aeaaf81c2c liblog: logd: logcat: Split out log/logger.h into public and private.
log/logger.h pieces moved into log/log.h.  Correct for some
minor Android Coding standards.

Test: gTests liblog-unit-tests, logd-unit-tests and logcat-unit-tests
Bug: 19235719
Bug: 26552300
Bug: 31289077
Bug: 31456426
Change-Id: I0a19fd8788eec20a582e72e4c62c04534bdb1b9a
2016-10-24 11:12:49 -07:00
Mark Salyzyn
37c9451349 system/core: drop or replace log/logger.h
debuggerd does not require log/logger.h, can use android/log.h
In some cases, mark why log/logger.h was required.

Test: Compile and boot smoke test
Bug: 26552300
Bug: 31289077
Bug: 31456426
Change-Id: Ia34987e25a01d81971ec8d785415f732b8376c4f
2016-10-04 09:09:10 -07:00
Mark Salyzyn
807e40ecc9 liblog: logd: Add android_lookupEventTag_len()
Allows us to mitigate the impact of MAP_PRIVATE and copy on write by
calling android_lookupEventTag_len instead of android_lookupEventTag,
and delaying the copy on write impact to the later.  We return a
string length in a supplied location along with the string pointer
with android_lookupEventTag_len(const EventTagMap* map, size_t* len,
int tag).  The string is not guaranteed to be nul terminated.  Since
android_lookupEventTag() called even once can cause the memory
impact, we will mark it as deprecated, but we currently have no
timeframe for removal since this is a very old interface.

Add an API for __android_log_is_loggable_len() that accepts the non
null terminated content and fixup callers that would gain because the
length is known prior to the call either in the compiler or at
runtime.  Tackle transition to android_lookupEventTag_len() and
fixup callers.

On any application that performs logging (eg: com.android.phone)

/proc/<pid>/smaps before:

xxxxxxxxxx-xxxxxxxxxx rw-p 00000000 fd:00 463 /system/etc/event-log-tags
Size:                 20 kB
Rss:                  20 kB
Pss:                   1 kB
Shared_Clean:          0 kB
Shared_Dirty:         20 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:            20 kB
AnonHugePages:         0 kB
Swap:                  0 kB
SwapPss:               0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:                0 kB
VmFlags: rd wr mr mw me ac

/proc/<pid>/smaps after:

xxxxxxxxxx-xxxxxxxxxx rw-p 00000000 fd:00 1773 /system/etc/event-log-tags
Size:                 20 kB
Rss:                  20 kB
Pss:                   1 kB
Shared_Clean:         20 kB  (was 0kB)
Shared_Dirty:          0 kB  (was 20kB)
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:           20 kB  (was 0kB)
Anonymous:             0 kB  (was 20kB)
AnonHugePages:         0 kB
Swap:                  0 kB
SwapPss:               0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:                0 kB
VmFlags: rd wr mr mw me ac

Added liblog-unit-tests --gtest_filter=liblog.event_log_tags to
check for Shared_Clean: to not be 0 and Anonymous: to be 0 for
all processes referencing event-log-tags.  Which can include multiple
references to /system/etc/event-log-tags and future possible refs to
/data/misc/logd/event-log-tags and /dev/event-log-tags.  We want
failure messages to help point to errant code using the deprecated
interface.

This change saves 1/4MB of memory or more on a typical system.

Test: gTest liblog-unit-tests
Bug: 31456426
Change-Id: I9e08e44d9092bd96fe704b5709242e7195281d33
2016-10-03 11:08:34 -07:00
Mark Salyzyn
6584d0a35a liblog: Replace log/log.h with android/log.h
Move all liblog related content into android/log.h, and make
log/log.h points to android/log.h.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I858e0ebe047b86f2a8530a99bc9c380d3d58edbb
2016-09-30 12:47:05 -07:00
Mark Salyzyn
a166708d15 liblog: logcat: Replace log/logd.h with log/log.h
Should use log/log.h and in some cases android/log.h instead. Can
not remove file because still in use by partners, so log/logd.h
points to log/log.h.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I3580d46154617abb7231027a44f4ab9ee023febf
2016-09-30 12:47:05 -07:00
Mark Salyzyn
305374cf0f logger: validate hdr_size field in logger entry
- check hdr_size to make sure it is in the expected range
  from sizeof entry_v1 to entry (entry_v4).
- alter msg() method to report NULL on invalid hdr_size
- alter all users of msg() method.

Bug: 30947841
Change-Id: I9bc1740d7aa9f37df5be966c18de1fb9de63d5dd
2016-08-23 14:51:50 -07:00
Mark Salyzyn
78786da116 liblog: O_CLOEXEC flag on opens
Bug: 28455828
Change-Id: Ic00101a6192aab7271cb0c3461e249a77d7f29ed
2016-04-29 07:52:36 -07:00
William Roberts
8a5b9caaa6 liblog: remove android_ids and replace with getpwuid
Note: This code makes the assumption that getpwuid is
thread safe, which it is ONLY ON BIONIC. Thus,
if you attempt to use this on a non-target build, you
may get burned. Thus, an ifndef checking on __BIONIC__
is used to produce a build error if you attempt to do
so.

Change-Id: I61038c428b71771edcfc76f18d8fc5cbe349238b
Bug: 27999086
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-04-11 14:55:56 +00:00
Mark Salyzyn
abdb758ef6 Merge "liblog: logprint: deal with malformed log messages" 2016-03-24 19:20:29 +00:00
Mark Salyzyn
018a96d03f liblog: split out transports into separate files
Create config_logger, logger and logger_read to house the log
interfaces. Add fake_logger, logd_logger and pmsg_logger to
house the write and read transports. Allows for an easier and
direct path to add new transports to the library.

SideEffects: None, logger benchmark performance unaffected

Bug: 27176738
Bug: 27405083
Change-Id: I01b38637334a5242905c8c89f6ab0a92e2540008
2016-03-22 13:01:15 -07:00
Mark Salyzyn
083c53462a liblog: logprint: deal with malformed log messages
Try to print as much content as possible should the application
logging only submit content as part of a tag with an empty message.
We search for the first non-printable ascii character in the tag, in
order to split it up for printing.

Applications (such as com.yahoo.mobile.client.android.weather) that
malform their log messages will no longer be punished by truncating
the content, but this should never be considered advocacy for their
bad behavior.

Bug: 27585978
Change-Id: Idb0680e8d6a6ad2bef5150661905acccb5b70afb
2016-03-21 23:06:29 +00:00
Mark Salyzyn
2f83d679dd liblog: truncate logtags that overflow prefixBuf
Bug: 27585978
Change-Id: If2f45e8787b05b46491a771702746cfc248b9ccd
2016-03-14 09:12:24 -07:00
Mark Salyzyn
be1d3c21b5 liblog: audit declare LIBLOG_ABI_PUBLIC
- replace <sys/cdefs.h> with local "log_cdefs.h" which
  fortifies and expands definitions, adding LIBLOG_ABI_PUBLIC,
  LIBLOG_HIDDEN, LIBLOG_ABI_PRIVATE and LIBLOG_WEAK.
- clearly tag each interface as LIBLOG_ABI_PUBLIC, LIBLOG_HIDDEN,
  LIBLOG_ABI_PRIVATE, LIBLOG_WEAK or static depending on scope
- Add -fvisibility=hidden to ensure nothing else leaks
- some code standard adjustments

Bug: 27566046
Change-Id: Ic14033c4e6d833d973beb035ddc1c6134fb35a3f
2016-03-10 13:49:38 -08:00
Mark Salyzyn
7cc8013e37 liblog: fix android_log_printLogLine empty event string
Allow _one_ empty line to get through before evaluating
further. Add __android_log_bswrite testing for content
and contentless cases; checking for propagation and for
expected printing. As for printing which is fixed here,
security variants cover the same code paths as the events.

Bug: 26646213
Change-Id: I484718aa604e0a00afde4c34a00e87468ea93aa5
2016-01-20 14:15:19 -08:00
Mark Salyzyn
7bc8023857 liblog: logprint security ANDROID_LOG_WARN
Bug: 26029733
Change-Id: I4f0cffc0a45819fb48807bf06ce336316276369d
2015-12-11 12:37:22 -08:00
Mark Salyzyn
2aa510e8b4 liblog: logprint use uid name if length less then 5
Bug: 25996918
Change-Id: Id882978b7b0b439e39bedeafc39edf80892f0317
2015-12-09 08:12:07 -08:00
Mark Salyzyn
90e7af30a5 liblog: logprint add uid format modifier
Bug: 25996918
Change-Id: Idff5e080fc5c7b69e0c45d3f596eb9d632451cbd
2015-12-09 08:12:07 -08:00
Mark Salyzyn
d7bcf40ee6 liblog: print message payload of zero length
logcat will crash if the log message payload is of zero length. Side
effect of possible log messages from LogKlog in eng and userdebug
builds, or lower level logging calls.

NB: The referenced bug cited an example of this native crash, this
    does not fix the problem cited in the bug about the
    com.android.music shutdown.

Bug: 25774695
Change-Id: I5c7a6ad8db640ba9bc8d34fab04ba7cc2a9a426a
2015-12-07 16:14:40 -08:00
Mark Salyzyn
ba7a9a016b logd: liblog: logcat: switch to android_log_clockid() (2)
android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()

Bug: 23668800
Change-Id: I38dee773bf3844177826b03a26b03215c79a5359
2015-12-07 18:45:31 +00:00
Mark Salyzyn
9e18cdcebd Revert "logd: liblog: logcat: switch to android_log_clockid()"
This reverts commit 77b5696b1d.

Change-Id: I7711bf1a7e3f72ed29a2498d7287b725a0e624bd
2015-12-07 18:30:58 +00:00
Mark Salyzyn
77b5696b1d logd: liblog: logcat: switch to android_log_clockid()
android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()

Bug: 23668800
Change-Id: I3c4e3e6b87f6676950797f1f0e203b44c542ed43
2015-12-04 14:49:19 -08:00
Mark Salyzyn
65d5ca2001 liblog: printable do not escape tabs
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 25755153
Change-Id: I99324e751db0e1ed1eb00820e82b176b6d789249
2015-11-18 09:59:12 -08:00
Mark Salyzyn
b6bee33182 liblog: logd: support logd.timestamp = monotonic
if ro.logd.timestamp or persist.logd.timestamp are set to the value
monotonic then liblog writer, liblog printing and logd all switch to
recording/printing monotonic time rather than realtime. If reinit
detects a change for presist.logd.timestamp, correct the older entry
timestamps in place.

ToDo: A corner case condition where new log entries in monotonic time
      occur before logd reinit detects persist.logd.timestamp, there
      will be a few out-of-order entries, but with accurate
      timestamps. This problem does not happen for ro.logd.timestamp
      as it is set before logd starts.

NB: This offers a nano second time accuracy on all log entries
    that may be more suitable for merging with other system
    activities, such as systrace, that also use monotonic time. This
    feature is for debugging.

Bug: 23668800
Change-Id: Iee6dab7140061b1a6627254921411f61b01aa5c2
2015-11-03 15:15:51 -08:00
Mark Salyzyn
4cbed02e44 liblog: logcat: add epoch and monotonic format modifiers
- '-v epoch' prints seconds since Jan 1 1970
- '-v monotonic' print cpu seconds since start of device
- '-T sssss.mmm...' as alternate tail time format

NB: monotonic is a best estimate and may be out by a few ms
    given the synchronization source clue accuracy.

Bug: 23668800
Change-Id: Ieb924b6d3817669c7e53beb9c970fb626eaad460
2015-10-29 14:23:42 -07:00
Mark Salyzyn
447356ddb4 Merge "liblog: logcat: Add year and zone to date on each line" 2015-09-30 18:56:48 +00:00
Mark Salyzyn
faa92e9915 liblog: logprint: printable nul
Change-Id: I57d1f86ce040ad196c558bb72ac0464af793c214
2015-09-29 15:43:34 -07:00
Mark Salyzyn
f28f6a9ba2 liblog: logcat: Add year and zone to date on each line
- '-v year' modifier adds the four digit year prefix
- '-v <timezone>' modifier sets and prints the timezone suffix
- Only promise in logcat to support UTC as a timezone since
  all others are based on the configured environment
- '-v zone' modifier toggles the timezone suffix on or off
- '-T YYYY-MM-DD HH:MM:SS.mmm...' format is added

Bug: 23668700
Change-Id: I7521c1efb7455dc9a25434fce72a69a65dcf72ea
2015-09-24 14:49:55 -07:00
Mark Salyzyn
b932b2f8ba liblog: logcat: Add printable format modifier
- added printable format modifier:
  logcat -v printable
- opencoded borrowed individual utf8 validity checking algorithm
  from utf8_length() in libutils/Unicode.cpp
- if considered basic one-character ASCII, use popular \x escape
  sequences for non-printable
- logprint convert to C comments to drop mixed-mode

Bug: 19000361
Change-Id: I122a5b8fb41216fc0bc816178c0b768f3df56586
2015-06-04 08:27:29 -07:00
Mark Salyzyn
e1f2004ecc logcat: liblog: Add "usec" format argument
- Add additional 3 digits of time precision for time output
  adding in the reporting of usec
- Remove trailing space in header file

Change-Id: Ifb560850b8e01080e126fbaeab640db71cce3eea
2015-05-12 15:51:46 -07:00
Jeff Brown
44193d9eae Add float support to binary event log.
Bug: 20664753
Change-Id: Ib4752bd785496dab5bb4d4979d5d80f662adbdfa
2015-04-28 18:20:48 -07:00
Mark Salyzyn
8470dad24f Revert "liblog: logprint use <endian.h>"
This reverts commit 66bfc5ccbd.

Bug: 19634248
Change-Id: I7c4851a247042193674f226fd0d5c5663e8074c7
2015-03-06 20:46:31 +00:00
Mark Salyzyn
f8d62a0107 liblog: logprint use <endian.h> part deux
Change-Id: I042194d0f5ec444dd192ee9da50d6b48d556f8ac
2015-03-04 16:20:50 -08:00
Mark Salyzyn
66bfc5ccbd liblog: logprint use <endian.h>
Change-Id: I0ec0fe3e954f6f04964d58e57c817d28057b630b
2015-03-04 12:48:04 -08:00
Mark Salyzyn
e2428429e0 liblog: logcat color output corrupted on 32-bit
sizeof(suffixBuf), not sizeof(suffixLen)!

Change-Id: I6e085089237585bb8b406372639b644556747699
2015-01-22 10:00:04 -08:00
Andreas Gampe
1f742864fa Liblog: Remove unused function
For build-system CFLAGS clean-up, remove unused function.

Change-Id: I8c28c4bbbadaea6a5b32483e9e220794967bdd4e
2014-11-24 10:36:55 -08:00
Yabin Cui
8a98535bcb kill HAVE_LOCALTIME_R
Bug: 18361583
Change-Id: Icdc745a5204bba26c6438d16ed38ec791e136163
2014-11-13 10:11:23 -08:00
Pierre Zurek
ead88fca6e liblog: logcat: colored output.
This patch adds a new '-v color' option to logcat so that the output is
colored similar to the ones in DDMS. Simply type "adb logcat -v color"
to use it. Works well with bash in gnome-terminal. NO GUARANTEE IT WILL
WORK ON A NON xterm STYLE TERMINAL.

Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Change-Id: I9189c5f27fed991579edbcbc6834536eb8112152
2014-09-11 19:04:17 -07:00
Mark Salyzyn
a04464adaf liblog: set -Werror
- Deal with some -Wunused issues
- Cleanup UNUSED to __unused transition

Change-Id: Icd33808d4c974625f4fd0a126a90a2b4c90c8314
2014-05-07 16:56:21 -07:00
Mark Salyzyn
5045f57525 liblog: logcat: Move library print test into gTest
Change-Id: Icd33808d4c974625f4fd0a126a90a2b4c90c8315
2014-05-02 14:16:00 -07:00
Mark Salyzyn
40b21558e5 liblog: support struct logger_event_v2 format
(cherry picked from commit c176e14ce3)

Change-Id: I34c96adffab3478dae8f5a2597a840caad5092cc
2014-01-27 15:21:29 -08:00
Mark Salyzyn
cf4aa030ce liblog: whitespace cleanup
- change cutils to liblog directory path
- change tabs to spaces

(cherry picked from commit c1215c0b46)

Change-Id: I7d9db1e2b817ba0ec9a224340c5c7535a2387fd5
2014-01-27 15:08:42 -08:00