WO2021190354A1 - 一种采集追踪trace调用链的方法和电子设备 - Google Patents

一种采集追踪trace调用链的方法和电子设备 Download PDF

Info

Publication number
WO2021190354A1
WO2021190354A1 PCT/CN2021/081046 CN2021081046W WO2021190354A1 WO 2021190354 A1 WO2021190354 A1 WO 2021190354A1 CN 2021081046 W CN2021081046 W CN 2021081046W WO 2021190354 A1 WO2021190354 A1 WO 2021190354A1
Authority
WO
WIPO (PCT)
Prior art keywords
function
electronic device
time
register
identification information
Prior art date
Application number
PCT/CN2021/081046
Other languages
English (en)
French (fr)
Inventor
江利进
罗煜
李翠琴
Original Assignee
华为技术有限公司
多伦多大学理事会
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司, 多伦多大学理事会 filed Critical 华为技术有限公司
Publication of WO2021190354A1 publication Critical patent/WO2021190354A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3438Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment monitoring of user actions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
    • G06F11/3419Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment by assessing time

Definitions

  • This application relates to the field of electronic equipment, and more specifically, to a method and electronic equipment for obtaining and tracking a call chain.
  • Performance problems are usually random, uncertain, and difficult to reproduce. Based on this, a trace call chain tool that can be run frequently is needed to ensure that when a performance problem occurs, it can be automatically captured to the scene to help analysis And positioning performance issues.
  • Systrace is a performance problem analysis tool provided by the Android system. It can capture several embedded call paths in the Android system. However, this method cannot obtain a complete call path, and provides limited useful information, and cannot perform in-depth and accurate analysis of performance problems.
  • This application provides a method and electronic device for collecting and tracking trace call chains, which is helpful for in-depth and accurate analysis of the performance problems of the electronic device.
  • a method for collecting and tracking trace call chains is provided.
  • the method is applied to an electronic device.
  • the method includes: the electronic device obtains time information and identification information of a function from a register, and the time information includes access to the function And the time when the function is exited; the electronic device stores the time information and the identification information in the memory; when the preset condition is met, the electronic device determines the function name corresponding to the function according to the identification information, and stores the The time information in the memory and the function name are written into the trace file.
  • the electronic device can directly obtain the time information and identification information from the register.
  • This processing method saves the overhead of function calls, and thus consumes very little system performance (does not affect the user experience and does not cause System performance deteriorates); this method can also obtain a complete call path, thereby ensuring that the real site where the performance problem occurs can be captured, and accurate information can be provided for the location of the system performance problem.
  • the memory is a ring memory.
  • the electronic device determines the function name corresponding to the function according to the identification information, including: the electronic device calls a conversion interface to convert the identification information of the function into the function name.
  • the electronic device stores the identification information of the function in the memory instead of the function name corresponding to the function, which reduces the time it takes for the electronic device to write the time information and identification information into the memory, thereby reducing the writing bandwidth. Performance overhead.
  • the conversion interface is the ArtMethod::PrettyMethod() interface. It should be understood that the name of the interface is not limited in the embodiments of the present application, and other conversion interfaces may also be used.
  • the function may be identified by a preset number of bits.
  • the identification information is the pointer address of the function.
  • the electronic device can obtain the pointer address of the function from the register.
  • the pointer address instead of the function name, the time consumption of the electronic device in writing the time information and identification information into the memory is reduced, thereby reducing the writing time.
  • the register includes a first register and a second register
  • the electronic device obtains the time information and identification information of the function from the register, including: the electronic device is in the function When starting to run, obtain the time of entering the function from the first register and obtain the identification information of the function from the second register; the electronic device obtains the time of exiting the function from the first register when the function is finished.
  • the electronic device may obtain the time of entering the function and the identification information of the function when the function starts to run; at the end of the function, the time of exiting the function may be obtained. Therefore, the corresponding time information and identification information are stored in the memory.
  • This processing method saves the overhead of function calls, and thus consumes very little system performance (does not affect the user experience and does not deteriorate the system performance); The method can also obtain a complete call path, thereby ensuring that the real site where the performance problem occurs can be captured, and accurate information can be provided for the location of the system performance problem.
  • the preset condition includes: the duration of the electronic device starting the first application program is greater than or equal to the preset duration; or the number of dropped frames of the electronic device is greater than or Equal to the preset number of frames.
  • the code for implementing the method is in the Android runtime ART of the electronic device.
  • the code for implementing the above method may be in the ART of the electronic device, which avoids adding code in the application layer or the framework layer.
  • a method for collecting and tracing trace call chains is provided.
  • the method is applied to a system.
  • the system includes a first electronic device and a second electronic device.
  • the method includes: the first electronic device obtains function information from a register. Time information and identification information, the time information includes the time of entering the function and the time of exiting the function; the first electronic device stores the time information and the identification information in the memory; when the preset condition is met, the first electronic device Determine the function name corresponding to the function according to the identification information, and write the time information and the function name in the memory into the trace file; the first electronic device sends the trace file to the second electronic device; the second electronic device pair The trace file is parsed to obtain the trace call chain.
  • the first electronic device can directly obtain the time information and identification information from the register.
  • This processing method saves the overhead of function calls, so that the consumption of the system performance of the first electronic device is very small (not affecting User experience does not degrade system performance); this method can also enable the second electronic device to obtain a complete call path, thereby ensuring that the real site where the performance problem occurs can be captured, and accurate information can be provided for the location of the system performance problem.
  • the first electronic device is a mobile phone
  • the second electronic device is a personal computer (PC).
  • a device in a third aspect, is provided, the device is included in an electronic device, and the device has the function of realizing the foregoing aspects and the behavior of the electronic device in the possible implementation manners of the foregoing aspects.
  • the function can be realized by hardware, or the corresponding software can be executed by hardware.
  • the hardware or software includes one or more modules or units corresponding to the above-mentioned functions.
  • an electronic device including: one or more processors; a memory; and one or more computer programs.
  • one or more computer programs are stored in the memory, and the one or more computer programs include instructions.
  • the electronic device is caused to execute the method of collecting and tracing the trace call chain in any possible implementation of the first aspect described above.
  • the technical solution provides an electronic device including one or more processors and one or more memories.
  • the one or more memories are coupled with one or more processors, and the one or more memories are used to store computer program codes.
  • the computer program codes include computer instructions.
  • the electronic device executes The method of collecting and tracing trace call chains in any possible implementation of the first aspect described above.
  • the present technical solution provides a computer storage medium, including computer instructions, which when the computer instructions run on an electronic device, cause the electronic device to execute the collection and tracking trace call chain in any one of the possible implementations of the first aspect.
  • the present technical solution provides a computer program product that, when the computer program product runs on an electronic device, causes the electronic device to execute the method of collecting and tracking trace call chains in any one of the possible designs of the first aspect.
  • Fig. 1 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • Fig. 2 is a software structure block diagram of an electronic device provided by an embodiment of the present application.
  • Fig. 3 is a schematic diagram of adding trace points in each Java function provided by an embodiment of the present application.
  • Fig. 4 is a schematic diagram of trace point information acquisition and storage provided by an embodiment of the present application.
  • FIG. 5 is another schematic diagram of the acquisition and storage of trace point information provided by an embodiment of the present application.
  • Fig. 6 is a flame diagram of a trace file provided by an embodiment of the present application.
  • Fig. 7 is a method for collecting trace call chains provided by an embodiment of the present application.
  • the electronic device may be a portable electronic device that also contains other functions such as a personal digital assistant and/or a music player function, such as a mobile phone, a tablet computer, and a wearable electronic device with wireless communication function (such as a smart watch) Wait.
  • portable electronic devices include, but are not limited to, carrying Or portable electronic devices with other operating systems.
  • the aforementioned portable electronic device may also be other portable electronic devices, such as a laptop computer (Laptop) and the like. It should also be understood that, in some other embodiments, the above-mentioned electronic device may not be a portable electronic device, but a desktop computer.
  • FIG. 1 shows a schematic structural diagram of an electronic device 100.
  • the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, and an antenna 2.
  • Mobile communication module 150 wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, earphone interface 170D, sensor module 180, compass 190, motor 191, indicator 192, camera 193, display screen 194, and user
  • An identification module subscriber identification module, SIM
  • the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100.
  • the electronic device 100 may include more or fewer components than those shown in the figure, or combine certain components, or split certain components, or arrange different components.
  • the illustrated components can be implemented in hardware, software, or a combination of software and hardware.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural-network processing unit (NPU), etc.
  • different processing units may be independent components, or may be integrated in one or more processors.
  • the electronic device 100 may also include one or more processors 110.
  • the controller can generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching instructions and executing instructions.
  • a memory may be provided in the processor 110 to store instructions and data.
  • the memory in the processor 110 may be a cache memory.
  • the memory can store instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. In this way, repeated accesses are avoided, the waiting time of the processor 110 is reduced, and the efficiency of the electronic device 100 in processing data or executing instructions is improved.
  • the processor 110 may include one or more interfaces.
  • the interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, and a universal asynchronous transceiver (universal asynchronous transceiver) interface.
  • asynchronous receiver/transmitter, UART) interface mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, SIM card interface and/or USB interface, etc.
  • the USB interface 130 is an interface that complies with the USB standard specification, and specifically may be a Mini USB interface, a Micro USB interface, a USB Type C interface, and so on.
  • the USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and peripheral devices.
  • the USB interface 130 can also be used to connect earphones and play audio through the earphones.
  • the interface connection relationship between the modules illustrated in the embodiment of the present application is merely a schematic description, and does not constitute a structural limitation of the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection modes in the foregoing embodiments, or a combination of multiple interface connection modes.
  • the charging management module 140 is used to receive charging input from the charger.
  • the charging management module 140 may receive the charging input of the wired charger through the USB interface 130.
  • the charging management module 140 may receive the wireless charging input through the wireless charging coil of the electronic device 100.
  • the charging management module 140 charges the battery 142, it can also supply power to the electronic device through the power management module 141.
  • the power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110.
  • the wireless communication function of the electronic device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor.
  • the wireless communication module 160 can provide applications on the electronic device 100 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), and global navigation satellites.
  • WLAN wireless local area networks
  • BT wireless fidelity
  • BT wireless fidelity
  • GNSS global navigation satellite system
  • FM frequency modulation
  • NFC near field communication technology
  • IR infrared technology
  • the display screen 194 is used to display images, videos, and the like.
  • the display screen 194 includes a display panel.
  • the display panel can adopt liquid crystal display (LCD), organic light-emitting diode (OLED), active-matrix organic light-emitting diode, or active-matrix organic light-emitting diode (active-matrix organic light-emitting diode).
  • LCD liquid crystal display
  • OLED organic light-emitting diode
  • active-matrix organic light-emitting diode active-matrix organic light-emitting diode
  • AMOLED flexible light-emitting diode
  • FLED flexible light-emitting diode
  • mini light-emitting diode miniled
  • MicroLed Micro-oLed
  • quantum dot light emitting diode QLED
  • the electronic device 100 may include one or more display screens 194.
  • the electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.
  • the ISP is used to process the data fed back from the camera 193. For example, when taking a picture, the shutter is opened, the light is transmitted to the photosensitive element of the camera through the lens, the light signal is converted into an electrical signal, and the photosensitive element of the camera transmits the electrical signal to the ISP for processing and is converted into an image visible to the naked eye.
  • the camera 193 is used to capture still images or videos.
  • the external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100.
  • the external memory card communicates with the processor 110 through the external memory interface 120 to realize the data storage function. For example, save music, video and other files in an external memory card.
  • the internal memory 121 may be used to store one or more computer programs, and the one or more computer programs include instructions.
  • the processor 110 can execute the above-mentioned instructions stored in the internal memory 121 to enable the electronic device 100 to execute the method for obtaining and tracking the call chain provided in some embodiments of the present application, as well as various applications and data processing.
  • the electronic device 100 may implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor. For example, music playback, recording, etc.
  • the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, and an ambient light sensor 180L, bone conduction sensor 180M, etc.
  • the gyro sensor 180B may be used to determine the movement posture of the electronic device 100.
  • the angular velocity of the electronic device 100 around three axes ie, X, Y, and Z axes
  • the acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in various directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of electronic devices, and apply to applications such as horizontal and vertical screen switching, pedometers, and so on.
  • the magnetic sensor 180D includes a Hall sensor.
  • the electronic device 100 may use the magnetic sensor 180D to detect the opening and closing of the flip holster.
  • the acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in various directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of electronic devices, and apply to applications such as horizontal and vertical screen switching, pedometers, and so on.
  • Distance sensor 180F used to measure distance.
  • the proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector such as a photodiode.
  • the light emitting diode may be an infrared light emitting diode.
  • the ambient light sensor 180L is used to sense the brightness of the ambient light.
  • the fingerprint sensor 180H is used to collect fingerprints.
  • the electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photographs, fingerprint answering calls, and so on.
  • the temperature sensor 180J is used to detect temperature.
  • Touch sensor 180K also called “touch panel”.
  • the touch sensor 180K may be disposed on the display screen 194, and the touch screen is composed of the touch sensor 180K and the display screen 194, which is also called a “touch screen”.
  • the touch sensor 180K is used to detect touch operations acting on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • the visual output related to the touch operation can be provided through the display screen 194.
  • the touch sensor 180K may also be disposed on the surface of the electronic device 100, which is different from the position of the display screen 194.
  • FIG. 2 is a block diagram of the software structure of the electronic device 100 according to an embodiment of the present application.
  • the layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Communication between layers through software interface.
  • the Android system is divided into the application (application, App) layer, the framework layer (Java API Framework), the system library (native C/C++ Libraries), and the Android runtime (Android runtime) from top to bottom. , ART), hardware abstraction layer (HAL) and kernel layer (Linux Kernel).
  • the application layer can include a series of application packages.
  • the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
  • the framework layer provides an application programming interface (application programming interface, API) and a programming framework for applications in the application layer.
  • the framework layer includes some predefined functions.
  • the framework layer can include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and so on.
  • the window manager is used to manage window programs.
  • the window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc.
  • the content provider is used to store and retrieve data and make these data accessible to applications.
  • the data may include video, image, audio, phone calls made and received, browsing history and bookmarks, phone book, etc.
  • the view system includes visual controls, such as controls that display text, controls that display pictures, and so on.
  • the view system can be used to build applications.
  • the display interface can be composed of one or more views.
  • a display interface that includes a short message notification icon may include a view that displays text and a view that displays pictures.
  • the phone manager is used to provide the communication function of the electronic device 100. For example, the management of the call status (including connecting, hanging up, etc.).
  • the resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and so on.
  • the notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages, and it can automatically disappear after a short stay without user interaction.
  • the notification manager is used to notify download completion, message reminders, and so on.
  • the notification manager can also be a notification that appears in the status bar at the top of the system in the form of a chart or a scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window.
  • the status bar prompts text messages, sounds prompts, electronic equipment vibrates, and indicator lights flash.
  • the system library can include multiple functional modules. For example: surface manager (surface manager), media library (media libraries), 3D graphics processing library (for example: OpenGL ES), 2D graphics engine (for example: SGL), etc.
  • surface manager surface manager
  • media library media libraries
  • 3D graphics processing library for example: OpenGL ES
  • 2D graphics engine for example: SGL
  • the surface manager is used to manage the display subsystem and provides a combination of 2D and 3D layers for multiple applications.
  • the media library supports playback and recording of a variety of commonly used audio and video formats, as well as still image files.
  • the media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG and PNG.
  • the 3D graphics processing library is used to realize 3D graphics drawing, image rendering, synthesis and layer processing.
  • the 2D graphics engine is a drawing engine for 2D drawing.
  • ART contains a collection of core libraries that provide most of the functions available in the core libraries of the Java programming language.
  • the hardware abstraction layer is to provide the corresponding hardware display interface for the upper framework layer.
  • Audio, Bluetooth, etc. are the library modules that make up the hardware abstraction layer to realize the interface display function of each hardware.
  • the kernel layer is the layer between hardware and software.
  • the kernel layer can include display drivers, camera drivers, audio drivers, and sensor drivers.
  • the trace call chain can ensure that when a performance problem occurs, it can be automatically captured to the scene to help analyze and locate the performance problem.
  • the technical requirements for obtaining trace call chain capabilities are as follows:
  • the current ways to obtain the trace call chain include Android Studio CPU Profiler.
  • Android Studio CPU Profiler is a multifunctional tool that comes with Android Studio, which can provide the ability to obtain the trace call chain of the Android system.
  • its performance load is relatively large, and it is only used for development and debugging scenarios.
  • AOP aspect-oriented programming
  • Systrace Another way to get the trace call chain is Systrace.
  • the principle of Systrace is to insert some information (label) in some key links of the system (such as system service, virtual machine, thread (binder) driver), and determine the execution time of a core process through the start and end of the label, and then Collect these label information to get the running time information of the critical path of the system, and then get the running performance information of the entire system.
  • Some important modules in the framework layer are inserted with label information (for example, the Java layer is completed by the android.os.Trace class, and the native layer is completed by the ATrace macro), and custom labels can be added to the App.
  • this method cannot obtain a complete trace call chain (or, the trace call path obtained by this method is very shallow), provides limited useful information, and cannot perform in-depth and accurate analysis of performance problems.
  • An embodiment of this application proposes a method for collecting trace call chains.
  • the method itself consumes very little system performance (does not affect user experience and does not deteriorate system performance), and can obtain the full call path, which benefits from this advantage .
  • This method can be always open in the system, can capture the real scene where the performance problem occurs, and can provide direct and accurate information for the delimitation and positioning of the system performance problem.
  • the code of the method for obtaining the trace call chain in the embodiment of the present application can be implemented in the Android runtime (ART), and there is no need to add code in the application layer and the framework layer.
  • the code of the method in the embodiment of the present application may also be implemented in a virtual machine.
  • a trace point can be added at the entrance and exit of each function.
  • the trace point includes time information and identification information.
  • the time information and identification information of the trace point can also be realized by directly accessing the register. This processing method can save the overhead of function calls, so as to save the performance overhead caused by obtaining the trace call chain.
  • the time information of the function may include the time when the function is entered and the time when the function is exited.
  • the time when the function is entered is the time when the function starts to run, and the time when the function is exited is the time when the function ends.
  • the identification information of can be the pointer address of the function or other information that can identify the function.
  • Figure 3 shows a schematic diagram of adding trace points to each Java function in an embodiment of the present application.
  • the execution of the Android system includes two ways of parsing execution and compilation execution, so adding trace points needs to cover these two ways.
  • the "pre-compilation” and “just-in-time compilation” in the figure correspond to compilation and execution, which are usually executed when the App is installed and when the mobile phone is idle; the “parser” in Figure 3 corresponds to the analysis and execution.
  • the Android system ART implementation code find the entry and exit of each function execution, and then add trace points at the entry and exit.
  • the Java functions in the application layer and the framework layer can be compiled and parsed in ART.
  • ART can add trace points to all Java functions, and finally ART can output Java functions containing trace points.
  • Java functions in the application layer and framework layer cannot be directly executed by electronic devices. ART adds trace points to Java functions and translates Java functions into machine code. Machine code can be used by electronic devices. Directly executed.
  • the method of obtaining the trace call chain in the embodiment of the application is implemented in ART, which can ensure that the electronic device obtains the call relationship of all Java functions, that is, the full call path, thereby ensuring that the performance problems of the electronic device are in-depth and accurate analyze.
  • Figure 4 shows a schematic diagram of trace point information acquisition and storage provided by an embodiment of the present application.
  • the trace point 1 (TracePoint1) in Figure 4 represents the time when the function is entered at the entry of the function.
  • the implementation can be to obtain the information directly from the register in the central processing unit (CPU), so that the highest speed is obtained.
  • the acquisition speed of the code can be implemented in assembly.
  • the trace point 2 (TracePoint2) in FIG. 4 represents the moment when the function is exited at the exit of the function, and the implementation can be to obtain the information directly from the register in the CPU.
  • the electronic device can save the acquired trace point information (TracePoint1 and TracePoint2) and the information identifying the function in the ring memory.
  • the information of TracePoint1 and the information of TracePoint2 can be a 32-bit integer value. Similarly, a predefined integer value can be used to identify the function.
  • the electronic device can combine the information of TracePoint1, TracePoint2, and the information that identifies the function. The information is stored in the ring memory.
  • the electronic device can obtain the time of entering the function, the time of exiting the function, and the identification information of the function from the same register; or the electronic device can obtain the time of entering the function from a register And at the time when the function is exited, the identification information of the function is obtained from another register.
  • the electronic device may store the time of entering the function and the information identifying the function in the ring memory at TracePoint1. Alternatively, the electronic device may save the time of exiting the function and the information identifying the function in the ring memory at TracePoint2.
  • the electronic device may also save the information of TracePoint1, the information of TracePoint2, and the information of the function name (or function string) in the ring memory.
  • the ring memory may be a storage structure connected end to end.
  • the total amount of data stored in the ring memory is fixed. For example, there may be 100 (for example, 1 to 100) storage locations in the ring memory.
  • the ring memory can automatically delete the data in the first storage location to store new data.
  • the ring memory uses an overwritten storage method for data storage.
  • the storage of the tracking point information in the ring memory is taken as an example for description.
  • the tracking point information may also be stored in other storage areas of the electronic device. Any restrictions.
  • the electronic device can import the information in the ring memory into the trace file. This allows the PC to parse the trace file to obtain the trace call chain after exporting the trace file.
  • the electronic device can obtain the corresponding function string through the identification information of the function, so as to determine the time-consuming operation of the function according to the entry and exit time of the function string.
  • the foregoing preset conditions include but are not limited to one or more of the following conditions:
  • the number of dropped frames of the electronic device is greater than or equal to the preset number of frames
  • the CPU usage rate of the electronic device is greater than or equal to the preset CPU usage rate
  • the temperature sensor of the electronic device detects that the temperature of the CPU is greater than or equal to the preset temperature value.
  • the number of dropped frames of the electronic device may refer to a certain amount of time that the electronic device consumes when drawing a frame of image. If the time is greater than or equal to the preset duration, a number of dropped frames can be determined.
  • the electronic device can determine that the number of lost frames is 1; if the electronic device draws a frame of image longer than 32ms, the electronic device can determine that the number of lost frames is 2.
  • the method of identifying functions is not specifically limited. Those skilled in the art will know that each function has its own identification information, and the electronic device can process the identification information of each function, for example, using pre- Set the bit to identify the corresponding function.
  • FIG. 5 shows another schematic diagram of the acquisition and storage of trace point information provided by an embodiment of the present application.
  • Tracepoint 3 (TracePoint3) in FIG. 5 indicates that the time of entering the function and the identification information of the function are obtained at the entry of the function.
  • the method of obtaining the time of entering the function and the identification information of the function may be to directly read the register in the CPU.
  • the moment of entering the function may occupy 32 bits
  • the identification information of the function may occupy 32 bits.
  • the trace point 4 (TracePoint4) in Figure 5 represents the moment when the function exits the function, and the implementation can be to obtain the information directly from the register in the CPU. Exemplarily, the moment of exiting the function may occupy 32 bits.
  • the electronic device in TracePoint3, can obtain the time of entering the function from the first register and the identification information of the function from the second register. In TracePoint4, the electronic device can obtain the time of exiting the function from the first register.
  • the electronic device may convert the identification information of the function into a function name (or a function string) when writing the identification information of the function stored in the ring memory into the trace file.
  • obtaining the identification information of the function in TracePoint3 is taken as an example for description, which is not specifically limited in the embodiment of the present application.
  • the identification information of the function can also be obtained at TracePoint4; or, the identification information of the function can also be obtained at any point in the execution of the function.
  • Table 1 shows trace point information stored in a ring memory.
  • Table 1 Trace point information stored in the ring memory
  • the function name when the acquired trace point information is written into the memory, the function name may not be saved, but the function identification information is recorded. Only when the memory information is finally exported to a file, the function identification information is matched with the function name, Then write the function name into the trace file.
  • the advantage of this processing method is to ensure that the time spent writing to the memory is as short as possible, so as to save the performance overhead caused by the writing.
  • the identification information of the function may be the pointer address of the function; or, the identification information of the function may be other identification information of the function, for example, a preset bit is used to identify the corresponding function.
  • Table 2 shows the trace call chain obtained in the embodiment of this application.
  • the number on the left of each line in the trace call chain represents the time (in nanoseconds)
  • the right of each line represents the function name string
  • POP represents the exit of the function.
  • the POP in the third line can represent the exit of the function int android.view.Window.getFeatures() in the second line;
  • the POP in the fourth line can represent the function boolean in the first line android.view.Window.hasFeature(int) The exit.
  • the POP in the fifth line can represent the exit of the upper layer function (not shown in Table 2) of the function boolean android.view.Window.hasFeature(int).
  • the trace file can be directly as shown in Table 2; if the function identification information is stored in the ring memory, then It is necessary to determine the corresponding function name through the identification information of the function. For example, if the identification information of the function is stored in the ring memory, the function name can be determined through the existing interface ArtMethod::PrettyMethod().
  • the trace file can be opened by borrowing flame graphs.
  • FIG. 6 shows a schematic diagram of the flame graph of the trace file in an embodiment of the present application.
  • the horizontal axis in the figure represents time, and the wider the width, the longer the corresponding function call takes.
  • the width value can be determined by the time difference between the function entry and the function exit.
  • the vertical axis represents the function call relationship, which is called sequentially from top to bottom (for example, the top-level function calls the second-level function, and the second-level function calls the third-level function, which are called in turn).
  • the embodiment of this application can obtain the full high-performance trace call chain of the Android system from the application layer to the framework layer.
  • This method has very low system performance consumption (does not increase the time consumption of function execution), as shown in Table 3 and Table 4. Experimental data.
  • the trace capability can be always turned on when the Android system is running (not affecting the user experience and not deteriorating the system performance), and the trace capability is always turned on to ensure that it can be caught At the scene where the performance problem occurs, the captured scene information is of direct help to the delimitation and positioning of the Android performance problem.
  • the traceable call chain depth is deep enough (full call chain), so that the performance problem analysis can reach the granularity of the function code.
  • the trace call chain can be obtained, but also other information, such as thread ID, CPU load information, etc. can be obtained.
  • FIG. 7 shows a schematic flowchart of a method 700 for collecting a trace call chain provided by an embodiment of the present application. As shown in FIG. 7, the method 700 includes:
  • the electronic device obtains time information and identification information of the function from a register, where the time information includes the time of entering the function and the time of exiting the function.
  • the electronic device can read the time information of the function entry, the time information of the function exit, and the identification information of the function from the register.
  • the electronic device stores the time information and the identification information in a memory.
  • the electronic device may store the information in the ring memory.
  • the preset condition in S703 may refer to the description of the preset condition in the foregoing embodiment, and for the sake of brevity, it will not be repeated here.
  • the electronic device can directly obtain the time information and identification information from the register.
  • This processing method saves the overhead of function calls, and thus consumes very little system performance (does not affect the user experience and does not cause the system Performance deterioration); this method can also obtain a complete call path, thereby ensuring that the real site where the performance problem occurs can be captured, and accurate information can be provided for the location of the system performance problem.
  • the memory is a ring memory.
  • the electronic device determining the function name corresponding to the function according to the identification information includes: the electronic device calls a conversion interface to convert the identification information of the function into the function name.
  • the electronic device stores the identification information of the function in the memory instead of the function name corresponding to the function, which reduces the time it takes for the electronic device to write the time information and identification information into the memory, thereby reducing the writing bandwidth. Performance overhead.
  • the conversion interface is the ArtMethod::PrettyMethod() interface. It should be understood that the name of the interface is not limited in the embodiments of the present application, and other conversion interfaces may also be used.
  • the function may be identified by a preset number of bits.
  • the identification information is the pointer address of the function.
  • the electronic device can obtain the pointer address of the function from the register.
  • the pointer address instead of the function name, the time consumption of the electronic device in writing the time information and identification information into the memory is reduced, thereby reducing the writing time.
  • the register includes a first register and a second register.
  • the electronic device obtains the time information and identification information of the function from the register, including: when the function starts to run, the electronic device obtains and enters the function from the first register. The time of the function and the identification information of the function is obtained from the second register; when the function is finished, the electronic device obtains the time of exiting the function from the first register.
  • the electronic device when the function starts running (TracePoint3), the electronic device can obtain the time of entering the function from the first register and the identification information of the function from the second register; the electronic device can run in the function At the end (TracePoint4) get the time to exit the function.
  • the electronic device may obtain the time of entering the function and the identification information of the function when the function starts to run, and obtain the time of exiting the function when the function ends. Therefore, the corresponding time information and identification information are stored in the memory.
  • This processing method saves the overhead of function calls, and thus consumes very little system performance (does not affect user experience and does not deteriorate system performance); this method
  • the complete call path can also be obtained, which can ensure that the real site where the performance problem occurs can be captured, and accurate information can be provided for the location of the system performance problem.
  • the moment of entering the function may be obtained from the register when the function starts to run. It may also be that a time is recorded after the preset time length when the function starts to run, and then the electronic device can determine the time to enter the function based on the time and the preset time length.
  • a time can also be recorded at a preset time before the function ends, and then the electronic device can determine the time to exit the function based on the time and the preset time.
  • the code for implementing the method 700 is in the Android runtime ART of the electronic device.
  • the code for implementing the above method may be in the ART of the electronic device, which avoids adding code in the application layer or the framework layer.
  • An embodiment of the present application also provides an electronic device, which may include a processor 110 and a memory as shown in FIG. 1, where one or more computer programs are stored in the memory, and the one or more computer programs include instructions, When the instructions are executed by the one or more processors, the electronic device is caused to execute the steps S701, S702, and S703 in the method 700.
  • the disclosed system, device, and method may be implemented in other ways.
  • the device embodiments described above are merely illustrative, for example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or It can be integrated into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the technical solution of the present application essentially or the part that contributes to the existing technology or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)
  • Telephone Function (AREA)

