Performance analysis method, device, equipment and medium
By obtaining the starting thread and establishing thread statistics objects during the running of the program, combined with the performance analysis objects of business logic, the thread execution status is obtained in real time, which solves the problem of insufficient thread performance analysis in the existing technology and achieves efficient and accurate Performance monitoring and optimization.
Patent Information
- Application Number
- CN202410725701.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-08-23
AI Technical Summary
Existing performance analysis methods can only focus on the start and end positions of threads, and cannot obtain thread execution status in real time, resulting in thread execution performance analysis that is not accurate and efficient enough.
During the running of the program, the starting thread is obtained and the thread statistics object is established, the business logic is determined and the performance analysis object is generated. Through the combination of the thread statistics object and the performance analysis object, the execution time of the business logic is obtained in real time and performance analysis results are generated.
It achieves detailed analysis of business logic within threads, accurately locates locations with poor performance, improves analysis efficiency and accuracy, avoids system failures caused by thread blocking, and enhances the stability and response speed of financial services.
Smart Images

Figure CN118535440A
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and in particular to a performance analysis method, device, equipment and medium. Background Art
[0002] With the development of banking business and the update of computer technology, banking business is increasingly dependent on information-based business systems. Due to the particularity of banking business, banking business systems have high requirements for response speed and stability. Ensuring efficient and stable operation of business systems and avoiding system failures are of great significance to transaction convenience and security.
[0003] However, in business systems, threads are often used to process tasks when the code is running. However, if there is a code logic error or system anomaly that causes the thread execution time to be too long, the thread will be blocked. The continuous blocking of the thread will cause the task to pile up, and eventually it will exceed a certain limit and cause application failure. Taking payment transactions as an example, thread blocking can easily lead to user transaction failures. If an application failure occurs, it may even cause transaction data loss, affecting the user's transaction experience and even property safety. In order to avoid this problem, it is necessary to perform performance analysis on the thread.
[0004] For example, the time consumption can be counted by tracking at the beginning and end of the thread execution. However, this method can only track at the beginning and end of each thread and can only play a monitoring role, but cannot achieve the role of performance analysis. In addition, the execution stack of the thread can be captured during the program to obtain the execution status of the thread. You only need to execute certain commands on the server to see the execution status of the program's internal threads from the outside. This is very helpful for diagnosing problems by viewing the execution status of the thread at runtime. However, this method, such as timing to pull the execution status of the thread, cannot be obtained in real time. Real-time pulling of all thread information is likely to cause certain performance problems. In addition, timing pulling also has a certain delay. It is difficult to achieve fine-grained monitoring of thread execution time, so it is impossible to efficiently and accurately monitor the execution time of the thread. Summary of the invention
[0005] In view of this, the present application provides a performance analysis method, apparatus, medium and equipment, which solves the problem that the existing performance analysis method can only embed points at the beginning and end positions of the thread, and cannot pull the execution status of the thread in real time, resulting in the thread execution performance analysis being not accurate and efficient enough.
[0006] In a first aspect of the present application, a performance analysis method is provided, the method comprising:
[0007] During the program running process, a starting thread is obtained and the starting thread is used as a thread to be analyzed;
[0008] Establishing a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count a first start time and a first end time of the start thread;
[0009] Determine at least one business logic in the thread to be analyzed, and perform tracking for each of the business logics, and generate a performance analysis object corresponding to each of the business logics, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic;
[0010] Adding the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic;
[0011] A performance analysis result is generated according to the first start time, the first end time, the second start time and the second end time in the thread statistics object.
[0012] In a second aspect of the present application, a performance analysis device is provided, the device comprising:
[0013] An initialization module, used to obtain a starting thread and use the starting thread as a thread to be analyzed during program execution;
[0014] An object construction module is used to establish a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count the first starting time and the first ending time of the starting thread; and, determine at least one business logic in the thread to be analyzed, and perform tracking for each of the business logics respectively, and generate a performance analysis object corresponding to each of the business logics, wherein the performance analysis object includes a second starting time and a second ending time corresponding to the business logic; and, add the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic;
[0015] The analysis module is used to generate a performance analysis result according to the first start time, the first end time, the second start time and the second end time in the thread statistics object.
[0016] In a third aspect of the present application, a device is provided, including a storage medium, a processor, and instructions or codes stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned performance analysis method when executing the instructions or codes.
[0017] In a fourth aspect of the present application, a medium is provided, on which instructions or codes are stored, and when the instructions or codes are executed by a processor, the above-mentioned performance analysis method is implemented.
[0018] The solution implemented by the above-mentioned performance analysis method, device, equipment and medium obtains the execution time of the business logic in the thread by tracing the business logic in the thread, and then obtains the performance analysis result of the entire thread by analyzing the execution status of each business logic. Compared with the traditional method of tracing only at the beginning and end of the thread, this embodiment can deeply analyze each business logic in the thread, so the analysis is more detailed and can more accurately locate the location with poor performance; compared with the method of periodically pulling the execution status of the thread, the execution time of the business logic in this embodiment can be obtained in real time during the execution process, so there is no delay, the analysis process is more efficient, and the analysis results are more accurate.
[0019] Therefore, through such a method, during the system development and testing process, the locations that affect performance can be found in a timely and accurate manner, optimized, and the performance of the business system can be improved, allowing the bank to provide more responsive financial services; during the system application process, the slow execution locations can be located in a timely manner and processed in a targeted manner to avoid system failures or even crashes due to thread blocking, making the financial services provided by the bank more stable and avoiding the property safety of users being endangered by system failures.
[0020] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0022] Figure 1 A schematic diagram of a performance analysis method provided in an embodiment of the present application is shown;
[0023] Figure 2 A schematic diagram of another performance analysis method provided in an embodiment of the present application is shown;
[0024] Figure 3 A schematic diagram of a performance analysis tree of another performance analysis method provided by an embodiment of the present application is shown;
[0025] Figure 4 A structural block diagram of a performance analysis device provided in an embodiment of the present application is shown;
[0026] Figure 5 A structural block diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] The performance analysis method provided in the embodiment of the present application can be applied to electronic devices that have the ability to run instructions or programs. Among them, the electronic devices can be, but are not limited to, various servers, workstations, personal computers, laptops, etc. Running on different computing devices is only a difference in the execution subject of the scheme. People in this field can foresee that running on different computing devices can produce the same technical effect. The present invention is described in detail below through specific embodiments.
[0029] See also Figure 1 As shown, Figure 1 A schematic flow chart of a performance analysis method provided by an embodiment of the present invention includes the following steps:
[0030] S101: During program execution, a starting thread is obtained and used as a thread to be analyzed.
[0031] The method provided by the present invention can be used in the development, testing and operation and maintenance projects of the information business system in the financial field, and can be specifically used to analyze the performance of the thread of the business system. It can be understood that in the program running process of the information business system in the financial field, the corresponding tasks are executed through the thread. A program can run a single thread or multiple threads at the same time. For example, when a user performs a savings operation, the user's account is queried in the database through the thread, and a record of the savings operation is written for the user to modify the balance field of the user. In this process, if the thread execution time is too long, it will affect the response speed of the business system and may even cause the failure of the entire business system. For example, if the time to write the savings operation record is too long, the user will not receive feedback on the successful deposit, which will affect the user experience. If the entire system fails due to the long execution time, it may even cause the user's deposit operation to fail. Based on this, the performance analysis is performed on the thread to find the part that causes the thread execution time to be too long as soon as possible, and then optimize it, shorten the thread execution time, and improve the response speed and stability of the development project.
[0032] In this step, the starting thread is first obtained. Since this embodiment is applied to the program running process, points are buried and objects are generated during the program running process, and then the performance analysis of the thread is performed. Therefore, in the specific application process, the performance analysis method is executed during the program running process. When the performance analysis method is executed for the first time, the position where the program runs is the starting position, and the thread executed at this time is the starting thread. Taking the above-mentioned user savings operation as an example, the user can be queried in the database in response to the user's savings request as the starting position, and the thread executed when the savings operation starts can be used as the starting thread.
[0033] In actual application, if it is detected that the execution time of a thread is too long, the method of this embodiment is executed, and the thread executed at this time is the thread with too long execution time, that is, the thread with too long execution time is used as the starting thread. After determining the starting thread, it is used as the process to be analyzed, and its performance is analyzed to find the reason for the long execution time and then improve it.
[0034] It is understandable that all threads can be used for performance analysis using the method of this embodiment, and are not limited to analyzing threads with long execution time. For example, during the testing of a business system, testers can perform performance analysis on any thread and modify the code based on the analysis results to achieve software performance optimization. For example, before the system goes online, testers can perform performance analysis on threads of any specific application scenarios such as savings, transfers, and modification of payment passwords to ensure the response speed and stability of the system.
[0035] S102: Create a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count a first start time and a first end time of the start thread.
[0036] In this step, a corresponding thread statistics object is created for the thread to be analyzed, and in the following steps, the performance analysis of the thread to be analyzed can be performed based on the data in the thread statistics object. In actual applications, a function can be designed to automatically locate the thread to be analyzed using the designed function, and a thread statistics object can be created for the thread to be analyzed.
[0037] The thread statistics object includes a start time attribute and an end time attribute, which are used to record the start time and end time corresponding to the start thread, that is, the first start time and the first end time attributes. In addition, the thread statistics object may also include a duration calculation function, which is used to calculate the duration consumed by the entire thread to be analyzed during execution.
[0038] Taking the above user savings operation as an example, the thread executed when the savings operation starts can be used as the starting thread, the starting thread can be automatically located through the designed function, and a thread statistics object corresponding to the starting thread can be established. During the object establishment process, the time when the user's savings operation starts can be used as the first starting time, and the time when the savings operation is completed can be used as the first ending time.
[0039] It is understandable that, according to the actual application scenario and requirements, the thread statistics object may also include other properties and / or methods. For example, the thread statistics object may also include a duration alarm function. If the execution duration of the corresponding thread to be analyzed exceeds the preset duration threshold, an alarm prompt message is generated to facilitate testers to more quickly locate the part whose performance does not meet the actual business requirements and therefore needs to be optimized.
[0040] S103: Determine at least one business logic in the thread to be analyzed, and perform tracking for each business logic respectively to generate a performance analysis object corresponding to each business logic, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic.
[0041] It is understandable that during the execution of a thread, some business logic will be executed within the thread. For example, in the thread of user savings operation, the database table is first queried to determine whether there is a user ID corresponding to the user, and then if the user ID is found, the operation record corresponding to the savings operation is inserted into the database table, and then the savings balance corresponding to the user ID is modified. In this thread, there are user query business logic, operation record insertion business logic, and balance modification business logic.
[0042] Based on this, in this step, each business logic is tracked separately, and the time consumption during the execution of each business logic can be analyzed separately. In actual applications, different functions can be designed, and the designed functions can be used to automatically establish a performance analysis object for each business logic.
[0043] Among them, the performance analysis object includes a start time attribute and an end time attribute, which are used to record the start time and end time corresponding to the business logic, that is, the second start time and the second end time attributes. In addition, the performance analysis object may also include a time capture function, which is used to capture the second start time and the second end time corresponding to the business logic according to the buried point. The performance analysis object may also include a duration calculation function, which is used to calculate the duration consumed by the entire business logic during the execution process.
[0044] Specifically in the aforementioned user savings embodiment, corresponding performance analysis objects can be established for the user query business logic, the operation record insertion business logic, and the balance modification business logic, and each performance analysis object records the start time and end time of its corresponding business logic. For example, in the performance analysis object corresponding to the user query business logic, the time when the query for the user starts and the time when the query ends are recorded.
[0045] It is understandable that, according to the actual application scenario and requirements, the performance analysis object may also include other properties and / or methods. For example, the performance analysis object may also include a duration alarm function. If the execution time of the corresponding business logic exceeds the preset duration threshold, an alarm prompt message is generated to facilitate testers to more quickly locate the part where the performance does not meet the actual business requirements and thus requires performance optimization. Among them, due to the different complexity of different business logics, different duration thresholds can be preset for different business logics, and the more complex the business logic, the longer the corresponding duration threshold.
[0046] This embodiment refines the performance analysis of threads to the specific business logic in the threads. Compared with the traditional method of only tracking points at the start and end of each thread, this embodiment has a more detailed analysis and is more accurate in locating the locations with poor performance.
[0047] S104: Add the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic.
[0048] In this step, each thread to be analyzed may execute multiple business logics, and the performance analysis object corresponding to each business logic is added to the thread statistics object of the corresponding thread to be analyzed. At this time, in addition to the start time and end time of the thread to be analyzed, the thread statistics object also includes the start time and end time of each business logic in the thread to be analyzed. Therefore, when performing performance analysis on the thread, the time consumption of each business logic in the thread can be specifically analyzed.
[0049] In addition, since the business logic in the thread to be analyzed has a certain execution order, multiple performance analysis objects can be added to the thread statistics object of the thread to be analyzed in sequence according to the execution order of the business logic. Specifically in the aforementioned user savings embodiment, the performance analysis objects corresponding to the user query business logic, the operation record insertion business logic, and the balance modification business logic can be added to the thread corresponding to the savings operation in sequence according to the execution order of the business logic. This way of adding makes the structure of the thread statistics object more consistent with the actual execution process, so it is more readable and more conducive to troubleshooting.
[0050] S105: Generate a performance analysis result according to the first start time, the first end time, the second start time, and the second end time in the thread statistics object.
[0051] In this step, since the thread statistics object includes the first start time and the second end time corresponding to the thread, and also includes the second start time and the second end time corresponding to the business logic in the thread, these data can be comprehensively analyzed to obtain the final performance analysis result.
[0052] For example, taking the aforementioned savings operation as an example, if the execution time of the thread to be analyzed corresponding to the savings operation is too long according to the first start time and the second start time, the business logic in the thread is further analyzed. If the thread includes the aforementioned three business logics, and the execution time of the user query business logic is too long according to the second start time and the second end time, the code corresponding to the user query business logic can be analyzed in a targeted manner and optimized to shorten the execution time of the user query. If the execution time of the thread to be analyzed meets the actual needs, it is considered that the execution speed of the savings operation is fast enough and there is no need to optimize the thread, so the business logic in the thread can no longer be analyzed.
[0053] This embodiment tracks the business logic in the thread to obtain the execution time of the business logic in the thread, and then obtains the performance analysis result of the entire thread by analyzing the execution status of each business logic. Compared with the traditional method of only tracking at the beginning and end of the thread, this embodiment can deeply analyze each business logic in the thread, so the analysis is more detailed and can more accurately locate the location with poor performance; compared with the method of periodically pulling the execution status of the thread, the execution time of the business logic in this embodiment can be obtained in real time during the execution process, so there is no delay, the analysis process is more efficient, and the analysis results are more accurate.
[0054] Therefore, through such a method, during the system development and testing process, the locations that affect performance can be found in a timely and accurate manner, optimized, and the performance of the business system can be improved, allowing the bank to provide more responsive financial services; during the system application process, the slow execution locations can be located in a timely manner and processed in a targeted manner to avoid system failures or even crashes due to thread blocking, making the financial services provided by the bank more stable and avoiding the property safety of users being endangered by system failures.
[0055] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, another performance analysis method is provided, such as Figure 2 As shown, the method comprises the following steps:
[0056] S201: During program execution, a starting thread is obtained and the starting thread is used as a thread to be analyzed.
[0057] S202: Set the starting thread as the parent thread.
[0058] S203: Determine whether there is a child thread in the parent thread; if so, jump to step S204; if not, jump to step S205.
[0059] S204: Use the child thread as the thread to be analyzed, use the child thread as the new parent thread, and return to step S203.
[0060] In this step, during the execution of the program, each thread may generate a new thread, that is, a sub-thread. For example, in the thread of the user's savings operation, in addition to the aforementioned business logic, the user can also perform operations such as balance query. At this time, a sub-thread can be started inside the current thread, and the sub-thread is used to perform query operations in the balance table and feedback the query results to the user. Therefore, when analyzing the execution performance of a thread, the time consumption of its internal sub-threads can be analyzed.
[0061] Based on this, firstly, the starting thread is taken as the parent thread, and it is determined whether there is a child thread inside it. If there is, this child thread is also taken as the thread to be analyzed. Then the child thread is taken as the new parent thread, and it is further determined whether there is a child thread inside the new parent thread. This is repeated until there is no child thread in the new parent thread. At this point, a multi-level structure can be obtained, and each thread in the structure is taken as a thread to be analyzed for performance analysis.
[0062] S205: Creating a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count a first start time and a first end time of the start thread.
[0063] In this step, a corresponding thread statistics object is created for each thread to be analyzed. The creation method is similar to that in the above embodiment and will not be described again.
[0064] Among them, the thread statistics object includes thread name, thread start time, thread end time, thread parent-child relationship, etc. The thread name is used to uniquely identify a specific thread, the thread start time and thread end time are used to analyze the time consumption during the thread execution process, and the thread parent-child relationship includes the parent thread name and child thread name corresponding to the current thread, which are used to determine the parent thread object and child thread object corresponding to the current thread. In addition, the thread statistics object may also include thread description information, the starting thread name, the starting position corresponding to the starting thread, the starting time corresponding to the starting thread, etc.
[0065] Preferably, the thread statistics object can be cached in memory. Compared with the traditional method of storing performance data in the hard disk, caching in memory can improve the execution efficiency of the method.
[0066] S206: Determine at least one business logic in the thread to be analyzed.
[0067] S207: Split each business logic into multiple code blocks respectively, and determine the time consumption of the code blocks.
[0068] S208: If the time consumption is greater than a preset threshold, a point is buried at the position corresponding to the code block to generate a performance analysis object corresponding to the business logic, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic.
[0069] In this step, since the business logic can usually be divided into multiple code blocks, and the operations corresponding to some code blocks are relatively simple and do not need to be analyzed for performance, only the code blocks that may be time-consuming can be monitored and then performance analyzed. Specifically, the business logic is first divided into multiple code blocks according to the code structure, and then the time consumption of each code block is determined separately. If the time consumption is high, it is considered that the code block is a code block that may be time-consuming, so the point is buried at the position corresponding to the code block. It can be understood that in a business logic, there may be multiple code blocks with a time consumption higher than the preset time consumption, so multiple points may be buried, and a performance analysis object is generated for the business logic, and the information of the multiple buried points is recorded in the performance analysis object.
[0070] For example, the aforementioned user query business logic can be divided into code blocks such as receiving the user ID sent by the user, performing security and legality verification, calling the database interface after verification, querying the user ID in the database, and returning the query results. Analyze the time consumption of each code block. If the code block corresponding to the user ID sent by the user and the code block corresponding to the user ID query in the database are time-consuming, you can embed points for these two code blocks, and the performance analysis object corresponding to the user query business logic includes information on both points.
[0071] In the specific application process, the time consumption of each code block can be determined based on historical experience. For example, the time consumption of code blocks used to operate hardware, send or receive network requests, call files, and operate databases is relatively high.
[0072] S209: adding the performance analysis object corresponding to the business logic to the linear list of the thread statistics object of the to-be-analyzed thread corresponding to the business logic according to the execution order of the business logic.
[0073] In this step, the thread to be analyzed contains multiple business logics. The performance analysis object of each business logic will be added to the thread to be analyzed according to the execution order of the business logics. The principle and method are similar to those in the previous embodiment and will not be repeated here.
[0074] In the specific application process, since the business logic inside the thread is executed serially, a linear data structure can be used to save the performance analysis object. Specifically, the thread statistics object includes a linear table, and the performance analysis object is saved in the linear table according to the execution order of the business logic.
[0075] S210: Determine the child threads in each parent thread among the multiple threads to be analyzed, and add the thread statistics object of the child thread to the thread statistics object of the parent thread corresponding to the child thread.
[0076] In this step, if the parent thread contains child threads, the thread statistics object of each child thread is added to the thread statistics object of the parent thread. In this way, when analyzing the performance of the parent thread, the time consumption of each child thread in the parent thread can be intuitively judged, and then the child threads that consume more time can be accurately located and optimized.
[0077] Different from the business logic executed serially within the thread, multiple child threads within the parent thread can be executed in parallel. Therefore, when adding the thread statistics object of the child thread to the thread statistics object of the parent thread, a linear table is no longer used to save it.
[0078] Specifically in the aforementioned user savings embodiment, after the user requests a savings operation, while the server executes the savings operation record insertion, it can also provide the user with other services such as modifying the user contact information. At this time, the sub-thread of modifying the user contact information is parallel to the savings record insertion business logic, so the two are no longer recorded serially.
[0079] S211: Generate a performance analysis result according to the first start time, the first end time, the second start time, and the second end time in the thread statistics object.
[0080] S212: Taking the threads to be analyzed and the execution logic as nodes, a performance analysis tree with a tree structure is established according to the parent-child relationship between the multiple threads to be analyzed and the execution order between the multiple business logics, wherein the starting thread is the root node;
[0081] In this step, each thread to be analyzed and the execution logic are used as nodes to establish a tree structure to obtain a performance analysis tree. Among them, the starting thread is the root node of the performance analysis tree. In addition, the parent-child relationship between the threads to be analyzed is mapped to the performance analysis tree, that is, for any pair of threads with a parent-child relationship, they are also reflected as nodes with a parent-child relationship in the performance analysis tree, wherein the parent thread corresponds to the parent node in the performance analysis tree, and the child thread corresponds to the child node in the performance analysis tree. The execution order between multiple business logics is mapped to the performance analysis tree, that is, the first business logic executed inside any thread is the child node of the thread, the second business logic executed is the child node of the first business logic executed, and so on. The two business logics with adjacent execution orders are reflected in the performance analysis tree as nodes with a parent-child relationship, wherein the one in the execution order is the parent node, and the one in the execution order is the child node.
[0082] Figure 3 The performance analysis tree diagram of the performance analysis method of the embodiment of the present application is shown. As shown in the figure, thread 1 is the starting thread and is the root node in the performance analysis tree. Thread 1 contains three business logics. The business logic with the first execution order is used as the child thread of thread 1. The other business logics are arranged in order of execution. Figure 3 The leftmost branch. In addition, thread 1 also includes two child threads, thread 2 and thread 3, and these two child threads are regarded as child nodes of thread 1.
[0083] Similarly, thread 2 contains two business logics, thread 3 contains one business logic and a child thread, thread 4, which contains one business logic. Using the same method, add threads 2, 3, 4 and their business logics to the performance analysis tree in a tree structure, and you get Figure 3 Dendrogram shown.
[0084] Specifically in the aforementioned embodiment, for example, thread 1 is the thread corresponding to the user savings operation, that is, the starting thread, and the three business logics contained in thread 1 are user query business logic, operation record insertion business logic, and balance modification business logic. Thread 2 can be a sub-thread corresponding to balance query, and the two business logics contained in thread 2 are balance query business logic and information feedback business logic. Thread 3 can be a sub-thread corresponding to user contact information query, and the business logic contained in thread 3 is user contact information query business logic. Thread 4 can be a sub-thread corresponding to user contact information modification.
[0085] The execution of the entire thread 1 is finally aggregated into a performance analysis tree. Therefore, you only need to obtain the structure of the performance analysis tree and the data of each node to clearly and completely understand the overall execution of thread 1 and the execution of each part of thread 1. Since the performance analysis tree records the parent-child relationship between each node, it can effectively solve the link query problem when performing time-consuming analysis. If the thread execution time is too long, the abnormal time-consuming part can be located in a timely and accurate manner based on all the execution links of the performance analysis tree.
[0086] S213: Send the performance analysis tree to the monitoring platform, so that the monitoring platform reads the structure of the performance analysis tree and the data corresponding to each node, and generates a performance analysis report.
[0087] In this step, the monitoring platform is used to monitor the execution of the thread in real time. In the specific application process, the performance analysis tree is sent to the monitoring platform, which can read the structure of the entire performance analysis tree and the data of each node, and monitor the time-consuming problems of each link in the thread in real time. If the thread execution time is long and the processing is slow, an alarm message can be issued in time to inform the tester or operation and maintenance personnel of the specific location that affects the thread execution efficiency, and then optimize the code at that location to improve the thread execution efficiency.
[0088] For example, if the tester receives an alarm message for a user's savings operation, he can accurately and intuitively know which links the user's savings operation includes, the specific time consumption of these links, and the relationship between the links based on the performance analysis tree. If it is found that the savings operation record writing link is executed too slowly, the code of this link can be modified accordingly. For other links executed after this link, such as balance modification, it can be analyzed whether they must be executed in sequence after this link. If they can be executed in parallel or after other links, the structural relationship between the links can be modified accordingly. For example, the balance modification link and the savings operation record writing link can be set to execute in parallel by modifying the code, and the transfer link can also be set to execute in parallel with the savings operation record writing link.
[0089] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0090] It can be seen that compared with the traditional performance analysis method, this solution can track time-consuming code blocks according to actual needs during program execution, and implement on-demand tracking. For unimportant or less time-consuming code blocks, no performance analysis is performed. This method of only monitoring and optimizing performance for specific parts effectively improves the performance analysis efficiency of the entire thread and the system optimization efficiency. In addition, since this solution generates a tree-structured performance analysis tree for each link, the execution link of the program is clearer, so the time consumption of each link can be monitored intuitively and accurately through the performance analysis tree. And when it takes too long, the structure of the performance analysis tree can be adjusted by modifying the code, and the execution order of each link can be changed, so as to further improve the execution performance of the entire thread from a global perspective.
[0091] In one embodiment, a performance analysis device is provided, which corresponds one-to-one to the performance analysis method in the above embodiment. Figure 4 As shown, the performance analysis device includes: an initialization module, an object construction module and an analysis module. The detailed description of each functional module is as follows:
[0092] An initialization module is used to obtain a starting thread and use the starting thread as a thread to be analyzed during program execution;
[0093] An object construction module is used to establish a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count the first start time and the first end time of the start thread; and, determine at least one business logic in the thread to be analyzed, and perform tracking for each business logic respectively, and generate a performance analysis object corresponding to each business logic, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic; and, add the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic;
[0094] The analysis module is used to generate a performance analysis result according to the first start time, the first end time, the second start time and the second end time in the thread statistics object.
[0095] In one embodiment, the thread statistics object includes a linear table;
[0096] Object building blocks are used to:
[0097] According to the execution order of the business logic, the performance analysis object corresponding to the business logic is added to the linear list of the thread statistics object of the thread to be analyzed corresponding to the business logic.
[0098] In one embodiment, the object construction module is further used to:
[0099] Take the starting thread as the parent thread, determine whether there is a child thread in the parent thread, and if so, take the child thread as the thread to be analyzed;
[0100] The child thread is used as a new parent thread, and the process returns to the step of determining whether a child thread exists in a parent thread, until all parent threads do not contain a child thread.
[0101] In one embodiment, the object construction module is further used to:
[0102] Among the multiple threads to be analyzed, the child threads in each parent thread are respectively determined, and the thread statistics objects of the child threads are added to the thread statistics objects of the parent threads corresponding to the child threads.
[0103] In one embodiment, the apparatus further comprises a tree building module for:
[0104] Taking the threads to be analyzed and the execution logic as nodes, a performance analysis tree with a tree structure is established according to the parent-child relationship between the multiple threads to be analyzed and the execution order between the multiple business logics, wherein the starting thread is the root node;
[0105] The performance analysis tree is sent to the monitoring platform so that the monitoring platform reads the structure of the performance analysis tree and the data corresponding to each node and generates a performance analysis report.
[0106] In one embodiment, the object construction module is further used to:
[0107] Split the business logic into multiple code blocks and determine the time consumption of each code block;
[0108] If the time consumption is greater than the preset threshold, a point is placed at the location corresponding to the code block.
[0109] In one embodiment, the thread statistics object includes the thread name, thread start time, thread end time, and thread parent-child relationship.
[0110] In one embodiment, an electronic device is provided. The electronic device may be a mobile device such as a mobile phone, a tablet, a vehicle-mounted mobile terminal, or other device with program execution capability. The internal structure diagram of the electronic device may be as shown below: Figure 5As shown. The electronic device includes a processor, a memory and a network module. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, instructions or codes. The internal memory provides an environment for the operation of the operating system and instructions or codes in the non-volatile storage medium. When the instructions or codes are executed by the processor, a function or step of the above-mentioned performance analysis method is implemented. The network module of the electronic device may include a network interface and / or a wireless network module, and the electronic device may communicate with other devices or service platforms through the network module. In addition, the electronic device may also include a display screen and an input device, etc.
[0111] In one embodiment, an electronic device is provided, including a memory, a processor, and instructions or codes stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the instructions or codes:
[0112] During the program running process, the starting thread is obtained and used as the thread to be analyzed;
[0113] Establishing a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count the first start time and the first end time of the start thread;
[0114] Determine at least one business logic in the thread to be analyzed, and perform tracking for each business logic respectively, and generate a performance analysis object corresponding to each business logic, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic;
[0115] Add the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic;
[0116] A performance analysis result is generated according to a first start time, a first end time, a second start time, and a second end time in the thread statistics object.
[0117] In one embodiment, a storage medium is provided, on which instructions or codes are stored, and when the instructions or codes are executed by a processor, the following steps are implemented:
[0118] During the program running process, the starting thread is obtained and used as the thread to be analyzed;
[0119] Establishing a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count the first start time and the first end time of the start thread;
[0120] Determine at least one business logic in the thread to be analyzed, and perform tracking for each business logic respectively, and generate a performance analysis object corresponding to each business logic, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic;
[0121] Add the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic;
[0122] A performance analysis result is generated according to a first start time, a first end time, a second start time, and a second end time in the thread statistics object.
[0123] It should be noted that the functions or steps that can be implemented by the above-mentioned storage medium or electronic device can refer to the relevant description in the aforementioned method embodiment. In order to avoid repetition, they will not be described one by one here.
[0124] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through instructions or codes, and the instructions or codes can be stored in a non-volatile readable storage medium. When the instructions or codes are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0125] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0126] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the units or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the units in the system in the implementation scenario can be distributed in the system of the implementation scenario according to the implementation scenario description, or can be changed accordingly and located in one or more systems different from the present implementation scenario. The units of the above-mentioned implementation scenario can be combined into one unit, or can be further split into multiple sub-units.
[0127] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A performance analysis method, characterized in that: The method comprises: During the program running process, a starting thread is obtained and the starting thread is used as a thread to be analyzed; Establishing a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count a first start time and a first end time of the start thread; Determine at least one business logic in the thread to be analyzed, and perform tracking for each of the business logics, and generate a performance analysis object corresponding to each of the business logics, wherein the performance analysis object includes a second start time and a second end time corresponding to the business logic; Adding the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic; A performance analysis result is generated according to the first start time, the first end time, the second start time and the second end time in the thread statistics object.
2. The method according to claim 1, characterized in that The thread statistics object includes a linear table; Correspondingly, the adding the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic includes: According to the execution order of the business logic, the performance analysis object corresponding to the business logic is added to the linear list of the thread statistics object of the thread to be analyzed corresponding to the business logic.
3. The method according to claim 2, characterized in that Before establishing the thread statistics object corresponding to the thread to be analyzed, the method further includes: Taking the starting thread as the parent thread, determining whether there is a child thread in the parent thread, and if so, taking the child thread as the thread to be analyzed; The child thread is used as a new parent thread, and the process returns to the step of determining whether a child thread exists in the parent thread, until all parent threads do not contain a child thread.
4. The method according to claim 3, characterized in that After adding the performance analysis object to the thread statistics object, the method further includes: Among the multiple threads to be analyzed, the child threads in each parent thread are determined respectively, and the thread statistics objects of the child threads are added to the thread statistics objects of the parent thread corresponding to the child threads.
5. The method according to claim 4, characterized in that After generating the performance analysis result, the method further includes: Taking the threads to be analyzed and the execution logic as nodes, a performance analysis tree with a tree structure is established according to the parent-child relationship between the multiple threads to be analyzed and the execution order between the multiple business logics, wherein the starting thread is the root node; The performance analysis tree is sent to a monitoring platform, so that the monitoring platform reads the structure of the performance analysis tree and the data corresponding to each node, and generates a performance analysis report.
6. The method according to claim 1, characterized in that The tracking of each business logic includes: Splitting the business logic into multiple code blocks and determining the time consumption of the code blocks; If the time consumption is greater than a preset threshold, a point is buried at the position corresponding to the code block.
7. The method according to claim 1, characterized in that The thread statistics object includes thread name, thread start time, thread end time, and thread parent-child relationship.
8. A performance analysis device, characterized in that: The device comprises: An initialization module, used to obtain a starting thread and use the starting thread as a thread to be analyzed during program execution; An object construction module is used to establish a thread statistics object corresponding to the thread to be analyzed, wherein the thread statistics object is used to count the first starting time and the first ending time of the starting thread; and, determine at least one business logic in the thread to be analyzed, and perform tracking for each of the business logics respectively, and generate a performance analysis object corresponding to each of the business logics, wherein the performance analysis object includes a second starting time and a second ending time corresponding to the business logic; and, add the performance analysis object corresponding to the business logic to the thread statistics object of the thread to be analyzed corresponding to the business logic; The analysis module is used to generate a performance analysis result according to the first start time, the first end time, the second start time and the second end time in the thread statistics object.
9. A storage medium having a program or instruction stored thereon, characterized in that: When the program or instruction is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.
