Code tracking method and device based on probe specific recognition, equipment and medium
By dynamically inserting probes in the application, monitoring and analyzing the running data of key functional units, the problems of code intrusion and data overload in the existing technology are solved, and efficient and secure code tracking is achieved.
Patent Information
- Application Number
- CN202411868011.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-03-18
AI Technical Summary
Existing code tracking technologies have problems of code intrusion and data overload, making it difficult to take into account both code tracking efficiency and system security.
Using a probe-based specific identification method, probes are dynamically inserted to monitor key functional units of the application, collect and analyze running data, and generate analysis reports for code tracking.
Through non-invasive monitoring, it reduces the damage to the original code structure, improves the flexibility and scalability of code tracking, enhances system security, and improves the timeliness of problem discovery and resolution.
Smart Images

Figure CN119645774A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program monitoring technology, and in particular to a code tracking method, device, equipment and medium based on probe-specific identification. Background Art
[0002] With the rapid development of Internet technology and the complexity of the network environment, it is particularly important for developers to track the code implementation process. However, in software development technology, conventional code tracking technologies include: Using logging: inserting log statements at key locations in the code to record variable values, program status and other information. Debugger: The developer sets breakpoints, executes the code step by step, and observes the real-time evaluation process of variables and expressions. Some code analysis tools: used for performance analysis, can track the number of function calls, time overhead, etc. Distributed tracing system: used for microservice architecture or distributed systems. However, the above code tracking methods have the following problems:
[0003] If there are too many log records or the log level is set improperly, a large number of I / O operations will be generated, reducing system performance. For example, frequent log writing in high-concurrency scenarios will not only slow down the entire system, but may also generate massive amounts of data. In addition, when the log record location is inaccurate, key information may be missed. Code analysis tools can also interfere with system performance when collecting data, resulting in deviations between the measured performance data and the actual production environment. In a complex distributed environment, the link information of a distributed tracing system may be too complex to focus on the problem. In addition, some code tracing technologies have certain requirements for programming languages and frameworks, and there are compatibility issues. For example, some debugging tools can only be used for specific versions of programming languages; they are invasive to the code, and adding tracing code may change the original logic of the program.
[0004] It can be seen that conventional code tracking technology will make it difficult to balance code tracking efficiency and system security due to code intrusion and data overload. Summary of the invention
[0005] The present application provides a code tracking method, apparatus, device and medium based on probe-specific identification to solve the problem in the above-mentioned prior art that it is difficult to balance code tracking efficiency and system security due to code intrusion and data overload.
[0006] According to one aspect of an embodiment of the present application, the present application provides a code tracing method based on probe-specific identification, the method comprising: determining a monitoring target of the probe based on the code complexity of an application; creating the probe, and dynamically inserting the probe into the monitoring target when the application starts; retrieving the operating data of the monitoring target based on the probe; performing modular analysis on the operating data, and generating an analysis report, so as to perform code tracking on the application according to the analysis report.
[0007] Optionally, the monitoring target of the probe is determined based on the code complexity of the application, including: performing static code analysis on the functional units in the application based on the dependencies between code modules, and determining the first functional unit according to the code dependencies; determining the second functional unit according to the running time and calling frequency of the functional units in the application; and merging the first functional unit and the second functional unit as the monitoring target.
[0008] Optionally, the creation of the probe and the dynamic insertion of the probe into the monitoring target when the application is started include: creating a proxy class containing a program pre-main method in the application based on a target bytecode operation library, writing the business logic of the probe in the proxy class, and associating the business logic with the monitoring target; packaging the proxy class with the business logic written and the corresponding target bytecode operation dependency package to generate a corresponding target archive file, and placing the target archive file in a file corresponding to the monitoring target; and automatically loading the target archive file according to the operation and compilation of the monitoring target to complete the dynamic creation of the probe.
[0009] Optionally, the business logic of the probe is written in the proxy class, and the business logic is associated with the monitoring target, including: determining the target function of the probe based on the code tracking requirements of the monitoring target; creating a corresponding function in the program pre-main method of the proxy class according to the target function to write logic code; wherein the target function includes at least: recording the execution time of the monitoring target, detecting the memory operation status, recording the method processing information and exception information of the monitoring target; and using the target bytecode operation library to bind the proxy class that has completed the logic code writing to the functional unit corresponding to the monitoring target.
[0010] Optionally, the retrieving the operation data of the monitoring target based on the probe includes: starting an application program, and the program pre-master method is automatically loaded based on the startup of the application program;
[0011] Based on the loading of the program pre-main method, the function in the proxy class bound to each functional unit is automatically executed, and the target function is executed through the function to retrieve the operating data of the monitoring target.
[0012] Optionally, the operating data of the monitored target includes the execution time, number of calls, exception logs and memory usage data of the functional unit, and the modular analysis of the operating data generates an analysis report to track the code of the application according to the analysis report, including: modular analysis of the execution time, number of calls, exception logs and memory usage data of the functional unit to obtain the average execution time, call frequency, exception information and memory change status of the functional unit; visualizing the average execution time, call frequency, exception information and memory change status of the functional unit and / or generating a performance report of the application; and realizing real-time monitoring of the application code based on data visualization and / or the performance report.
[0013] Optionally, the code tracking method based on probe-specific identification also includes: using a circular buffer area to cache the operation data of the monitoring target retrieved by the probe, specifically including: checking the circular buffer area to determine whether the data in the database overflows; if the data overflows, using the operation data to replace the historical data in the database; if the data does not overflow, storing the operation data in the database.
[0014] According to another aspect of an embodiment of the present application, the present application provides a code tracking device based on probe-specific identification, the device comprising: a probe monitoring module, for determining a monitoring target of the probe based on the code complexity of an application; a probe management module, for creating the probe and dynamically inserting the probe into the monitoring target when the application starts; a data acquisition module, for retrieving the operating data of the monitoring target based on the probe; a data analysis module, for performing modular analysis on the operating data and generating an analysis report, so as to perform code tracking on the application according to the analysis report.
[0015] According to another aspect of an embodiment of the present application, the present application provides an electronic device, including a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, the memory and the processor communicate through the communication bus and the communication interface, and the processor implements the steps of a code tracking method based on probe-specific identification when executing the computer program.
[0016] According to another aspect of an embodiment of the present application, the present application provides a computer-readable medium having a non-volatile program code executable by a processor, wherein a code tracking program based on probe-specific identification is stored on the computer-readable medium, and the code tracking program based on probe-specific identification, when executed by the processor, implements the steps of a code tracking method based on probe-specific identification.
[0017] The above technical solution provided by the embodiment of the present application has the following advantages compared with the related art:
[0018] This application can be applied to the debugging of code development in software development and the operation and maintenance scenarios after the application is launched. This application can find out the functional units with high complexity and high dependence by determining the monitoring target of the probe, which helps to accurately locate the performance bottlenecks and high-risk parts in the program. In addition, by dynamically inserting probes in the monitoring target, it is convenient for large-scale deployment and management, improves the flexibility and scalability of code tracking, and is more conducive to improving the efficiency of code tracking; by monitoring the code of the monitoring target and obtaining monitoring data through the probe, non-intrusive monitoring of the code is realized. Since there is no need to directly modify the source code, the damage to the original code structure and the risk of introducing new errors are reduced, which is more conducive to enhancing system security; by modularly analyzing the data obtained by the probe, it is convenient for developers to monitor the operation of the program code in real time and discover problems, and can quickly locate problems, shorten the time to locate problems, improve the timeliness of problem discovery and resolution, and ensure the safe and stable operation of the program. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0021] Figure 1 A schematic diagram of a hardware environment for an optional code tracing method based on probe-specific identification provided according to an embodiment of the present application;
[0022] Figure 2 A schematic flow chart of an optional code tracking method based on probe-specific identification provided according to an embodiment of the present application;
[0023] Figure 3 A schematic diagram of an optional probe creation method flow chart provided according to an embodiment of the present application;
[0024] Figure 4 A schematic diagram of an optional data analysis process provided according to an embodiment of the present application;
[0025] Figure 5 A structural diagram of an optional code tracking device based on probe-specific identification provided according to an embodiment of the present application;
[0026] Figure 6 A schematic diagram of an optional electronic device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0028] In order to solve the problems mentioned in the background technology, according to one aspect of the embodiments of the present application, an embodiment of a code tracking method based on probe-specific identification is provided.
[0029] like Figure 1 As shown, the code tracking method based on probe-specific identification can be applied to Figure 1 In the hardware environment shown. The system architecture 100 of the hardware environment includes a terminal device 101 and a server 103. The server 103 is connected to the terminal 101 through a network and can be used to provide services for the terminal or a client installed on the terminal. A database 105 can be set on the server or independently of the server to provide data storage services for the server 103. The network can include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0030] The user can use the terminal device 101 to interact with the server 103 through the network to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, search applications, instant messaging tools, etc. Among them, the terminal device 101 can be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, dynamic image experts compression standard audio layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic image experts compression standard audio layer 4) players, laptops and desktop computers, etc. The server 103 can be a server that provides various services, such as a background server that supports the pages displayed on the terminal device 101.
[0031] It should be noted that the code tracking method based on probe-specific identification provided in the embodiment of the present application is generally executed by a server and / or a terminal device, and accordingly, the code tracking device based on probe-specific identification is generally set in the server / terminal device. Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0032] like Figure 2 As shown, Figure 2 A flowchart of a code tracking method based on probe-specific identification provided by an embodiment of the present invention. Taking the code tracking method based on probe-specific identification executed by a server as an example, a code tracking method based on probe-specific identification includes the following steps:
[0033] Step S202: determining a monitoring target of the probe based on the code complexity of the application program.
[0034] In this embodiment, the code tracking method based on probe-specific identification is applicable to software development scenarios. Static code analysis tools can be used to calculate code complexity, identify functional units based on code complexity, that is, identify functions or modules, and then analyze the dependencies between the identified code modules, and finally determine the monitoring targets from the identified modules based on coverage and complexity. Among them, functions or modules may include: complex business rules and logic, operation modules for large-scale data processing, parsing, and conversion, modules that interact with databases, modules that are frequently called by multiple public libraries, modules that capture and handle exceptions, etc.
[0035] In this embodiment, a performance analysis tool can be used to monitor the performance of the system. Through dynamic analysis, functions or modules that take a preset time and whose calling frequency reaches a preset frequency threshold are found out, and the found functions or modules are determined as monitoring targets of the probe to facilitate real-time monitoring of these functions or modules. At the same time, exception logs that occur during system operation are collected, the causes of the exceptions are analyzed, and the normal operation of the code is ensured.
[0036] Specifically, the above-mentioned static analysis and dynamic analysis methods for searching functions or modules can help accurately locate possible performance bottlenecks and high-risk parts of the system, concentrate resources on the areas that need the most attention, avoid wasting resources caused by monitoring all codes, and improve the efficiency and pertinence of tracking. Static analysis can check the code structure and code logic without running the code, for example, checking the function call relationship, loop nesting depth, etc.; dynamic analysis is performed when the code is running, and can observe the actual execution of the code, such as counting the number of function calls and running time at runtime.
[0037] Step S204: Create the probe, and dynamically insert the probe into the monitoring target when the application is started.
[0038] In some embodiments, a dynamic configuration file, such as a JSON file, can be defined first. The configuration file includes logical codes such as monitoring conditions, specific code segments, conditions for capturing data, and output results. When the application is initialized, the system will load the configuration file and set the probe behavior according to the configuration file. The configuration file is loaded at runtime through the interface. If a change in the configuration file is detected, the monitoring range and capture conditions of the probe are dynamically adjusted according to the changed conditions. The system is continuously monitored according to the monitoring range and monitoring tasks of the probe in an adaptive manner to ensure the stability, security, and reliability of the system. This allows developers to adapt to different debugging and requirements when adjusting monitoring strategies. Dynamic adjustment can help developers more accurately control the monitoring range and reduce the impact on system performance. At the same time, problems can be discovered and solved in a timely manner.
[0039] Step S206: retrieve the operating data of the monitored target based on the probe.
[0040] In this embodiment, the operation data of the monitored function or module is obtained through the probe, which helps developers to promptly discover redundant parts in the code and improve the code quality. At the same time, it also helps to improve the testing efficiency and ensure the effectiveness and comprehensiveness of the test cases. The probe can record the calling relationship and calling frequency between each function or module, which helps to optimize the service layout, reduce the coupling between services, and improve the maintainability and scalability of the code.
[0041] In some embodiments, the above-mentioned operating data includes system resource usage data, such as memory usage, CPU occupancy, etc.; by monitoring these data, the resource consumption of the system under different loads can be clearly obtained, so as to reasonably allocate and optimize resources and avoid resource waste or insufficient resources leading to system performance degradation.
[0042] In some embodiments, the above-mentioned operating data includes exception logs and context information when the exception occurs, including variable status, call stack, etc.; by monitoring and recording this information, existing faults can be quickly located and repaired, and the rules of exception occurrence can be analyzed based on historical exception data, possible exceptions can be predicted, and preventive measures can be taken in advance.
[0043] Step S208, performing modular analysis on the operation data and generating an analysis report, so as to perform code tracking on the application program according to the analysis report.
[0044] In some embodiments, the data collected by the probe is analyzed modularly, covering multiple dimensions such as the average execution time of the function, the number of exceptions, and the call frequency, and the results are presented to the developer in the form of a line graph, providing a real-time viewing function through the Web application. Multi-dimensional analysis can help developers fully understand the system performance, and present it in the form of a visual line graph, which more intuitively presents the system performance trend and abnormal conditions. Developers can view it at any time through the Web application, which is convenient for real-time monitoring and problem discovery, and improves the timeliness of problem discovery and resolution.
[0045] In an embodiment of the present invention, the present application can identify functional units with higher complexity and higher dependence by determining the monitoring target of the probe, which helps to accurately locate the parts of the program that may have performance bottlenecks and high risks. In addition, by dynamically inserting probes into the monitoring targets, large-scale deployment and management are facilitated, the flexibility and scalability of code tracking are improved, and the efficiency of code tracking is improved. By monitoring the code of the monitoring target and obtaining monitoring data through the probe, non-intrusive monitoring of the code is achieved. Since there is no need to directly modify the source code, the damage to the original code structure and the risk of introducing new errors are reduced, which is more conducive to enhancing system security. By performing modular analysis on the data obtained by the probe and presenting the results to the developer in a visual manner, the developer can monitor the operation of the program code in real time and discover problems. This can quickly locate problems, shorten the time to locate problems, improve the timeliness of problem discovery and resolution, and ensure the safe and stable operation of the program.
[0046] In an optional embodiment, the above step S202 specifically includes:
[0047] Performing static code analysis on the functional units in the application program based on the dependency relationship between the code modules, and determining the first functional unit according to the code dependency;
[0048] Determine the second functional unit according to the running time and calling frequency of the functional unit in the application program;
[0049] The first functional unit and the second functional unit are combined as the monitoring target.
[0050] In this embodiment, the dependency of a function or module can be determined based on the calling relationship between functions or modules and the nesting depth of loop statements. The function or module with the highest dependency or the dependency value reaching the preset dependency threshold can be determined as the first functional unit. For nested functions, for example: for the conditional judgment statement if...else..., if other if...else... statements are contained inside, the number of nested ifs indicates the nesting depth. Since the code statements are static, this information can be identified by the code analysis tool. If the function or module is determined as the first functional unit based on the dependency value reaching the preset dependency threshold, the dependency value can be determined based on the total number of function calls. For the calling relationship, for example, function A calls function B, function B calls function C and function D, and function D calls function E. The total number of function calls is 5 times, and the corresponding dependency value is 5. If the preset dependency threshold is 4, the module or function corresponding to the dependency value of 5 can be determined as the first functional unit.
[0051] In this embodiment, static analysis is performed on the functional unit, i.e., the function or module, so that the code structure and code logic can be checked without running the code, including checking the function call relationship, loop nesting depth, etc., so as to accurately identify the dependency relationship between functions or modules. Functions or modules with higher dependencies will be called more frequently during operation, and the functions or modules with the highest dependency or whose dependency value reaches the preset dependency threshold can be monitored as monitoring targets to capture abnormal information in the first place. At the same time, performance analysis tools can be used to dynamically analyze the running time and calling frequency of functions or modules to monitor the performance of the system and find out functions or modules that take too long and have too high calling frequency, so as to collect abnormal logs that occur when the system is running and analyze the causes of abnormalities.
[0052] Among them, performance analysis tools can be selected from the Chrome DevTools tool in Google Browser, the Lighthouse open source tool, the WebPageTest online tool, etc., to quickly identify the complex business rules and logic in the system, operation modules for large-scale data processing, parsing, and conversion, modules that interact with the database, modules that are frequently called by multiple public libraries, modules that capture and handle exceptions, and other modules to obtain the monitoring target of the probe.
[0053] In an optional embodiment, in combination Figure 3 As shown, the above step S204 specifically includes:
[0054] S2041, creating a proxy class including a program pre-main method in the application based on the target bytecode operation library, writing the business logic of the probe in the proxy class, and associating the business logic with the monitoring target;
[0055] S2042, packaging the proxy class with the business logic written and the corresponding target bytecode operation dependency package to generate a corresponding target archive file, and placing the target archive file in a file corresponding to the monitoring target;
[0056] S2043, automatically loading the target archive file according to the running and compiling of the monitoring target to complete the dynamic creation of the probe.
[0057] In this embodiment, the target bytecode operation library can be a ByteBuddy bytecode operation library, and the target archive file can be a JAR file. Using the ByteBuddy bytecode operation library to dynamically modify the code program, inserting probes at runtime and after compilation can achieve non-intrusive monitoring of the code. Inserting probes at runtime and after compilation can dynamically modify the code without modifying the source code, and the application program can no longer be redeployed, reducing the damage to the original code structure and the risk of introducing new errors. At the same time, the automated insertion method facilitates large-scale deployment and management, improves the flexibility and scalability of code tracking, and makes the monitoring of the probe more flexible and efficient.
[0058] In an optional embodiment, in the above step S2041, writing the business logic of the probe in the proxy class and associating the business logic with the monitoring target specifically includes:
[0059] Determining the target function of the probe based on the code tracking requirement for the monitoring target;
[0060] According to the target function, a corresponding function is created in the program pre-main method of the proxy class to write logic code;
[0061] The target bytecode operation library is used to bind the proxy class that has completed the logic code writing to the functional unit corresponding to the monitoring target.
[0062] In some embodiments, the target function can be to record the execution time, method processing information, exception information and memory usage of the monitoring target; the pre-main method of the recorded program is mainly the premain method. When using the ByteBuddy bytecode operation library to dynamically modify the code program, first create a JAR agent containing the premain method, and realize automatic insertion through the loading agent mechanism. Among them, ByteBuddy allows the bytecode to be operated without modifying the source code, and can modify the behavior of the class when the class is loaded; the premain method is an entry in the Java Agent technology, which is executed before the main method of the main class of the program is executed, and the bytecode can be modified here.
[0063] Among them, the premain method is an entry method of the JAVA agent, which will be called at startup. You can use the premain method to write a class to configure the probe logic and bind it to the target class and method. After loading the JAR, the premain method will be executed at startup. The configuration will insert the probe into the target class and method. When the method in the target class is called, the probe logic will be automatically executed. This method can simplify the insertion and management of the probe logic for easy monitoring, debugging and subsequent optimization.
[0064] Furthermore, inserting probes at runtime and after compilation includes inserting relevant logic when defining the start and completion of method execution, when catching exceptions, and before specific code blocks or statements. First, the goal of the probe logic must be clearly defined, which can be to record the execution time of the method, detect memory usage, record method calls, input and output parameter settings, and record exception information, and finally capture exception information; define these functions as methods or classes, use ByteBuddy to bind the probe logic to the target and method, and then package the proxy class and ByteBuddy dependency package into a JAR file, place this JAR file in the corresponding file, load the JAR when the application starts running, and dynamically insert the probe. Among them, the logic code of the probe can verify the logic method through unit testing and integration testing.
[0065] In some examples, ASM, Javassist, and CGLIB can be used instead of ByteBuddy to create and insert probes. ASM is a general Java bytecode manipulation and analysis framework that provides low-level manipulation functions for Java bytecodes and allows direct manipulation of bytecode instructions. It is very flexible, but relatively complex to use and requires a deep understanding of the structure and opcodes of Java bytecodes. Javassist is a bytecode editing library that provides a more advanced API than ASM. It is relatively simple to use and allows bytecodes to be manipulated with source-level syntax, such as modifying method bodies, adding member variables and methods, etc., without having to know too much about the details of the bytecode. CGLIB is developed based on ASM and is mainly used to dynamically generate and modify Java classes at runtime, especially to create proxies for classes that do not implement interfaces; CGLIB can extend classes to intercept and modify class methods.
[0066] In this embodiment, by encapsulating the probe logic into a method or class and dynamically binding it to the target method using the target bytecode operation library, the probe logic can be easily added, modified or deleted without making a lot of modifications to the original code. By inserting probes at multiple key nodes such as the start of method execution, completion of execution, and catching exceptions, the operation data can be obtained in real time for real-time monitoring and problem location. When the system has performance problems or exceptions, the location and context of the exception can be accurately recorded, including the input and output parameters of the method, exception information, etc., so that developers can quickly locate the problem. The probe can monitor the execution time of the method, as well as the memory usage and exception information, and record the call status of the method at the same time, evaluate the system from multiple angles, and conduct a comprehensive analysis of the health status of the system, providing developers with rich information to better maintain and optimize the system, significantly improving the efficiency of troubleshooting of the application, and solving the problem that the existing technology is difficult to balance code tracking efficiency and system security.
[0067] In some embodiments, recording method execution time, memory usage and other performance indicators through probes helps to comprehensively evaluate system performance. When a service that runs for a long time is found to take too long to execute different methods, the code can be optimized to improve the overall performance of the system.
[0068] In some examples, by packaging the proxy class and ByteBuddy dependency package into a JAR file and inserting the probe in an external loading manner, the stability of the original system is guaranteed. In particular, for applications that have already been launched, if performance monitoring is required, there is no need to modify the original code, which avoids introducing new errors and reduces the risk to the existing system. In addition, by packaging the proxy class and ByteBuddy dependency into a JAR file, this JAR file can be easily deployed and used in different projects or different deployment environments as long as the same programming language and runtime environment are used, making the performance monitoring solution universal.
[0069] In this embodiment, the probe technology can be dynamically enabled and disabled, and asynchronous processing technology can be used. Developers can dynamically set it according to different stages or different scenarios, which can adapt to different development and operation and maintenance needs. It is not only suitable for debugging in the development stage but also for monitoring the production environment. In the process of using the probe, it is first necessary to clarify the scope and conditions of the probe capture in the configuration file, and then use the probe to collect and analyze data. When the configuration file is dynamically adjusted, the captured data can be optimized to ensure the relevance of the data. Real-time adjustment of the probe capture conditions by dynamically adjusting the configuration file can reduce the impact on system performance, help the system to optimize the probe behavior in time during operation, and ensure the stability and reliability of the system.
[0070] In an optional embodiment, the above step S204 specifically includes:
[0071] Starting the application, the program pre-master method is automatically loaded based on the startup of the application;
[0072] Based on the loading of the program pre-main method, the function in the proxy class bound to each functional unit is automatically executed, and the target function is executed through the function to retrieve the operating data of the monitoring target.
[0073] In this embodiment, by obtaining the execution time and call count of the functional module, the module or function where the performance bottleneck is located can be determined, which helps to optimize the service layout, reduce the coupling between services, and improve the maintainability and scalability of the system. By obtaining memory usage data, it can help developers understand the resource consumption of the system under different loads, so as to reasonably allocate and optimize resources and avoid performance degradation caused by resource waste or insufficient resources. By capturing exception logs, it can help to quickly locate and repair existing exceptions.
[0074] In some examples, by analyzing the function execution time and the number of calls, the module or function where the performance bottleneck is located can be determined. For example, for a web application, if the loading time of a certain page is too long, the function execution time data obtained by the probe can be used to find that the database query function takes a long time, and then optimize the database query statement or adjust the database index.
[0075] In other examples, the system load is evaluated based on the number of calls and resource usage data at different time points, such as the load during peak and trough periods. For example, if the number of requests to the monitoring system surges during a specific time period every day, the system's performance indicators such as response time and resource usage will change accordingly, and based on this, elastic expansion of resources or adjustment of service deployment strategies can be performed in advance.
[0076] In other examples, data collected over a long period of time by the probe can show the changing trend of system performance, whether it is gradually getting worse or remaining stable. For example, if data from consecutive weeks shows that the average execution time of a function is gradually increasing, it may be that the complexity of the code is increasing as new features are added, or that the growth in data volume has caused performance to deteriorate, thus alerting developers to take action.
[0077] In this embodiment, the operation data captured by the probe provides comprehensive and detailed information for system performance evaluation, troubleshooting, resource management and optimization, and is an important means to ensure efficient and stable operation of the system. In addition, by configuring specific conditions through probe technology, it is activated and collects data if the conditions are met. It can be set to record data when certain specific functions are called, specific parameter values appear, and specific exceptions are thrown. In this way, valuable and meaningful data can be screened out to avoid useless data occupying a large amount of storage space and causing space waste.
[0078] In an optional embodiment, in combination Figure 4 As shown, the above step S208 specifically includes:
[0079] S2081, performing modular analysis on the execution time, call times, exception logs, and memory usage data of the functional unit to obtain the average execution time, call frequency, exception information, and memory change status of the functional unit;
[0080] S2082, visualize the average execution time, call frequency, exception information and memory change status of the functional unit and / or generate a performance report of the application program;
[0081] S2083, based on the data visualization and / or the performance report, the code of the application program is monitored in real time.
[0082] In this embodiment, the running data of the monitored target includes the execution time, call count, exception log, and memory usage data of the functional units.
[0083] In some embodiments, the running time can be obtained using built-in methods of the programming language. For example, in C / C++, the clock function in the time.h library can be used to measure the user time and system time, or the gettimeofday function in the <sys / time.h library can be used to measure the wall clock time; in Python, the built-in time module can be used to measure the code execution time; in Java, the System.currentTimeMillis method can be used to measure the wall clock time, or the System.nanoTime method can be used to measure the more precise code execution time; in web front-end development, the Date.now method can be used to measure the code execution time; in the Go language, the Now() and Sub() methods in the time package can be used to measure the code execution time.
[0084] In some embodiments, the call frequency of a function can be obtained using the variable method. For example, a global variable is defined outside the function, and each time the function is called, the variable is incremented by one. When the program runs to completion, the value of the variable is output to obtain the call count of the function; or a static variable is defined inside the function, and each time the function is called, the variable is incremented by one. When the program runs to completion, the value of the variable is output to obtain the call frequency of the function.
[0085] In some embodiments, the call frequency of a function can also be obtained using decorators or class decorators. For example, a decorator function is defined before the function definition. The decorator function takes a function as a parameter and returns a new function. In the new function, the counter is first incremented by one, and then the original function is called. Each time the function is called, it will pass through the decorator function, thus implementing the counting function. A class decorator is a special decorator that can be used to decorate class methods. By defining a counter property in the class decorator and incrementing the counter each time the method is called, the call count of the class method can be counted. By obtaining the call frequency of the function as described above, it is convenient for resource allocation and load balancing.
[0086] In this embodiment, data visualization can be displayed in the form of time series graphs, comparison graphs, distribution statistics graphs, dashboards, etc. Among them, the time series graph can show the changes of performance indicators over time, such as average execution time, memory usage, etc., which is convenient for observing trends and discovering periodic laws. The comparison graph can be a bar graph or a line graph, showing the performance indicators between different functions or modules, for example, the call frequency of the monitoring function or monitoring module; the distribution statistics graph can be a pie chart or a bar graph, showing the distribution of exception types according to the exception log, and understanding the proportion of various exceptions in the system; the dashboard displays multiple performance indicators in an intuitive interface, which is convenient for quickly viewing the overall status of the system, and is suitable for monitoring the status of the system when it is running.
[0087] Furthermore, for the average execution time and call frequency, a simple key-value pair can be used for storage, the exception log can be stored as text, and the memory change status can be stored as time series data. The acquired data can be sorted and analyzed, for example, the average, maximum, and minimum values of the average execution time over a period of time can be calculated, the number of occurrences of different types of exceptions can be counted, and the trend of memory usage can be analyzed.
[0088] Furthermore, before analyzing the data acquired by the probe, since the acquired data may contain some outliers, it is necessary to clean the data. For example, exclude some abnormally high or low execution time data points due to special circumstances, such as temporary system jitter. Data cleaning can use statistical methods, such as calculating the median, removing a certain proportion of the highest and lowest values, etc. Sum or average the call frequency data at different time points to obtain more macro call frequency information. Classify and organize the exception logs, count the number of occurrences of different types of exceptions, analyze the frequency and time distribution of the occurrence of exceptions, and find out the time period or module where the exceptions are concentrated. Smooth the memory data to remove some instantaneous fluctuations caused by factors such as garbage collection, and obtain a more stable memory usage trend.
[0089] Furthermore, for the average execution time and memory change status of a function or module, you can determine whether the performance is improving or deteriorating by calculating the trend over a period of time, such as the slope. You can also use methods such as linear regression to fit a straight line based on time series data, and the slope of the line represents the performance change trend.
[0090] Furthermore, functions or modules with a long average execution time or a high calling frequency may be performance bottlenecks. By analyzing the proportion of execution time of different functions or modules to the total time, we can determine the part that has the greatest impact on overall performance. Based on the above analysis results, we can formulate targeted function or module optimization suggestions to improve the overall performance of the system and ensure the reliability and stability of the system.
[0091] In this embodiment, the data collected by the probe is analyzed modularly, covering multiple dimensions such as the average execution time of the function, the number of exceptions, and the call frequency, which can help developers fully understand the system performance, and more intuitively present the system performance trend and abnormal conditions through data visualization, which is convenient for real-time monitoring and problem discovery, and improves the timeliness of problem discovery and resolution. At the same time, the probe technology can record the function call stack, user session information, process / thread data, and analyze complex runtime behaviors and lock positioning problems through a large amount of context information. When collecting data, high concurrency and high load methods are used to transmit data, which can ensure the minimum impact on system performance.
[0092] In an optional embodiment, the code tracking method based on probe-specific identification further includes:
[0093] The operation data of the monitoring target retrieved by the probe is cached using a circular buffer area, specifically including:
[0094] Checking the circular buffer to determine whether data in the database overflows;
[0095] If the data overflows, the historical data in the database is replaced with the operating data;
[0096] If the data does not overflow, the running data is stored in the database.
[0097] In this embodiment, a circular buffer is used to store data acquired by the probe, and two pointers can be used to control the writing and reading positions of the data, that is, the logic function of the probe is called in the function or module of the monitoring target, and the data is acquired by executing the logic function of the probe. When the pointer reaches the end of the array, it automatically wraps around, and at the same time checks whether the data overflows and performs corresponding processing. This caching method can realize circular storage of data within a limited memory space, avoid frequent data storage and deletion operations, and improve the efficiency of data storage. At the same time, the handling of overflow situations can ensure that data will not be lost, but strategically replace the data in the database, ensuring the continuity and integrity of the data.
[0098] It should be noted that although the circular buffer can improve storage efficiency, it may frequently replace data under high load, resulting in the loss of some important data or data inconsistency. Therefore, in this embodiment, two or more circular buffers are used. When one buffer is full and data is replaced, other buffers can continue to receive new data, reducing the risk of data loss.
[0099] According to another aspect of the embodiment of the present application, Figure 5As shown, corresponding to the code tracking method based on probe-specific identification in the above embodiment, this embodiment provides a code tracking device based on probe-specific identification, and the device includes:
[0100] The probe monitoring module 501 is used to determine the monitoring target of the probe based on the code complexity of the application program;
[0101] A probe management module 503 is used to create the probe and dynamically insert the probe into the monitoring target when the application is started;
[0102] A data acquisition module 505 retrieves the operation data of the monitoring target based on the probe;
[0103] The data analysis module 507 performs modular analysis on the operation data and generates an analysis report, so as to perform code tracking on the application program according to the analysis report.
[0104] It should be noted that, in this embodiment, the probe monitoring module 501 can be used to execute step S202 in the embodiment of the present application, the probe management module 503 in this embodiment can be used to execute step S204 in the embodiment of the present application, the data acquisition module 505 in this embodiment can be used to execute step S206 in the embodiment of the present application, and the data analysis module 507 in this embodiment can be used to execute step S208 in the embodiment of the present application.
[0105] Optionally, the probe monitoring module 501 specifically includes: a first probe monitoring sub-module, used to perform static code analysis on functional units in the application based on the dependency relationship between code modules, and determine the first functional unit according to the code dependency; determine the second functional unit according to the running time and calling frequency of the functional units in the application; and merge the first functional unit and the second functional unit as the monitoring target.
[0106] Optionally, the probe management module 503 specifically includes: a first probe management submodule, which is used to create a proxy class containing a program pre-main method in an application based on a target bytecode operation library, write the business logic of the probe in the proxy class, and associate the business logic with the monitoring target; a second probe management submodule, which packages the proxy class with the business logic written and the corresponding target bytecode operation dependency package, generates a corresponding target archive file, and places the target archive file in the file corresponding to the monitoring target; a third probe management submodule, which is used to automatically load the target archive file according to the operation and compilation of the monitoring target to complete the dynamic creation of the probe.
[0107] Optionally, the first probe management submodule specifically also includes: a first probe management subunit, used to determine the target function of the probe based on the code tracking requirements of the monitoring target; a second probe management subunit, used to create a corresponding function in the program pre-main method of the proxy class according to the target function to write logic code; and a third probe management subunit, used to use the target bytecode operation library to bind the proxy class that has completed the logic code writing to the functional unit corresponding to the monitoring target.
[0108] Optionally, the data acquisition module 505 includes: a startup submodule, used to start the application, and the program pre-main method is automatically loaded based on the startup of the application; a calling submodule, used to automatically execute the function in the proxy class bound to each functional unit based on the loading of the program pre-main method, and execute the target function through the function to call the operating data of the monitoring target.
[0109] Optionally, the data analysis module 507 specifically includes: a first data analysis sub-module, which is used to perform modular analysis on the execution time, call times, exception logs and memory usage data of the functional unit to obtain the average execution time, call frequency, exception information and memory change status of the functional unit; a second data analysis sub-module, which is used to visualize the average execution time, call frequency, exception information and memory change status of the functional unit and / or generate a performance report for the application; a third data analysis sub-module, which is used to realize real-time monitoring of the application code based on data visualization and / or the performance report.
[0110] Optionally, the device further comprises: a data storage module, configured to use a circular buffer area to cache the operation data of the monitoring target retrieved by the probe.
[0111] Optionally, the data storage module specifically includes: a data checking submodule, used to check the circular buffer area to determine whether the data in the database has overflowed; a data replacement submodule, used to replace the historical data in the database with the operating data if the data has overflowed; and a data storage submodule, used to store the operating data in the database if the data has not overflowed.
[0112] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.
[0113] It should be noted here that the suffixes such as module, component, unit, sub-module, and sub-unit used to represent elements described in the above device are only for the convenience of description of this application and have no specific meaning in themselves. Therefore, they can be used in combination.
[0114] According to another aspect of the embodiments of the present application, the present application provides an electronic device, such as Figure 6 As shown, it includes a memory 601, a processor 603, a communication interface 605 and a communication bus 606. The memory 601 stores a computer program that can be run on the processor 603. The memory 601 and the processor 603 communicate through the communication interface 605 and the communication bus 606. When the processor 603 executes the computer program, the steps of the code tracking method based on probe-specific identification are implemented.
[0115] The memory and processor in the above electronic device communicate via a communication bus and a communication interface. The communication bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus may be divided into an address bus, a data bus, a control bus, etc.
[0116] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0117] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0118] According to another aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of the code tracking method based on probe-specific identification in any of the above embodiments.
[0119] Optionally, in an embodiment of the present application, a computer-readable medium is configured to store program code for the processor to execute the steps of the code tracking method based on probe-specific identification described in the above embodiment.
[0120] Optionally, the specific examples in this embodiment can refer to the examples described in the above embodiments, and this embodiment will not be repeated here. And when the embodiments of this application are specifically implemented, they can refer to the above embodiments and have corresponding technical effects.
[0121] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application, or a combination thereof.
[0122] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0123] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0124] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0125] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0126] 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 purpose of the scheme of this embodiment. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0127] If 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. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art 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 a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
[0128] It should be noted that, in this article, relational terms such as first, second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms include, include or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0129] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A code tracking method based on probe-specific identification, characterized in that: The method comprises: Determine the monitoring target of the probe based on the code complexity of the application; Creating the probe, and dynamically inserting the probe into the monitoring target when the application is started; Retrieving the operation data of the monitoring target based on the probe; The operation data is modularly analyzed to generate an analysis report, so as to perform code tracking on the application program according to the analysis report.
2. The code tracking method based on probe-specific identification according to claim 1, characterized in that: The monitoring targets of the probes are determined based on the code complexity of the application, including: Performing static code analysis on the functional units in the application program based on the dependency relationship between the code modules, and determining the first functional unit according to the code dependency; Determine the second functional unit according to the running time and calling frequency of the functional unit in the application program; The first functional unit and the second functional unit are combined as the monitoring target.
3. The code tracking method based on probe-specific identification according to claim 2, characterized in that: The step of creating the probe and dynamically inserting the probe into the monitoring target when the application is started includes: Based on the target bytecode operation library, a proxy class including a program pre-main method is created in the application program, the business logic of the probe is written in the proxy class, and the business logic is associated with the monitoring target; Packing the proxy class and the corresponding target bytecode operation dependency package written by the business logic to generate a corresponding target archive file, and placing the target archive file in the file corresponding to the monitoring target; According to the operation and compilation of the monitoring target, the target archive file is automatically loaded to complete the dynamic creation of the probe.
4. The code tracking method based on probe-specific identification according to claim 3 is characterized in that: The step of writing the business logic of the probe in the proxy class and associating the business logic with the monitoring target includes: Determining the target function of the probe based on the code tracking requirement for the monitoring target; According to the target function, a corresponding function is created in the program pre-main method of the proxy class to write logic code; The target bytecode operation library is used to bind the proxy class that has completed the logic code writing to the functional unit corresponding to the monitoring target.
5. The code tracking method based on probe-specific identification according to claim 4, characterized in that: The step of retrieving the operation data of the monitoring target based on the probe includes: Starting the application, the program pre-master method is automatically loaded based on the startup of the application; Based on the loading of the program pre-main method, the function in the proxy class bound to each functional unit is automatically executed, and the target function is executed through the function to retrieve the operating data of the monitoring target.
6. The code tracking method based on probe-specific identification according to claim 5, characterized in that: The operation data of the monitoring target includes the execution time, call times, exception logs and memory usage data of the functional unit, and the modular analysis of the operation data to generate an analysis report to track the code of the application according to the analysis report includes: Perform modular analysis on the execution time, call times, exception logs and memory usage data of the functional unit to obtain the average execution time, call frequency, exception information and memory change status of the functional unit; Visualize the average execution time, call frequency, exception information and memory change status of the functional unit and / or generate a performance report of the application program; Real-time monitoring of the application code is achieved based on data visualization and / or the performance report.
7. The code tracking method based on probe-specific identification according to claim 5, characterized in that: The method further comprises: The operation data of the monitoring target retrieved by the probe is cached using a circular buffer area, specifically including: Checking the circular buffer to determine whether data in the database overflows; If the data overflows, the historical data in the database is replaced with the operating data; If the data does not overflow, the running data is stored in the database.
8. A code tracking device based on probe-specific identification, characterized in that: The device comprises: The probe monitoring module is used to determine the monitoring target of the probe based on the code complexity of the application; A probe management module is used to create the probe and dynamically insert the probe into the monitoring target when the application is started; A data acquisition module, for acquiring the operation data of the monitoring target based on the probe; The data analysis module performs modular analysis on the operation data and generates an analysis report so as to perform code tracking on the application program according to the analysis report.
9. An electronic device, comprising a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, and the memory and the processor communicate through the communication bus and the communication interface, characterized in that: When the processor executes the computer program, the code tracking method based on probe-specific identification described in any one of claims 1 to 7 is implemented.
10. A computer readable medium having a non-volatile program code executable by a processor, characterized in that: A code tracking program based on probe-specific identification is stored on a computer-readable medium, and when the code tracking program based on probe-specific identification is executed by a processor, the code tracking method based on probe-specific identification described in any one of claims 1 to 7 is implemented.