Abstract

一种采集追踪trace调用链的方法,该方法应用于电子设备中,该方法包括:该电子设备从寄存器中获取函数的时间信息和标识信息(701),该时间信息包括进入该函数的时刻以及退出该函数的时刻;该电子设备将该时间信息和该标识信息存储在内存中(702);在满足预设条件时,该电子设备根据该标识信息确定该函数对应的函数名,并将该内存中的该时间信息以及该函数名写入trace文件(703)。该方法可以在不影响系统性能的情况下,获取完整的调用路径,从而为系统性能问题的定位提供准确的信息。

Description

一种采集追踪trace调用链的方法和电子设备
本申请要求于2020年3月26日提交中国专利局、申请号为202010225986.8、申请名称为“一种采集追踪trace调用链的方法和电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及电子设备领域,并且更具体地,涉及一种获取追踪调用链的方法和电子设备。
背景技术
当前Android系统的智能手机使用过程中仍会出现许多性能问题,比如用户在使用某应用程序(application,App)出现卡顿现象。性能问题通常是随机的、不确定的、且难以复现的,基于此需要一款可以常运行的追踪(trace)调用链工具,保证在性能问题发生时能自动抓取到现场,以帮助分析与定位性能问题。
Systrace是Android系统提供一款性能问题分析工具,它能抓取到Android系统中若干预埋的调用路径。但是该方法不能获取到完整的调用路径,提供的有用信息有限,无法对性能问题做深入和准确的分析。
发明内容
本申请提供一种采集追踪trace调用链的方法和电子设备,有助于对电子设备的性能问题做深入和准确的分析。
第一方面,提供了一种采集追踪trace调用链的方法,该方法应用于电子设备中,该方法包括:该电子设备从寄存器中获取函数的时间信息和标识信息,该时间信息包括进入该函数的时刻以及退出该函数的时刻;该电子设备将该时间信息和该标识信息存储在内存中;在满足预设条件时,该电子设备根据该标识信息确定该函数对应的函数名,并将该内存中的该时间信息以及该函数名写入trace文件。
本申请实施例中,电子设备可以直接从寄存器中获取时间信息和标识信息,这样的处理方法省去了函数调用的开销,从而对系统性能的消耗非常小(不影响用户体验,且不会使系统性能恶化);该方法还可以获取到完整的调用路径,从而可以保证抓到性能问题发生的真正现场,为系统性能问题的定位提供准确的信息。
在一些可能的实现方式中,该内存为环形内存。
结合第一方面,在第一方面的某些实现方式中,该电子设备根据该标识信息确定该函数对应的函数名,包括:该电子设备调用转化接口,将该函数的标识信息转化为该函数名。
本申请实施例中,电子设备在内存中保存的是函数的标识信息而不是函数对应的函数名,减少了电子设备在将时间信息和标识信息写入内存的耗时,从而降低了写入带来的性 能开销。
应理解,本申请实施例中的函数可以包括函数名、函数参数等等信息。
在一些可能的实现方式中,该转化接口为ArtMethod::PrettyMethod()接口。应理解,本申请实施例中对接口的名称并不作限定,还可以是其他转化接口。
在一些可能的实现方式中,该函数可以是由预设比特数标识。
结合第一方面,在第一方面的某些实现方式中,该标识信息为该函数的指针地址。
本申请实施例中,电子设备可以从寄存器中获取函数的指针地址,通过保存指针地址而不是保存函数名,减少了电子设备在将时间信息和标识信息写入内存的耗时,从而降低了写入带来的性能开销。
结合第一方面,在第一方面的某些实现方式中,该寄存器包括第一寄存器和第二寄存器,该电子设备从寄存器中获取函数的时间信息和标识信息,包括:该电子设备在该函数开始运行时,从该第一寄存器获取进入该函数的时刻且从该第二寄存器获取该函数的标识信息;该电子设备在该函数运行结束时,从该第一寄存器获取退出该函数的时刻。
本申请实施例中,电子设备可以在函数开始运行时,获取进入该函数的时刻以及函数的标识信息;在函数运行结束时,获取退出该函数的时刻。从而将相应的时间信息和标识信息保存在内存中,这样的处理方法省去了函数调用的开销,从而对系统性能的消耗非常小(不影响用户体验,且不会使系统性能恶化);该方法还可以获取到完整的调用路径,从而可以保证抓到性能问题发生的真正现场,对系统性能问题的定位提供准确的信息。
结合第一方面,在第一方面的某些实现方式中,该预设条件包括:该电子设备启动第一应用程序的时长大于或者等于预设时长;或者,该电子设备的丢帧数大于或者等于预设帧数。
结合第一方面,在第一方面的某些实现方式中,实现该方法的代码在该电子设备的安卓运行时ART中。
本申请实施例中,实现上述方法的代码可以在电子设备的ART中,这样避免了在应用程序层或者框架层中添加代码。
第二方面,提供了一种采集追踪trace调用链的方法,该方法应用于系统中,该系统包括第一电子设备和第二电子设备,该方法包括:第一电子设备从寄存器中获取函数的时间信息和标识信息,该时间信息包括进入该函数的时刻以及退出该函数的时刻;第一电子设备将该时间信息和该标识信息存储在内存中;在满足预设条件时,第一电子设备根据该标识信息确定该函数对应的函数名,并将该内存中的该时间信息以及该函数名写入trace文件;第一电子设备向第二电子设备发送该trace文件;该第二电子设备对该trace文件进行解析,获得trace调用链。
本申请实施例中,第一电子设备可以直接从寄存器中获取时间信息和标识信息,这样的处理方法省去了函数调用的开销,从而对第一电子设备的系统性能的消耗非常小(不影响用户体验,不会使系统性能恶化);该方法还可以使得第二电子设备获取到完整的调用路径,从而可以保证抓到性能问题发生的真正现场,对系统性能问题的定位提供准确的信息。
在一些可能的实现方式中,该第一电子设备为手机,该第二电子设备为个人计算机(personal computer,PC)。
第三方面,提供了一种装置,该装置包含在电子设备中,该装置具有实现上述方面及上述方面的可能实现方式中电子设备行为的功能。功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括一个或多个与上述功能相对应的模块或单元。
第四方面,提供了一种电子设备,包括:一个或多个处理器;存储器;以及一个或多个计算机程序。其中,一个或多个计算机程序被存储在存储器中,一个或多个计算机程序包括指令。当指令被电子设备执行时,使得电子设备执行上述第一方面任一项可能的实现中的采集追踪trace调用链的方法。
第五方面,本技术方案提供了一种电子设备,包括一个或多个处理器和一个或多个存储器。该一个或多个存储器与一个或多个处理器耦合,一个或多个存储器用于存储计算机程序代码,计算机程序代码包括计算机指令,当一个或多个处理器执行计算机指令时,使得电子设备执行上述第一方面任一项可能的实现中的采集追踪trace调用链的方法。
第六方面,本技术方案提供了一种计算机存储介质,包括计算机指令,当计算机指令在电子设备上运行时,使得电子设备执行上述第一方面任一项可能的实现中的采集追踪trace调用链的方法。
第七方面,本技术方案提供了一种计算机程序产品,当计算机程序产品在电子设备上运行时,使得电子设备执行上述第一方面任一项可能的设计中的采集追踪trace调用链的方法。
附图说明
图1是本申请实施例提供的电子设备的结构示意图。
图2是本申请实施例提供的电子设备的软件结构框图。
图3是本申请实施例提供的在每个Java函数中添加trace点的示意图。
图4是本申请实施例提供的trace点信息获取与存储的示意图。
图5是本申请实施例提供的trace点信息获取与存储的另一示意图。
图6是本申请实施例提供的trace文件火焰图。
图7是本申请实施例提供的采集trace调用链的方法。
具体实施方式
以下实施例中所使用的术语只是为了描述特定实施例的目的,而并非旨在作为对本申请的限制。如在本申请的说明书和所附权利要求书中所使用的那样,单数表达形式“一个”、“一种”、“所述”、“上述”、“该”和“这一”旨在也包括例如“一个或多个”这种表达形式,除非其上下文中明确地有相反指示。还应当理解,在本申请以下各实施例中,“至少一个”、“一个或多个”是指一个、两个或两个以上。术语“和/或”,用于描述关联对象的关联关系,表示可以存在三种关系;例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B的情况,其中A、B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。
以下介绍电子设备、用于这样的电子设备的用户界面、和使用这样的电子设备的实施例。在一些实施例中,电子设备可以是还包含其它功能诸如个人数字助理和/或音乐播放器功能的便携式电子设备,诸如手机、平板电脑、具备无线通讯功能的可穿戴电子设备(如 智能手表)等。便携式电子设备的示例性实施例包括但不限于搭载
Figure PCTCN2021081046-appb-000001
Figure PCTCN2021081046-appb-000002
或者其它操作系统的便携式电子设备。上述便携式电子设备也可以是其它便携式电子设备,诸如膝上型计算机(Laptop)等。还应当理解的是,在其他一些实施例中,上述电子设备也可以不是便携式电子设备,而是台式计算机。
示例性的,图1示出了电子设备100的结构示意图。电子设备100可以包括处理器110、外部存储器接口120、内部存储器121、通用串行总线(universal serial bus,USB)接口130、充电管理模块140、电源管理模块141、电池142、天线1、天线2、移动通信模块150、无线通信模块160、音频模块170、扬声器170A、受话器170B、麦克风170C、耳机接口170D、传感器模块180、指南针190、马达191、指示器192、摄像头193、显示屏194以及用户标识模块(subscriber identification module,SIM)卡接口195等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备100的具体限定。在本申请另一些实施例中,电子设备100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的部件,也可以集成在一个或多个处理器中。在一些实施例中,电子设备100也可以包括一个或多个处理器110。其中,控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。在其他一些实施例中,处理器110中还可以设置存储器,用于存储指令和数据。示例性地,处理器110中的存储器可以为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从所述存储器中直接调用。这样就避免了重复存取,减少了处理器110的等待时间,因而提高了电子设备100处理数据或执行指令的效率。
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路间(inter-integrated circuit,I2C)接口、集成电路间音频(inter-integrated circuit sound,I2S)接口、脉冲编码调制(pulse code modulation,PCM)接口、通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口、移动产业处理器接口(mobile industry processor interface,MIPI)、用输入输出(general-purpose input/output,GPIO)接口、SIM卡接口和/或USB接口等。其中,USB接口130是符合USB标准规范的接口,具体可以是Mini USB接口、Micro USB接口、USB Type C接口等。USB接口130可以用于连接充电器为电子设备100充电,也可以用于电子设备100与外围设备之间传输数据。该USB接口130也可以用于连接耳机,通过耳机播放音频。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备100的结构限定。在本申请另一些实施例中,电子设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。充电管理模块140用于从充电器接收充电输入。充电管理模块140可以通过USB接口130接收有线充电器的充 电输入。在一些无线充电的实施例中,充电管理模块140可以通过电子设备100的无线充电线圈接收无线充电输入。充电管理模块140为电池142充电的同时,还可以通过电源管理模块141为电子设备供电。电源管理模块141用于连接电池142,充电管理模块140与处理器110。
电子设备100的无线通信功能可以通过天线1、天线2、移动通信模块150、无线通信模块160、调制解调处理器以及基带处理器等实现。
无线通信模块160可以提供应用在电子设备100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络)、蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS)、调频(frequency modulation,FM)、近距离无线通信技术(near field communication,NFC)、红外技术(infrared,IR)等无线通信的解决方案。
显示屏194用于显示图像、视频等。显示屏194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD)、有机发光二极管(organic light-emitting diode,OLED)、有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED)、柔性发光二极管(flex light-emitting diode,FLED)、迷你发光二极管(mini light-emitting diode,miniled)、MicroLed、Micro-oLed、量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备100可以包括1个或多个显示屏194。
电子设备100可以通过ISP、摄像头193、视频编解码器、GPU、显示屏194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头193反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。
摄像头193用于捕获静态图像或视频。外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。
内部存储器121可以用于存储一个或多个计算机程序,该一个或多个计算机程序包括指令。处理器110可以通过运行存储在内部存储器121的上述指令,从而使得电子设备100执行本申请一些实施例中所提供的获取追踪调用链的方法,以及各种应用以及数据处理等。
电子设备100可以通过音频模块170、扬声器170A、受话器170B、麦克风170C、耳机接口170D、以及应用处理器等实现音频功能。例如音乐播放、录音等。
传感器模块180可以包括压力传感器180A、陀螺仪传感器180B、气压传感器180C、磁传感器180D、加速度传感器180E、距离传感器180F、接近光传感器180G、指纹传感器180H、温度传感器180J、触摸传感器180K、环境光传感器180L、骨传导传感器180M等。
陀螺仪传感器180B可以用于确定电子设备100的运动姿态。在一些实施例中,可以通过陀螺仪传感器180B确定电子设备100围绕三个轴(即X、Y和Z轴)的角速度。加 速度传感器180E可检测电子设备100在各个方向上(一般为三轴)加速度的大小。当电子设备100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
磁传感器180D包括霍尔传感器。电子设备100可以利用磁传感器180D检测翻盖皮套的开合。
加速度传感器180E可检测电子设备100在各个方向上(一般为三轴)加速度的大小。当电子设备100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器180F,用于测量距离。
接近光传感器180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。
环境光传感器180L用于感知环境光亮度。指纹传感器180H用于采集指纹。电子设备100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器180J用于检测温度。
触摸传感器180K,也称“触控面板”。触摸传感器180K可以设置于显示屏194,由触摸传感器180K与显示屏194组成触摸屏,也称“触控屏”。触摸传感器180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器180K也可以设置于电子设备100的表面,与显示屏194所处的位置不同。
图2是本申请实施例的电子设备100的软件结构框图。分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统从上至下分别为应用程序(application,App)层,框架层(Java API Framework),系统库(native C/C++Libraries),安卓运行时(Android runtime,ART),硬件抽象层(hardware abstraction layer,HAL)以及内核层(Linux Kernel)。应用程序层可以包括一系列应用程序包。
如图2所示,应用程序包可以包括相机、图库、日历、通话、地图、导航、WLAN、蓝牙、音乐、视频、短信息等应用程序。
框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架,框架层包括一些预先定义的函数。
如图2所示,框架层可以包括窗口管理器、内容提供器、视图系统、电话管理器、资源管理器、通知管理器等。
窗口管理器用于管理窗口程序,窗口管理器可以获取显示屏大小,判断是否有状态栏、锁定屏幕、截取屏幕等。
内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频、图像、音频、拨打和接听的电话、浏览历史和书签、电话簿等。
视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。
电话管理器用于提供电子设备100的通信功能。例如通话状态的管理(包括接通,挂断等)。
资源管理器为应用程序提供各种资源,比如本地化字符串、图标、图片、布局文件、视频文件等等。
通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息、发出提示音、电子设备振动、指示灯闪烁等。
系统库可以包括多个功能模块。例如:表面管理器(surface manager)、媒体库(media libraries)、三维图形处理库(例如:OpenGL ES)、2D图形引擎(例如:SGL)等。
表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。
媒体库支持多种常用的音频、视频格式回放和录制以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4、H.264、MP3、AAC、AMR、JPG和PNG等。
三维图形处理库用于实现三维图形绘图、图像渲染、合成和图层处理等。
2D图形引擎是2D绘图的绘图引擎。
ART中包含一个核心库的集合,提供大部分Java编程语言核心库中可用的功能。
硬件抽象层是为上层的框架层提供相应硬件的显示界面,音频(Audio)、蓝牙(Bluetooth)等是组成硬件抽象层的库模块,实现每个硬件的界面显示功能。
内核层是硬件和软件之间的层。内核层可以包含显示驱动、摄像头驱动、音频驱动、传感器驱动。
下面介绍本申请实施例提供的采集trace调用链的方法。
trace调用链可以保证在性能问题发生时能自动抓取到现场,以帮助分析与定位性能问题。这对获取trace调用链能力的技术要求如下:
(1)能在系统运行时常开,以抓到问题发生现场;
(2)trace信息量充足;
(3)自身性能消耗足够小,不降低整个系统的性能表现。
当前获取trace调用链的方式包括Android Studio CPU Profiler,Android Studio CPU Profiler是Android studio自带的一款多功能工具,它能提供Android系统trace调用链获取能力。但是其性能负载较大,仅仅用于开发调试场景。在获取trace调用链时需要对所有必要的class进行字节码增强,在进入每个方法前需要进行埋点,方法执行结束后统计本次方法执行耗时。该方法对几乎所有方法添加额外的面向切面编程(aspect oriented programming,AOP)逻辑(通过反射方式实现),这会导致巨额的性能影响。
另一种获取trace调用链的方式为Systrace。Systrace的原理是在系统的一些关键链路(比如system service,虚拟机,线程(binder)驱动)中插入一些信息(label),通过label的开始和结束来确定某个核心过程的执行时间,然后把这些label信息收集起来得到系统关键路径的运行时间信息,进而得到整个系统的运行性能信息。框架层里面的一些重要模块都插入了label信息(例如,Jave层的通过android.os.Trace类完成,native层通过ATrace 宏完成),App中可以添加自定义的label。但是这种方法不能获取到完整的trace调用链(或者,该方法获取的trace调用路径很浅),提供的有用信息有限,无法对性能问题做深入和准确的分析。
本申请实施例中提出一种采集trace调用链的方法,该方法本身消耗系统性能非常小(不影响用户体验,不会使系统性能恶化),且能获取到全量调用路径,得益于该优点,该方法可以在系统中常开,能抓到性能问题发生的真正现场,能对系统性能问题的定界定位提供直接的、准确的信息。
本申请实施例中的获取trace调用链的方法的代码可以在安卓运行时(Android runtime,ART)中实现,在应用程序层和框架层无需添加代码。或者,本申请实施例的方法的代码也可以在虚拟机中实现。
在每个函数的出入口可以各添加一个追踪(trace)点,trace点包括时间信息和标识信息,为节省系统的性能开销,trace点的时间信息和标识信息也可以通过直接访问寄存器的方式实现,该处理方法可以省去函数调用的开销,以节约获取trace调用链所带来的性能开销。
应理解,本申请实施例中,函数的时间信息可以包括进入函数的时刻以及退出函数的时刻,进入函数的时刻为该函数开始运行的时刻,退出函数的时刻为该函数结束运行的时刻;函数的标识信息可以是函数的指针地址或者其他可以标识函数的信息。
图3示出了本申请实施例中在每个Java函数中添加trace点的示意图。
Android系统执行包括解析执行和编译执行两种方式,因此添加trace点需要覆盖这两种方式。如图3所示,图中的“预编译”和“即时编译”对应编译执行,通常在App安装时和手机空闲编译时会执行到;图3中“解析器”对应解析执行。在Android系统ART实现代码中,找到每个函数执行的入口和出口,然后在入口和出口添加trace点。
如图3所示,应用程序层和框架层中的Java函数可以在ART中进行编译和解析,其中,ART可以对所有Java函数添加trace点,最后ART可以输出包含trace点的Java函数。
应理解,应用程序层和框架层中的Java函数是不能被电子设备直接进行执行的,ART在对Java函数添加trace点的同时也会将Java函数翻译为机器码,机器码是可以被电子设备直接执行的。
本申请实施例中的获取trace调用链的方法在ART中实现,可以保证电子设备获取到所有Java函数的调用关系,即为全调用路径,从而保证了对电子设备的性能问题做深入和准确的分析。
图4示出了本申请实施例提供的trace点信息获取与存储的示意图。
图4中的追踪点1(TracePoint1)表示在函数的入口获取进入该函数的时刻,实现方式可以是直接从中央处理器(central processing unit,CPU)中的寄存器获取该信息,这样是得到最高速的获取速度,代码可以使用汇编方式实现。
图4中的追踪点2(TracePoint2)表示在函数的出口获取退出该函数的时刻,实现方式可以是直接从CPU中的寄存器获取该信息。
电子设备可以将获取到的trace点信息(TracePoint1和TracePoint2)以及标识该函数的信息保存在环形内存中。
示例性的,TracePoint1的信息和TracePoint2的信息可以是一个32位的整数值,同样 的可以采用预定义的整数值来标识该函数,电子设备可以将TracePoint1的信息、TracePoint2的信息以及标识该函数的信息存入环形内存中。
应理解,本申请实施例中,电子设备可以从同一寄存器中获取进入该函数的时刻、退出该函数的时刻以及该函数的标识信息;或者,电子设备可以从一个寄存器中获取进入该函数的时刻以及退出该函数的时刻,从另一个寄存器中获取该函数的标识信息。
一个实施例中,电子设备可以在TracePoint1处将进入该函数的时刻以及标识该函数的信息保存在环形内存中。或者,电子设备可以在TracePoint2处将退出该函数的时刻以及标识该函数的信息保存在环形内存中。
一个实施例中,电子设备也可以将TracePoint1的信息、TracePoint2的信息以及函数名(或者,函数字符串)的信息保存到环形内存中。
本申请实施例中,环形内存可以是首尾相连的存储结构。环形内存中存储数据的总量是固定的。例如,环形内存中可以有100(例如,1至100)个存储位置。当环形内存中1至100个存储位置存满且需要存储新的数据时,环形内存可以自动将第1个存储位置上的数据删除从而存储新的数据。或者,也可以理解为环形内存是采用覆盖的存储方式进行数据存储。
应理解,本申请实施例中是以将追踪点的信息保存在环形内存中为例进行说明的,追踪点的信息还可以保存在电子设备的其他存储区域中,本申请实施例对此并不作任何限定。
在满足预设条件时,电子设备可以将环形内存中的信息导入trace文件中。从而使得PC在导出trace文件后,对trace文件进行解析获得trace调用链。电子设备可以通过函数的标识信息获取对应的函数字符串,从而针对该函数字符串的进入以及退出时刻来判断该函数运行的耗时情况。
本申请实施例中,上述预设条件包括但不限于以下条件中的一种或者多种:
(1)电子设备启动某个应用程序时的时长大于或者等于预设时长;
(2)电子设备的丢帧数大于或者等于预设帧数;
(3)电子设备的CPU使用率大于或者等于预设CPU使用率;
(4)电子设备的温度传感器检测到CPU的温度大于或者等于预设温度值。
应理解,本申请实施例中,电子设备的丢帧数可以指电子设备在绘制一帧图像时都会消耗一定的时长,如果这个时长大于或者等于预设时长则可以确定出一个丢帧数。
示例性的,若电子设备绘制一帧图像的时长大于16ms,那么电子设备可以确定丢帧数为1;如果电子设备绘制一帧图像的时长大于32ms,那么电子设备可以确定丢帧数为2。
应理解,本申请实施例中,对函数的标识方式并不作具体限定,本领域技术人员可知每一个函数都会有自己的标识信息,电子设备可以对每个函数的标识信息进行处理,例如采用预设的比特来标识对应的函数。
图5示出了本申请实施例提供的trace点信息获取与存储的另一示意图。
图5中的追踪点3(TracePoint3)表示在函数的入口获取进入该函数的时刻和函数的标识信息,获取进入该函数的时刻和函数的标识信息的方式可以是直接读取CPU中的寄存器。示例性的,进入该函数的时刻可以占32比特,函数的标识信息可以占32比特。
图5中的追踪点4(TracePoint4)表示在函数的出口获取退出该函数的时刻,实现方 式可以是直接从CPU中的寄存器获取该信息。示例性的,退出该函数的时刻可以占32比特。
一个实施例中,在TracePoint3,电子设备可以从第一寄存器中获取进入该函数的时刻且从第二寄存器中获取该函数的标识信息。在TracePoint4,电子设备可以从第一寄存器获取退出该函数的时刻。
相比于图4中所示的方法,此时内存中存储是函数的时间和函数的标识信息,需要将函数的标识信息转换成函数名(或者,函数字符串),实现方式可以是调用ART中已有接口:ArtMethod::PrettyMethod()。
一个实施例中,电子设备可以在将环形内存中保存的函数的标识信息写入trace文件时,将函数的标识信息转化为函数名(或者,函数字符串)。
应理解,图5中是以在TracePoint3获取函数的标识信息为例进行说明的,本申请实施例中并不做具体限定。也可以是在TracePoint4获取函数的标识信息;或者,也可以是在执行函数中的任意一个时间点获取函数的标识信息。
示例性的,表1示出了一种环形内存中保存的trace点信息。
表1 环形内存中保存的trace点信息
函数的标识信息 进入函数的时刻 退出函数的时刻
标识1 时刻1 时刻4
标识2 时刻2 时刻5
标识3 时刻3 时刻6
本申请实施例中,获取到的trace点信息写入内存时可以不保存函数名,而是记录该函数标识信息,仅在最后将内存信息导出到文件时,将函数标识信息与函数名匹配,然后将函数名写入trace文件中。这种处理方式的好处是保证写入内存的耗时尽量短,以节约写入带来的性能开销。
一个实施例中,函数的标识信息可以为函数的指针地址;或者,函数的标识信息可以是函数的其他标识信息,例如,采用预设的比特来标识对应的函数。
示例性的,表2示出了本申请实施例中获取到的trace调用链。其中,trace调用链中每行左侧数字表示时间(单位为纳秒),每行右侧表示函数名称字符串,POP表示函数的出口。
表2 trace调用链
Figure PCTCN2021081046-appb-000003
Figure PCTCN2021081046-appb-000004
示例性的,第三行的POP可以表示第二行函数int android.view.Window.getFeatures()的出口;第四行的POP可以表示第一行函数boolean android.view.Window.hasFeature(int)的出口。第五行的POP可以表示函数boolean android.view.Window.hasFeature(int)的上一层函数(表2中未示出)的出口。
应理解,在从环形内存导出到trace文件时,如果环形内存中直接保存的是函数名,那么trace文件时可以直接如表2所示;若在环形内存中保存的是函数的标识信息,则需要先通过函数的标识信息确定对应的函数名。例如,在环形内存中保存的是函数的标识信息,则可以通过已有接口ArtMethod::PrettyMethod()确定函数名。
trace文件可以借用火焰图(flame graphs)打开,图6示出了本申请实施例中trace文件火焰图的示意图。其中,图中的横轴表示时间,宽度越宽,表示对应函数调用耗时越长。其中,宽度值可以由函数入口和函数出口的时间差确定。纵轴表示函数调用关系,从上到下依次调用(例如,最上层函数调用第二层函数,第二层函数调用第三层函数,依次调用)。通过火焰图可以快速知道哪个或者哪几个函数调用耗时长,耗时异常的即为性能问题发生分析点。
本申请实施例可以获取到Android系统从应用程序层到框架层全量的高性能trace调用链,该方法对系统性能消耗非常低(不增加函数执行的耗时),见表3和表4所示的实验数据。
表3和表4中对手机1(64位模式)和手机2(32位模式)做实验,实验方法为将如下代码运行十万次,计算每次的时间值(共实验50轮,数据取50轮平均值)。
long myAdd(long a,long b){
      log.d("xxxxx");
      return a+b;
           }
