Rockchip 系统日志收集

rk3399 rk3288 rk3588

Posted by LXG on June 27, 2023

Firefly-Log

系统日志收集

android 7

开发者选项-系统日志收集器

src/com/android/settings/DevelopmentSettings.java


public class DevelopmentSettings extends RestrictedSettingsFragment {

    private static final String ABC_ON = "abc_on";

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        mAbcOn = (RestrictedSwitchPreference) findAndInitSwitchPref(ABC_ON);

    }

    @Override
    public boolean onPreferenceTreeClick(Preference preference) {

        //------------------------------------------------------------

        } else if (preference == mAbcOn) {
            if (SystemProperties.getInt("persist.sys.abc_switch", 0) == 1) {
                Log.d(TAG, "set persist.sys.abc_switch 0");
                mAbcOn.setChecked(false);
                SystemProperties.set("persist.sys.abc_switch", "0");
            } else {
                Log.d(TAG, "set persist.sys.abc_switch 1");
                mAbcOn.setEnabled(true);
                SystemProperties.set("persist.sys.abc_switch", "1");
            }
        }

        //------------------------------------------------------------

    }

}

external/abc

android 7

system/bin/abc


LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
        abc.c \
        misc.c \
        mail.c \
        hotplug.c

LOCAL_MODULE := abc
LOCAL_MODULE_TAGS := eng
LOCAL_SHARED_LIBRARIES := liblog libselinux libext2_blkid
LOCAL_CFLAGS += -Wno-error

ifeq ($(strip $(TARGET_BOARD_PLATFORM)), rk3399)
LOCAL_CFLAGS += -DTARGET_BOARD_PLATFORM_RK3399
endif
include $(BUILD_EXECUTABLE)

配置 config.h


#ifndef __CONFIG_H__
#define __CONFIG_H__

#define SYSTEM_PATH "/data/logs"              // 日志缓存路径

#define LOG_SD_PATH "/storage/"
#define LOG_FLASH_PATH  "/data/media/0";      // 日志保存位置

/* Mime subject */
#define FROM    "from@rock-chips.cn"
#define TO  "to@example.com"
#define SUBJECT "Subject Example"

/* Mail sender and recipient */
#define MAIL_SERVER "mail.XXX.cn"
#define MAIL_SENDER "from@XXX.cn"
#define MAIL_RECIPIENT  "to@example.com"

/* User name and password */
#define USER_NAME   "username@XXX.cn\n"
#define USER_PASSWORD   "userpasseord"

/*Logcat priority is one of the following character values,
 *ordered from lowest to highest priority:
 *V — Verbose (lowest priority)
 *D — Debug
 *I — Info
 *W — Warning
 *E — Error
 *F — Fatal
 *S — Silent (highest priority, on which nothing is ever printed)
 */
#define LOGCAT_PRIOR    "V"

/* Function config */
#define CONFIG_KERNEL_LOG                       // 内核日志
#define CONFIG_LOGCAT_LOG                       // android 日志
//#define CONFIG_PROCESS_LOG
//#define CONFIG_SEND_MAIL

#ifdef TARGET_BOARD_PLATFORM_RK3399
#define CONFIG_COPY_LOG_TO_FLASH
#define CONFIG_MONITOR_UEVENT
#endif

/* config all files numbers in SYSTEM_PATH
 * usually keep default configure---100
 */
#define ITERM_MAX   100                         // 最大文件个数

/* config syslog max numbers */
#define SYS_LOG_MAX 10                          // 最大日志个数

#include <cutils/log.h>
#define printf ALOGD
#define LOG_TAG "abc"
#endif

日志打开后的进程

android 7


root      2300  1     13476  2532           0 0000000000 S /system/bin/abc
root      2305  2300  7716   1800           0 0000000000 S sh
root      2306  2300  8152   2032           0 0000000000 S logcat

abc 进程启动入口

android 7

./device/rockchip/common/init.rk30board.rc


# Android bug collector
service abc /system/bin/abc
    class main
    disabled
    oneshot

on property:persist.sys.abc_switch=1
    start abc
on property:persist.sys.abc_switch=0
    stop abc

android 11


# Android bug collector
service abc /vendor/bin/abc
    class main
    disabled
    oneshot

on property:persist.abc_switch=1
    start abc
on property:persist.abc_switch=0
    stop abc

日志缓存路径

android 7

sdcard/rk_logs


.
├── anr
│   └── traces.txt.bugreport
├── bugreport.log
├── COPY-COMPLETE
├── logs
│   ├── 23-06-27-15-10-40
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-18-31
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-20-20
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-21-23
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-23-04
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-24-06
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-25-26
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-26-23
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── 23-06-27-15-27-39
│   │   ├── android
│   │   ├── kernel
│   │   └── process
│   ├── aplog
│   ├── aplogs
│   ├── events
│   │   ├── eventfile_1fecf505e55ebb2533ae
│   │   ├── eventfile_2136944940053a026b9a
│   │   ├── eventfile_2bcba580af879e494d0a
│   │   ├── eventfile_5464efcad6ee856085ad
│   │   ├── eventfile_5b3e4e38f0223d3b6931
│   │   ├── eventfile_645af322c05165ec0ddc
│   │   ├── eventfile_a4f7dd3c5391f6ae1cdf
│   │   ├── eventfile_c5a8ad2784000dcc5a92
│   │   └── eventfile_ece19f1b38e8894403e7
│   ├── history_event
│   ├── modemcrash
│   ├── stats
│   └── uuid.txt
├── pstore
│   ├── console-ramoops-0
│   └── pmsg-ramoops-0
├── recovery
│   ├── last_install
│   ├── last_kmsg
│   ├── last_kmsg.1
│   ├── last_kmsg.2
│   ├── last_kmsg.3
│   ├── last_kmsg.4
│   ├── last_kmsg.5
│   ├── last_kmsg.6
│   ├── last_kmsg.7
│   ├── last_kmsg.8
│   ├── last_locale
│   ├── last_log
│   ├── last_log.1
│   ├── last_log.2
│   ├── last_log.3
│   ├── last_log.4
│   ├── last_log.5
│   ├── last_log.6
│   ├── last_log.7
│   └── last_log.8
└── tombstones