Investigate Android Logcat Process exit reason

Source: Internet
Author: User

The problem is that the final logcat process exits because the log buffer size setting is too small, the default size is 256KB, the buffer size is set to 4MB, and there is no logcat interrupt after the event Modified code on a line, but this cause of the investigation process is not easy, here record 121, test colleagues in android 8.0 platform version often encountered Logcat process exit, resulting in grasping the logcat information is not complete, to the analysis of positioning problems caused inconvenience ; 2, based on the occurrence of this, to analyze the possibility of logcat process exit;  One, when the logcat process is interrupted, the program that listens to Logcat process shows exit code[1];    Sometimes "unexpected eof" is displayed in the CMD terminal window, viewing logcat.cpp related code,    See is the LOGCAT process in the while loop Android_logger_ List_read the data read to the 0,&NBSP;&NBSP;&NBSP;LOGCAT process to invoke the Logcat_panic process actively, logcat process exits.    two, and then try to track the LOGCAT process read the data code process, and finally found that the associated content is quite a lot of,  have Liblog, Libsysutils, LOGD, mainly these three modules;  The biggest difficulty in analyzing this kind of problem is that when the logcat process exits, there is no relevant logcat information, it is difficult to see the cause of the problem,  only own the DUP redirection standard input output or the log Print kmsg module;  Finally, based on the debug information added and the print log confirmation, the;        analysis of the buffer size is as follows: 1,    In applications or services such as process   write to LOGD log is too large (greater than the buffer size setting of twice times), LOGD will call Kickme function, which will judge the stats size that the actual size of the system to occupy, When the default buffer size (64KB) is greater than twice times as we set in the Init function, Logd thinks that reader reads the data too slowly, and will actively release_locked the function to attempt to disconnect, disconnect the connectedThe logd.reader.per thread will cause a while loop break to exit, and the Logd.cpp -> kickme function part code: VOID&NBSP;LOGBUFFER::KICKME ( Logtimeentry* me, log_id_t id, unsigned long prunerows)  {     if  (stats.sizes (ID)  >  (2 * log_buffer_size (ID)))  {  // + 100%        // a misbehaving or slow reader  has its connection        // dropped if  we hit too much memory pressure.         me->release_locked ();         2, After the logd.reader.per thread exits, the socketlistener::release,logd of the SocketListener listener class that is called is inherited from SocketListener, and the LogReader The Decref function associated with dosocketdelete,socketclient is called, and     mrefcount-is called to the ~socketclient destructor when the value is reduced. After the destructor is called Close (msocket)   Close socket connection on SocketListener side,   3, socketAfter the socket connection of the listener is open, the Read function in LogReader is not reading the data, and the return value of 0,logreader is to pass the log to Logcatbool logreader:--ondataavailable : ondataavailable (SOCKETCLIENT*&NBSP;CLI)  {    static bool name_set;     if  (!name_set)  {        prctl (Pr_set_name,   "Logd.reader");        name_set = true;     }     char buffer[255];     int len  = read (Cli->getsocket (),  buffer, sizeof (buffer)  - 1);     if  (len <= 0)  {         android:: Prdebug ("logreader->ondataavailable ,length:%d !\n",  len);         dosocketdelete (CLI);        return false;     } 4, and then will guideThe return value of the recv function of the Logdread to the Liblog module is 0 (omit part transport related process, there are some conversion steps), Static int logdread (struct  ANDROID_LOG_LOGGER_LIST*&NBSP;LOGGER_LIST,&NBSP;&NBSP;RET&NBSP;=&NBSP;RECV (Ret, log_msg, logger_ entry_max_len, 0);   e = errno;  fprintf (stderr,  "LogdRead ()->  receive  ret :%d   ^^ ^^ ^^ ^^ ^^ ^\n ", ret)   5, a while loop that leads to the final logcat-side process Android_ Logger_list_read the data read to the 0,LOGCAT process to invoke the Logcat_panic process actively, logcat process exits.     while  (!context->stop &&             (!context->maxcount | |   (Context->printcount < context->maxcount))  {         struct log_msg log_msg;        int  Ret = android_logger_list_read (logger_list, &log_msg);         if (!ret)  {              fprintf ( stderr,  "android_logger_list_read error ,ret:%d !\n",  ret);             logcat_panic (context, help_false,  "read:  unexpected eof!\n ");            break;         }


Investigate Android Logcat Process exit reason

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.