表3 对手机1进行测试得到的实验数据
Figure PCTCN2021081046-appb-000005
表4 对手机2进行测试得到的实验数据
Figure PCTCN2021081046-appb-000006
从实验数据看,使用了本申请的获取trace调用链的方法,在32位和64位模式下,对函数调用时长增加的影响极小(在1%以内)。
得益于本申请实施例中获取trace调用链极小的性能开销,使trace能力能在Android系统运行时常开(不影响用户体验,不会使系统性能恶化),trace能力常开能保证抓到性能问题发生的现场,抓到的现场信息对Android性能问题定界定位有直接的帮助。
本申请实施例中可跟踪的调用链深度足够深(全量调用链),使性能问题分析可以到函数代码粒度。同时基于本申请实施例,不仅可以获取到trace调用链,还能获取到其他信息,比如线程ID、CPU负载信息等等。
图7示出了本申请实施例提供的采集trace调用链的方法700的示意性流程图。如图7所示,该方法700包括:
S701,该电子设备从寄存器中获取函数的时间信息和标识信息,该时间信息包括进入该函数的时刻以及退出该函数的时刻。
示例性的,如图4所示,电子设备可以从寄存器中读取函数入口的时间信息、函数出口的时间信息以及函数的标识信息。
S702,该电子设备将该时间信息和该标识信息存储在内存中。
示例性的,如图4所示,电子设备可以将这些信息存储在环形内存中。
S703,在满足预设条件时,该电子设备根据该标识信息确定该函数对应的函数名,并将该内存中的该时间信息以及该函数名写入trace文件。
应理解,S703中的预设条件可以参考上述实施例中预设条件的描述,为了简洁,在此不再赘述。
本申请实施例中,电子设备可以直接从寄存器中获取时间信息和标识信息,这样的处理方法省去了函数调用的开销,从而对系统性能的消耗非常小(不影响用户体验,不会使系统性能恶化);该方法还可以获取到完整的调用路径,从而可以保证抓到性能问题发生的真正现场,对系统性能问题的定位提供准确的信息。
在一些可能的实现方式中,该内存为环形内存。
可选地,该电子设备根据该标识信息确定该函数对应的函数名,包括:该电子设备调用转化接口,将该函数的标识信息转化为该函数名。
本申请实施例中,电子设备在内存中保存的是函数的标识信息而不是函数对应的函数名,减少了电子设备在将时间信息和标识信息写入内存的耗时,从而降低了写入带来的性能开销。
可选地,该转化接口为ArtMethod::PrettyMethod()接口。应理解,本申请实施例中对接口的名称并不作限定,还可以是其他转化接口。
在一些可能的实现方式中,该函数可以是由预设比特数标识。
可选地,该标识信息为该函数的指针地址。
本申请实施例中,电子设备可以从寄存器中获取函数的指针地址,通过保存指针地址而不是保存函数名,减少了电子设备在将时间信息和标识信息写入内存的耗时,从而降低了写入带来的性能开销。
可选地,该寄存器包括第一寄存器和第二寄存器,该电子设备从寄存器中获取函数的时间信息和标识信息,包括:该电子设备在该函数开始运行时,从该第一寄存器获取进入该函数的时刻且从该第二寄存器获取该函数的标识信息;该电子设备在该函数运行结束时,从该第一寄存器获取退出该函数的时刻。
示例性的,如图5所示,电子设备可以在函数开始运行时(TracePoint3),从第一寄存器中获取进入函数的时刻且从第二寄存器中获取函数的标识信息;电子设备可以在函数运行结束时(TracePoint4)获取退出该函数的时刻。
本申请实施例中,电子设备可以在函数开始运行时,获取进入该函数的时刻以及函数的标识信息,在函数运行结束时,获取退出该函数的时刻。从而将相应的时间信息和标识信息保存在内存中,这样的处理方法省去了函数调用的开销,从而对系统性能的消耗非常小(不影响用户体验,不会使系统性能恶化);该方法还可以获取到完整的调用路径,从而可以保证抓到性能问题发生的真正现场,对系统性能问题的定位提供准确的信息。
应理解,本申请实施例中,可以是在函数开始运行时,从寄存器获取进入该函数的时刻。也可以是从函数开始运行时的预设时长后记录一个时刻,之后电子设备可以通过该时刻与预设时长确定进入该函数的时刻。
或者,也可以在函数结束运行前的预设时长记录一个时刻,之后电子设备可以通过该时刻与预设时长确定退出该函数的时刻。
可选地,实现该方法700的代码在该电子设备的安卓运行时ART中。
本申请实施例中,实现上述方法的代码可以在电子设备的ART中,这样避免了在应用程序层或者框架层中添加代码。
本申请实施例还提供了一种电子设备,该电子设备可以包括如图1所示的处理器110以及存储器,存储器存储有一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行方法700中S701、S702和S703的步骤。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以 通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (14)

  1. 一种采集追踪trace调用链的方法,所述方法应用于电子设备中,其特征在于,所述方法包括:
    所述电子设备从寄存器中获取函数的时间信息和标识信息,所述时间信息包括进入所述函数的时刻以及退出所述函数的时刻;
    所述电子设备将所述时间信息和所述标识信息存储在内存中;
    在满足预设条件时,所述电子设备根据所述标识信息确定所述函数对应的函数名,并将所述内存中的所述时间信息以及所述函数名写入trace文件。
  2. 根据权利要求1所述的方法,其特征在于,所述电子设备根据所述标识信息确定所述函数对应的函数名,包括:
    所述电子设备调用转化接口,将所述函数的标识信息转化为所述函数名。
  3. 根据权利要求1或2所述的方法,其特征在于,所述标识信息为所述函数的指针地址。
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述寄存器包括第一寄存器和第二寄存器,所述电子设备从寄存器中获取函数的时间信息和标识信息,包括:
    所述电子设备在所述函数开始运行时,从所述第一寄存器获取进入所述函数的时刻且从所述第二寄存器获取所述函数的标识信息;
    所述电子设备在所述函数运行结束时,从所述第一寄存器获取退出所述函数的时刻。
  5. 根据权利要求1至4中任一项所述的方法,其特征在于,所述预设条件包括:所述电子设备启动第一应用程序的时长大于或者等于预设时长;或者,
    所述电子设备的丢帧数大于或者等于预设帧数。
  6. 根据权利要求1至5中任一项所述的方法,其特征在于,实现所述方法的代码在所述电子设备的安卓运行时ART中。
  7. 一种电子设备,其特征在于,包括:
    一个或多个处理器;
    一个或多个存储器;
    所述一个或多个存储器存储有一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    从寄存器中获取函数的时间信息和标识信息,所述时间信息包括进入所述函数的时刻以及退出所述函数的时刻;
    将所述时间信息和所述标识信息存储在内存中;
    在满足预设条件时,根据所述标识信息确定所述函数对应的函数名,并将所述内存中的所述时间信息以及所述函数名写入trace文件。
  8. 根据权利要求7所述的电子设备,其特征在于,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    调用转化接口,将所述函数的标识信息转化为所述函数名。
  9. 根据权利要求7或8所述的电子设备,其特征在于,所述标识信息为所述函数的指 针地址。
  10. 根据权利要求7至9中任一项所述的电子设备,其特征在于,所述寄存器包括第一寄存器和第二寄存器,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    在所述函数开始运行时,从所述第一寄存器获取进入所述函数的时刻且从所述第二寄存器获取所述函数的标识信息;
    在所述函数运行结束时,从所述第一寄存器获取退出所述函数的时刻。
  11. 根据权利要求7至10中任一项所述的电子设备,其特征在于,所述预设条件包括:所述电子设备启动第一应用程序的时长大于或者等于预设时长;或者,
    所述电子设备的丢帧数大于或者等于预设帧数。
  12. 根据权利要求7至11中任一项所述的电子设备,其特征在于,所述指令包含在所述电子设备的安卓运行时ART中。
  13. 一种计算机存储介质,其特征在于,包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求1-6中任一项所述的采集追踪trace调用链的方法。
  14. 一种计算机程序产品,其特征在于,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如权利要求1-6中任一项所述的采集追踪trace调用链的方法。
PCT/CN2021/081046 2020-03-26 2021-03-16 一种采集追踪trace调用链的方法和电子设备 WO2021190354A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010225986.8 2020-03-26
CN202010225986.8A CN113448815B (zh) 2020-03-26 2020-03-26 一种采集追踪trace调用链的方法和电子设备

Publications (1)

Publication Number Publication Date
WO2021190354A1 true WO2021190354A1 (zh) 2021-09-30

Family

ID=77807359

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/081046 WO2021190354A1 (zh) 2020-03-26 2021-03-16 一种采集追踪trace调用链的方法和电子设备

Country Status (2)

Country Link
CN (1) CN113448815B (zh)
WO (1) WO2021190354A1 (zh)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116074628A (zh) * 2022-05-30 2023-05-05 荣耀终端有限公司 一种数据处理方法及电子设备
CN116701134A (zh) * 2022-10-14 2023-09-05 荣耀终端有限公司 一种数据处理方法和电子设备
CN116881089A (zh) * 2023-09-07 2023-10-13 浙江保融科技股份有限公司 一种用于调用链状态回传状态下埋点及埋点管理的方法
CN117171058A (zh) * 2023-11-03 2023-12-05 睿思芯科(深圳)技术有限公司 调用链实时追踪方法、系统及相关设备
CN117724664A (zh) * 2024-02-18 2024-03-19 芯来智融半导体科技(上海)有限公司 数据写入方法、装置、设备及存储介质

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114826639B (zh) * 2021-11-01 2024-03-19 中国工商银行股份有限公司 基于函数调用链跟踪的应用攻击检测方法及装置
CN114115746A (zh) * 2021-12-02 2022-03-01 北京乐讯科技有限公司 一种用户态存储系统的全链路追踪装置
CN114398296B (zh) * 2022-03-24 2022-09-27 荣耀终端有限公司 用于问题定位的方法和终端设备
CN114936040A (zh) * 2022-05-31 2022-08-23 北京达佳互联信息技术有限公司 程序数据处理方法、装置、电子设备、存储介质

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043594A (zh) * 2010-12-31 2011-05-04 中科海量存储技术(北京)有限公司 分布式环境下实现输入输出踪迹收集回放的系统和方法
US20150095626A1 (en) * 2013-09-30 2015-04-02 Fujitsu Limited Trace method and information processing apparatus
CN106649084A (zh) * 2016-09-14 2017-05-10 腾讯科技(深圳)有限公司 函数调用信息的获取方法及装置、测试设备
CN106909431A (zh) * 2015-12-22 2017-06-30 阿里巴巴集团控股有限公司 定位函数性能问题的方法及装置
CN108595319A (zh) * 2018-03-30 2018-09-28 阿里巴巴集团控股有限公司 函数选取方法和服务器
CN109344083A (zh) * 2018-11-05 2019-02-15 郑州云海信息技术有限公司 一种程序调试方法、装置、设备及可读存储介质

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040054991A1 (en) * 2002-09-17 2004-03-18 Harres John M. Debugging tool and method for tracking code execution paths
JP2008059402A (ja) * 2006-09-01 2008-03-13 Movell Software:Kk リアルタイム診断システムおよびリアルタイム診断方法
US8214807B2 (en) * 2007-01-10 2012-07-03 International Business Machines Corporation Code path tracking
CN102681886A (zh) * 2011-04-14 2012-09-19 天脉聚源(北京)传媒科技有限公司 一种移动设备上用户行为追踪的方法和系统
US8910124B1 (en) * 2011-10-31 2014-12-09 Google Inc. Low-overhead method and apparatus for collecting function call trace data
JP6075204B2 (ja) * 2013-05-17 2017-02-08 富士通株式会社 性能情報収集プログラム、情報処理装置及び性能情報収集方法
CN103559123B (zh) * 2013-10-24 2016-02-10 烽火通信科技股份有限公司 基于VxWorks操作系统的函数调用栈分析方法及装置
CN105242873B (zh) * 2014-06-27 2018-06-01 阿里巴巴集团控股有限公司 云计算系统的性能数据的采集与存储方法及装置
CN106940681B (zh) * 2017-03-11 2020-07-21 苏州浪潮智能科技有限公司 一种利用跟踪函数和解析工具调试存储软件的方法

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043594A (zh) * 2010-12-31 2011-05-04 中科海量存储技术(北京)有限公司 分布式环境下实现输入输出踪迹收集回放的系统和方法
US20150095626A1 (en) * 2013-09-30 2015-04-02 Fujitsu Limited Trace method and information processing apparatus
CN106909431A (zh) * 2015-12-22 2017-06-30 阿里巴巴集团控股有限公司 定位函数性能问题的方法及装置
CN106649084A (zh) * 2016-09-14 2017-05-10 腾讯科技(深圳)有限公司 函数调用信息的获取方法及装置、测试设备
CN108595319A (zh) * 2018-03-30 2018-09-28 阿里巴巴集团控股有限公司 函数选取方法和服务器
CN109344083A (zh) * 2018-11-05 2019-02-15 郑州云海信息技术有限公司 一种程序调试方法、装置、设备及可读存储介质

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116074628A (zh) * 2022-05-30 2023-05-05 荣耀终端有限公司 一种数据处理方法及电子设备
CN116074628B (zh) * 2022-05-30 2023-10-20 荣耀终端有限公司 一种数据处理方法及电子设备
CN116701134A (zh) * 2022-10-14 2023-09-05 荣耀终端有限公司 一种数据处理方法和电子设备
CN116701134B (zh) * 2022-10-14 2024-05-17 荣耀终端有限公司 一种数据处理方法和电子设备
CN116881089A (zh) * 2023-09-07 2023-10-13 浙江保融科技股份有限公司 一种用于调用链状态回传状态下埋点及埋点管理的方法
CN116881089B (zh) * 2023-09-07 2023-12-05 浙江保融科技股份有限公司 一种用于调用链状态回传状态下埋点及埋点管理的方法
CN117171058A (zh) * 2023-11-03 2023-12-05 睿思芯科(深圳)技术有限公司 调用链实时追踪方法、系统及相关设备
CN117171058B (zh) * 2023-11-03 2024-02-20 睿思芯科(深圳)技术有限公司 调用链实时追踪方法、系统及相关设备
CN117724664A (zh) * 2024-02-18 2024-03-19 芯来智融半导体科技(上海)有限公司 数据写入方法、装置、设备及存储介质

Also Published As

Publication number Publication date
CN113448815B (zh) 2022-10-18
CN113448815A (zh) 2021-09-28

Similar Documents

Publication Publication Date Title
WO2021190354A1 (zh) 一种采集追踪trace调用链的方法和电子设备
WO2021083378A1 (zh) 一种加速应用程序启动的方法及电子设备
WO2022262530A1 (zh) 内存管理的方法及电子设备
WO2021057643A1 (zh) 一种多线程同步方法及电子设备
WO2022100221A1 (zh) 检索处理方法、装置及存储介质
WO2022100141A1 (zh) 插件管理方法、系统及装置
WO2021185352A1 (zh) 一种版本升级方法及相关装置
CN115016866A (zh) 应用启动时的数据处理方法、电子设备及存储介质
WO2023051355A1 (zh) 权限检查的方法和电子设备
CN110866254A (zh) 一种检测漏洞方法与电子设备
CN116048933A (zh) 一种流畅度检测方法
WO2022127130A1 (zh) 一种添加操作序列的方法、电子设备和系统
WO2021238376A1 (zh) 功能包的加载方法、装置、服务器和电子设备
CN117632400A (zh) 任务调度方法、电子设备及计算机可读存储介质
CN116450473A (zh) 踩内存问题的定位方法和电子设备
WO2024131486A1 (zh) 性能分析方法、可读存储介质、程序产品及电子设备
CN116088955B (zh) 进程处理方法和终端设备
CN115016921B (zh) 资源调度方法、装置及存储介质
WO2020147859A1 (zh) 分散式重锁降级
CN116700813B (zh) 微件的加载方法、电子设备及可读存储介质
CN117079596B (zh) 屏幕亮度调节方法、终端设备及存储介质
WO2024140891A1 (zh) 一种编译方法、电子设备及系统
CN113485923B (zh) 项目代码检测方法与装置、电子设备
WO2023051357A1 (zh) 一种虚拟设备运行方法
WO2023169212A1 (zh) 一种识别应用程序中sdk的方法、终端及服务器

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21776860

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21776860

Country of ref document: EP

Kind code of ref document: A1