Function execution time information output method and device, electronic device and storage medium
By obtaining and outputting the execution time information of the target thread, the problem of not being able to judge the time-consuming of functions in high concurrency scenarios is solved, and the effective recording and output of the execution time of functions is realized, which improves the efficiency of system performance analysis.
Patent Information
- Application Number
- CN202210141603.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-16
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2042-02-16
AI Technical Summary
In high concurrency scenarios, the existing technology cannot effectively determine the running time of the function, resulting in the inability to determine which function has the problem of taking too long.
By obtaining the target execution time information of the target thread completing the execution of the target function, and writing it to the target memory space corresponding to the target thread in the target memory, the target execution time information in the target memory space is finally output.
It realizes the execution time of each function in high concurrency scenarios, helps analyze whether the function takes too long and improves the efficiency of system performance analysis.
Smart Images

Figure CN114595128B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method and device for outputting function execution duration information, an electronic device, and a storage medium. Background Art
[0002] At present, with the widespread use of various systems, as well as the increasing complexity and intensity of use of various systems, high concurrency scenarios are prone to occur, for example, in existing database systems or production environments.
[0003] In the related art, in a high-concurrency scenario, if there is a performance problem, it is necessary to determine which function is causing the problem by taking too long to run. However, the related art does not provide a method for determining the time taken for a function to run.
[0004] Therefore, there is a problem in the related art that it is impossible to determine the running time of a function. Summary of the invention
[0005] The present application provides a method and device for outputting function execution duration information, an electronic device and a storage medium, so as to at least solve the problem in the related art that the function execution duration cannot be determined.
[0006] According to one aspect of an embodiment of the present application, a method for outputting function execution duration information is provided, including:
[0007] Obtain target execution time information of the target execution time of the target thread to complete the execution of the target function;
[0008] Writing the target execution duration information into a target memory subspace corresponding to the target thread in the target memory through the target thread;
[0009] Output the target execution duration information in the target memory partition.
[0010] Optionally, as in the aforementioned method, the step of obtaining target execution time information of a target execution time for a target thread to complete execution of a target function includes:
[0011] Recording the first system time when the target function is started to be executed;
[0012] When the target function ends execution, recording the second system time;
[0013] The target execution duration is obtained based on the difference between the second system time and the first system time, and the target execution duration information corresponding to the target execution duration is obtained.
[0014] Optionally, as in the aforementioned method, before writing the target execution duration information into the target memory partition corresponding to the target thread in the target memory through the target thread, the method further includes:
[0015] Apply for the target memory of the target space, and the starting address of the target memory is 4K aligned;
[0016] According to a preset target number, the target space is divided to obtain the target number of memory sub-spaces, wherein the starting address corresponding to each of the memory sub-spaces is aligned with 4K, and the memory size of each of the memory sub-spaces is an integer multiple of 4K.
[0017] Optionally, as in the aforementioned method, writing the target execution duration information into a target memory subspace corresponding to the target thread in the target memory through the target thread includes:
[0018] Determine the target memory subspace corresponding to the target thread among all memory subspaces of the target memory;
[0019] Obtaining the target function name of the target function, and establishing a corresponding relationship between the target function name and the target execution duration information;
[0020] Determine the current starting address of the unused memory in the target memory partition;
[0021] According to the current starting address, the corresponding relationship is written into the target memory partition through the target thread.
[0022] Optionally, as in the aforementioned method, determining the target memory subspace corresponding to the target thread in all memory subspaces of the target memory includes:
[0023] Determine the thread identifier of the target thread;
[0024] After deleting the lower 8 bits of the thread identifier, a processed thread identifier is obtained;
[0025] According to the remainder obtained by calculating the modulus of the processed thread identifier and the target number, the target memory sub-space whose arrangement order is consistent with the remainder is determined among all the memory sub-spaces, wherein the target number is the number of the memory sub-spaces, and the arrangement order of each of the memory sub-spaces is used to indicate the order of storage positions corresponding to the memory sub-spaces relative to storage positions corresponding to other memory sub-spaces in the target memory.
[0026] Optionally, as in the aforementioned method, the outputting the target execution duration information in the target memory sub-space includes:
[0027] According to the arrangement order of each memory sub-space in the target memory, traverse each memory sub-space in turn, wherein the arrangement order of each memory sub-space is used to indicate the order relationship between the storage position corresponding to the memory sub-space and the storage position corresponding to other memory sub-spaces in the target memory;
[0028] When traversing to the target memory sub-space, all data in the target memory sub-space are output to the target log, wherein the data includes the target execution duration information.
[0029] Optionally, as in the aforementioned method, before obtaining the target execution time information of the target execution time of the target thread to complete the execution of the target function, the method further includes:
[0030] Get timing command;
[0031] In response to the timing command, executing a jump operation for jumping to the target execution duration information of obtaining the target execution duration of the target thread to complete the execution of the target function;
[0032] After outputting the target execution duration information in the target memory partition space, the method further includes:
[0033] Get the stop timing instruction;
[0034] In response to the stop timing instruction, stop counting the execution time of any function;
[0035] After a preset time interval, the target memory is released.
[0036] According to another aspect of the embodiment of the present application, there is also provided a device for outputting function execution duration information, including:
[0037] An acquisition module is used to obtain target execution time information of a target execution time for a target thread to complete executing a target function;
[0038] A writing module, used for writing the target execution duration information into a target memory subspace corresponding to the target thread in the target memory through the target thread;
[0039] The output module is used to output the target execution time information in the target memory sub-space.
[0040] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.
[0041] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.
[0042] In an embodiment of the present application, a method of writing and outputting execution duration information through multiple memory sub-spaces is adopted, by obtaining the target execution duration information of the target execution duration of the target function completed by the target thread; writing the target execution duration information into the target memory sub-space corresponding to the target thread through the target thread; and outputting the target execution duration information in the target memory sub-space. Thus, the purpose of writing the target execution duration information in the target memory sub-space and outputting the target execution duration information in the target memory sub-space can be achieved, and the purpose of outputting the target execution duration information of the target function can be achieved, achieving the technical effect of facilitating relevant personnel to intuitively obtain the execution duration of each function, thereby solving the problem existing in the related technology that when there is a problem with system performance, it is impossible to determine which function is taking too long. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] 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.
[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0045] Figure 1 It is a flowchart of an optional method for outputting function execution duration information according to an embodiment of the present application;
[0046] Figure 2 is a flowchart of another optional method for outputting function execution duration information according to an embodiment of the present application;
[0047] Figure 3It is a structural block diagram of an optional function execution duration information output device according to an embodiment of the present application;
[0048] Figure 4 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to enable those skilled in the art to better understand the solution of the present application, 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 only 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 creative work should fall within the scope of protection of the present application.
[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0051] According to one aspect of an embodiment of the present application, a method for outputting function execution duration information is provided. Optionally, in this embodiment, the above-mentioned method for outputting function execution duration information can be applied to a hardware environment consisting of a terminal and a server. The server is connected to the terminal via a network, and can be used to provide services (such as data processing services, application services, etc.) to the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server.
[0052] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.
[0053] The function execution time information output method of the embodiment of the present application can be executed by a server, or by a terminal, or by both a server and a terminal. The terminal can also execute the function execution time information output method of the embodiment of the present application by a client installed thereon.
[0054] Taking the method for outputting function execution time information in this embodiment executed by a server as an example, Figure 1 A method for outputting function execution time information provided in an embodiment of the present application includes the following steps:
[0055] Step S101, obtaining target execution time information of a target thread completing a target function execution.
[0056] The execution time information output method in this embodiment can be applied to scenarios where it is necessary to output the time taken to execute each function, such as scenarios where database system performance problems occur, scenarios where production environment performance problems occur, etc., or other high-concurrency scenarios. For other types of scenarios, the above-mentioned execution time information output method is also applicable if there is no contradiction.
[0057] After the target thread specifies the target function, the target execution time for the target function to complete execution can be obtained, thereby generating target execution time information.
[0058] Furthermore, each thread is used to execute a function. Therefore, when there are multiple functions, one of the functions can be executed by multiple threads respectively, and the target execution time obtained after each thread executes the corresponding function can be obtained.
[0059] Step S102, writing the target execution duration information into the target memory partition corresponding to the target thread in the target memory through the target thread.
[0060] After obtaining the target execution time information of the target execution time, the target execution time can be written into the target memory subspace corresponding to the target thread. The target memory subspace can be a memory space divided from the target memory for storing data written by the target thread.
[0061] Furthermore, when the target memory is divided into a plurality of memory sub-spaces, each memory sub-space may correspond to a different thread, and therefore, each memory sub-space may store a plurality of execution duration information.
[0062] Step S103, outputting the target execution duration information in the target memory sub-space.
[0063] After the target execution time information is stored in the target memory sub-space in the target memory space, the target execution time in the target memory sub-space may be output to display the target execution time information in a desired display manner.
[0064] Through the method in this embodiment, when there is a problem with system performance, the execution time information of each function can be written into the corresponding memory sub-space, and the execution time information in the memory sub-space can be output, so as to clearly record the execution time of each function, so as to facilitate analysis of whether each function has the problem of taking too long.
[0065] As an optional implementation, as in the above method, the step S101 of obtaining the target execution time information of the target execution time of the target thread to complete the execution of the target function includes the following steps:
[0066] Step S201, recording the first system time when the target function starts to be executed.
[0067] In order to determine the duration of the target function, the start time of starting to execute the target function can be determined, and then the first system time of starting to execute the target function can be recorded.
[0068] The first system time may be the time when the target function starts to be executed.
[0069] Optionally, the execution time of the target function may be triggered to be recorded when the target function is executed.
[0070] Step S202: When the target function finishes executing, the second system time is recorded.
[0071] After the target function is finished executing, in order to determine the duration of the target function, the end time of finishing the execution of the target function can be determined, and then, the second system time of finishing the execution of the target function can be recorded.
[0072] The second system time may be the time when the execution of the target function ends.
[0073] Optionally, when the target function ends execution, the recording of the execution duration of the target function may be stopped to obtain the second system time.
[0074] Step S203, obtaining the target execution duration based on the difference between the second system time and the first system time, and obtaining the target execution duration information corresponding to the target execution duration.
[0075] After the second system time and the first system time are obtained, the target execution duration may be obtained based on the difference between the second system time and the first system time, that is, target execution duration=second system time-first system time.
[0076] After the target execution time is obtained, the target execution time information corresponding to the target execution time can be obtained.
[0077] By using the method in this embodiment, the purpose of determining the execution time of each function and generating corresponding execution time information can be achieved.
[0078] As an optional implementation, as in the above method, before the step S102 writes the target execution duration information into the target memory subspace corresponding to the target thread in the target memory through the target thread, the method further includes the following steps:
[0079] Step S301, applying for a target memory of a target space, and the start address of the target memory is 4K aligned.
[0080] In order to obtain the target memory, the memory may be applied for in advance to obtain the target memory of the target space in the system.
[0081] The target space can be pre-set to correspond to the required target memory, such as 500M, 1G, etc.
[0082] In addition, the starting address of the target memory can be guaranteed to be 4K aligned to improve the efficiency of reading and writing.
[0083] For example, you can use the malloc function to apply for a target memory with a target space size of 500M.
[0084] Step S302, dividing the target space according to a preset target number to obtain a target number of memory sub-spaces, wherein the starting address corresponding to each memory sub-space is aligned with 4K, and the memory size of each memory sub-space is an integer multiple of 4K.
[0085] After obtaining the target memory, the target space can be divided according to the preset target number to obtain memory sub-spaces that are consistent with the target number. Optionally, the target space can be evenly divided according to the target number to obtain the target number of memory sub-spaces. Furthermore, the starting address 4K (4096B) corresponding to each memory sub-space is aligned, and the memory size of each memory sub-space is an integer multiple of 4K, thereby achieving the purpose of improving the efficiency of reading and writing.
[0086] When the size of each memory partition is the same, the starting address of the address of the nth memory partition is X+n×M, where X is the starting address of the 4K-aligned large memory and M is the size of each memory partition, which is an integer multiple of 4K.
[0087] Optionally, when the amount of data read per unit time from the target memory is less than the amount written per unit time, and the proportion of the remaining space of the target memory in all the space of the target memory is less than or equal to a preset threshold, you can apply for the designated memory of the designated space, divide it into a designated number of designated memory sub-spaces, and then give priority to writing the duration information generated after each thread executes the function into the designated memory sub-space. At the same time, without increasing the memory, when each memory sub-space is full, the newly generated duration information can be written into the memory sub-space in a manner that overwrites each historical duration information according to the time written into the memory sub-space from far to near.
[0088] Through the method in this embodiment, by dividing the target memory into multiple memory sub-spaces, the duration information can be written synchronously in different memory sub-spaces to achieve the purpose of improving efficiency.
[0089] like Figure 2 As shown, as an optional implementation, as in the aforementioned method, the step S102 writes the target execution duration information into the target memory subspace corresponding to the target thread in the target memory through the target thread, including the following steps:
[0090] Step S401: determine a target memory subspace corresponding to a target thread from among all memory subspaces of the target memory.
[0091] As known from the above-mentioned embodiments, there are multiple memory sub-spaces in the target memory. Therefore, in this case, it is necessary to determine the target memory sub-space corresponding to the target thread from the multiple memory sub-spaces.
[0092] Step S402, obtaining the target function name of the target function, and establishing a corresponding relationship between the target function name and the target execution duration information.
[0093] Before writing the target execution time information into the target memory partition, it is also necessary to determine the format of the written data. In order to facilitate the output so that the function corresponding to each execution time information can be determined, it is also necessary to obtain the target function name of the target function and establish a corresponding relationship between the target function name and the target execution time information.
[0094] Furthermore, the corresponding relationship may also include the thread id of the target thread; and the record format of the corresponding relationship may be: thread id+space+function name abbreviation (ie, target function name)+space+execution time (in microseconds).
[0095] Step S403, determining the current starting address of the unused memory in the target memory partition.
[0096] After the target memory subspace is determined, the corresponding relationship needs to be written into the target memory subspace. In order to complete the writing operation, the current starting address of the unused memory in the target memory subspace needs to be determined.
[0097] Optionally, the memory recording method is len+=sprintf(X+n×M+len,"%s",str); that is, the current starting address of the unused memory in each memory partition is recorded additionally.
[0098] Step S404: write the corresponding relationship into the target memory partition space through the target thread according to the current starting address.
[0099] After the current starting address and the corresponding relationship are determined, the corresponding relationship can be written into the target memory partition space by the target thread using the current starting address as the first address to be written.
[0100] Through the method in this embodiment, the purpose of determining the corresponding function for each duration information in the memory can be achieved, and it can be ensured that each corresponding relationship is written into the corresponding memory space in sequence, thereby effectively avoiding waste of memory.
[0101] As an optional implementation, as in the above method, the step S401 of determining the target memory subspace corresponding to the target thread in all the memory subspaces of the target memory includes the following steps:
[0102] Step S501, determining the thread identifier of the target thread.
[0103] After the target thread is determined, a unique thread identifier for indicating the target thread may be determined.
[0104] For example, the current thread ID, such as 0x7f5728423700, can be recorded through pthead_self().
[0105] Step S502, after deleting the lower 8 bits of the thread identifier, a processed thread identifier is obtained.
[0106] After obtaining the thread identifier, the thread identifier is generally in hexadecimal, and the lower 8 bits are 0, so the lower 8 bits are the last two bits of the thread identifier, and are 0. Further, deleting the lower 8 bits of the thread identifier is to delete the last two bits that are 0 to obtain the processed thread identifier.
[0107] Based on the example shown in the above steps, after the lower 8 bits of "0x7f5728423700" are shifted 8 bits to the right and data is processed (the mantissa is not 0), the processed thread identifier obtained is "0x7f57284237".
[0108] Step S503, based on the remainder obtained by calculating the modulus of the processed thread identifier and the target number, determine the target memory sub-space in all memory sub-spaces whose arrangement order is consistent with the remainder, wherein the target number is the number of memory sub-spaces, and the arrangement order of each memory sub-space is used to indicate the order of storage positions corresponding to the memory sub-space relative to storage positions corresponding to other memory sub-spaces in the target memory.
[0109] After obtaining the processed thread identifier, in order to assign the thread identifier to each memory sub-space and determine the target memory sub-space corresponding to the target thread, the processed thread identifier can be divided by the target number and the corresponding remainder can be obtained. Then, based on the remainder, the target memory sub-space with the same arrangement order as the remainder can be determined among all the memory sub-spaces.
[0110] Optionally, the arrangement order may be an order obtained by arranging the addresses of the memory sub-spaces in the target memory in a sequential order.
[0111] For example, when the target memory is divided into N parts, such as 129 parts, the thread identifier after processing is n, which is obtained by taking the modulo 129, and corresponds to the nth memory sub-space in the target memory. For example, when n is 0, it is allocated to the memory sub-space that is the first in the arrangement order among all the memory sub-spaces. When n is 1, it is allocated to the memory sub-space that is the second in the arrangement order among all the memory sub-spaces.
[0112] Through the method in this embodiment, a correspondence can be evenly established between each thread and the memory space, so that the execution time information of each function can be evenly written into each memory space, thereby avoiding inconsistent cache loads in each memory space.
[0113] As an optional implementation, as in the above method, the step S103 of outputting the target execution time information in the target memory sub-space includes the following steps:
[0114] Step S601, traverse each memory sub-space in turn according to the arrangement order of each memory sub-space in the target memory, wherein the arrangement order of each memory sub-space is used to indicate the order relationship between the storage position corresponding to the memory sub-space and the storage position corresponding to other memory sub-spaces in the target memory.
[0115] After the arrangement order corresponding to each memory sub-space is determined, each memory sub-space may be traversed in sequence according to the arrangement order to read the data in each memory sub-space in sequence.
[0116] For example, when there are memory sub-spaces arranged in the order of 0, 1, 2, 3, ...128 (that is, the target space is divided into 129 memory sub-spaces), each memory sub-space can be traversed in the order of 0, 1, 2, 3, ...128 to read the data in each memory sub-space.
[0117] Step S602, when traversing to the target memory sub-space, output all data in the target memory sub-space to the target log, wherein the data includes target execution duration information.
[0118] After traversing to the target memory sub-space, all data currently included in the target memory sub-space can be output to the target memory. Moreover, since all data include the target execution time information, the purpose of outputting the target execution time information can be achieved. For any of all memory sub-spaces, when traversing to the memory sub-space, the data therein can be output according to the method in this embodiment.
[0119] Furthermore, when traversing to the target memory partition, the historical position where the data read last time is stored can be determined first, and then in the current output process, data can be read from the next position after the historical position, and the read data can be output to the target log.
[0120] For example, you can execute the print command at a fixed period to output the data in the target memory to the log. By looping through each memory partition, the log information recorded in the memory is output according to the length of each memory partition.
[0121] Through the method in this embodiment, the purpose of outputting the target execution time information in the memory sub-space can be achieved by traversing each memory sub-space in turn, and then all execution time information can be output through this method, so that relevant personnel can intuitively confirm the execution time of each function.
[0122] As an optional implementation, as in the above method, before the step S101 obtains the target execution time information of the target execution time of the target thread to complete the execution of the target function, the method further includes the following steps:
[0123] Step S701, obtaining a timing command;
[0124] Step S702 , in response to the timing command, executing a jump operation for jumping to obtain target execution duration information of a target execution duration for a target thread to complete execution of a target function.
[0125] Optionally, the switch for recording function execution time can be turned on through a timing command, for example, a newly created command such as "set xx=on" to start obtaining the execution time of the target function. In addition, other commands can also be used, which are not detailed here.
[0126] After acquiring the timing command, a response may be made to the timing command, and a jump operation may be performed to jump to step S101 to acquire target execution duration information of the target execution duration for the target thread to complete execution of the target function, so as to execute step S101.
[0127] After the target execution time information in the target memory sub-space is output in step S103, the method further includes the following steps:
[0128] Step S801, obtaining a stop timing instruction;
[0129] Step S802, in response to the stop timing instruction, stop counting the execution time of any function;
[0130] Step S803: after a preset time interval, the target memory is released.
[0131] Optionally, the switch for recording function execution time can be turned off by stopping the timing instruction. For example, a newly created command, such as "set xx=off", can be used to stop obtaining the execution time of the target function and turn off the statistics of the function's execution time. In addition, other commands can also be used, which are not listed here one by one.
[0132] After acquiring the timing command, the timing command may be responded to and the counting of the execution time of any function may be stopped. Optionally, the stop timing instruction may be automatically generated after determining that there is a function that takes too long.
[0133] After stopping counting the execution time of the function, the applied target memory can be released through the free function. During the release process, the execution time of the function will no longer be recorded after the preset time interval for stopping the statistics, and the background will release it asynchronously. For example, the target memory can be released after about 10 minutes to prevent the target memory from being in use during the memory release process, causing errors.
[0134] Through the method in this embodiment, a method is provided that can turn on or off function execution time statistics, and after turning off function execution time statistics, the target memory can be released to achieve the purpose of improving memory utilization and improving system performance.
[0135] As shown below, an application example of applying any of the above embodiments is provided:
[0136] 1. Open the switch for recording function execution time through the command:
[0137] A newly created command, such as "set xx=on", triggers a subsequent step of obtaining target execution time information of a target thread completing execution of a target function;
[0138] 2. Apply for a memory space:
[0139] Apply for a target memory such as 500M memory through the malloc function, and the starting memory of the target memory is aligned with 4K;
[0140] 3. Divide the target memory into N spaces, and each thread writes one of them:
[0141] Divide into N memory spaces, each of which is an integer multiple of 4k (4096B), ensuring that the starting address is aligned with 4K;
[0142] 4. During the execution of the function, record the current system time before the execution starts and when the function ends, and calculate the execution time of the function.
[0143] The process of recording execution time is as follows:
[0144] <1> Use pthead_self() to record the current thread ID, such as 0x7f5728423700, and then move the address right by 8 bits to 0x7f57284237 (the lower 8 bits of the address information are all 0. After removing them, the uniformity of the division can be improved when the remainder is calculated);
[0145] <2> The target memory is divided into N parts, such as 129 memory partitions. The remainder n obtained by multiplying the thread identifier by 129 after processing corresponds to the nth memory partition of the target memory.
[0146] The starting address of the nth address is X+n×M, where X is the starting address of the 4K-aligned target memory and M is the size of each memory partition, which is an integer multiple of 4K.
[0147] The method of recording memory is len+=sprintf(X+n×M+len,"%s",str); that is, appending records to the starting address of each memory;
[0148] The format of memory record is "thread id + space + function name abbreviation + space + execution time (in microseconds)";
[0149] 5. Scheduled execution of commands, asynchronous output of function execution time:
[0150] Execute the print command regularly to output all the data in the target memory to the log. By looping through each memory partition, according to the length of each memory partition, the log information recorded in the memory partition is output in sequence;
[0151] 6. Turn off function execution time statistics:
[0152] Through a newly created command, such as "set xx=off".
[0153] 7. Release the requested memory space:
[0154] The requested target memory is released through the free function. During the release process, after the execution time of the function is no longer recorded in the above step 6, the background can perform asynchronous release, which will be released after about 10 minutes (i.e., the preset time interval) to prevent the target memory from being used during the memory release process.
[0155] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0156] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0157] According to another aspect of an embodiment of the present application, a function execution duration information output device for implementing the above-mentioned function execution duration information output method is also provided. Figure 3 is a structural block diagram of an optional function execution duration information output device according to an embodiment of the present application, such as Figure 3 As shown, the device may include:
[0158] An acquisition module 1 is used to acquire target execution time information of a target execution time of a target thread to complete execution of a target function;
[0159] Writing module 2, used for writing target execution duration information into a target memory partition corresponding to the target thread in the target memory through the target thread;
[0160] The output module 3 is used to output the target execution time information in the target memory sub-space.
[0161] It should be noted that the acquisition module 1 in this embodiment can be used to execute the above step S101, the writing module 2 in this embodiment can be used to execute the above step S102, and the output module 3 in this embodiment can be used to execute the above step S103.
[0162] 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, wherein the hardware environment includes a network environment.
[0163] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned function execution duration information output method is also provided. The electronic device may be a server, a terminal, or a combination thereof.
[0164] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 4 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .
[0165] Memory 1503, used for storing computer programs;
[0166] The processor 1501 is used to implement the steps of the above method embodiment when executing the program stored in the memory 1503.
[0167] The bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0168] The communication interface is used for communication between the above electronic device and other devices.
[0169] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0170] 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.
[0171] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.
[0172] It should be noted that, in this article, relational terms such as "first" and "second" 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", "comprise" 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 "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0173] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for outputting function execution time information, characterized in that: include: Obtain target execution time information of the target execution time of the target thread to complete the execution of the target function; Writing the target execution duration information into the target memory sub-space corresponding to the target thread in the target memory through the target thread, including: determining the thread identifier of the target thread; deleting the lower 8 bits of the thread identifier to obtain a processed thread identifier; determining the target memory sub-space whose arrangement order is consistent with the remainder in all the memory sub-spaces according to the remainder obtained by taking the modulus of the processed thread identifier and the target number, wherein the target number is the number of the memory sub-spaces, and the arrangement order of each of the memory sub-spaces is used to indicate the order relationship between the storage position corresponding to the memory sub-space and the storage position corresponding to other memory sub-spaces in the target memory; obtaining the target function name of the target function, and establishing a corresponding relationship between the target function name and the target execution duration information; determining the current starting address of the unused memory in the target memory sub-space; and writing the corresponding relationship into the target memory sub-space through the target thread according to the current starting address; Output the target execution duration information in the target memory partition.
2. The method according to claim 1, characterized in that The target execution time information of obtaining the target execution time of the target thread to complete the execution of the target function includes: Recording the first system time when the target function is started to be executed; When the target function ends execution, recording the second system time; The target execution duration is obtained based on the difference between the second system time and the first system time, and the target execution duration information corresponding to the target execution duration is obtained.
3. The method according to claim 1, characterized in that Before writing the target execution duration information into the target memory subspace corresponding to the target thread in the target memory through the target thread, the method further includes: Apply for the target memory of the target space, and the starting address of the target memory is 4K aligned; According to a preset target number, the target space is divided to obtain the target number of memory sub-spaces, wherein the starting address corresponding to each of the memory sub-spaces is aligned with 4K, and the memory size of each of the memory sub-spaces is an integer multiple of 4K.
4. The method according to claim 1, characterized in that: The outputting of the target execution duration information in the target memory sub-space includes: According to the arrangement order of each memory sub-space in the target memory, traverse each memory sub-space in turn, wherein the arrangement order of each memory sub-space is used to indicate the order relationship between the storage position corresponding to the memory sub-space and the storage position corresponding to other memory sub-spaces in the target memory; When traversing to the target memory sub-space, all data in the target memory sub-space are output to the target log, wherein the data includes the target execution duration information.
5. The method according to any one of claims 1 to 4, characterized in that Before obtaining target execution time information of a target execution time for a target thread to complete executing a target function, the method further includes: Get timing command; In response to the timing command, executing a jump operation for jumping to the target execution duration information of obtaining the target execution duration of the target thread to complete the execution of the target function; After outputting the target execution duration information in the target memory partition space, the method further includes: Get the stop timing instruction; In response to the stop timing instruction, stop counting the execution time of any function; After a preset time interval, the target memory is released.
6. A device for outputting function execution time information, characterized in that: include: An acquisition module is used to obtain target execution time information of a target execution time for a target thread to complete executing a target function; A writing module, used to write the target execution duration information into the target memory sub-space corresponding to the target thread in the target memory through the target thread, including: determining the thread identifier of the target thread; deleting the lower 8 bits of the thread identifier to obtain a processed thread identifier; determining the target memory sub-space whose arrangement order is consistent with the remainder in all the memory sub-spaces according to the remainder obtained by taking the modulus of the processed thread identifier and the target number, wherein the target number is the number of the memory sub-spaces, and the arrangement order of each of the memory sub-spaces is used to indicate the order relationship between the storage position corresponding to the memory sub-space and the storage position corresponding to other memory sub-spaces in the target memory; obtaining the target function name of the target function, and establishing a corresponding relationship between the target function name and the target execution duration information; determining the current starting address of the unused memory in the target memory sub-space; and writing the corresponding relationship into the target memory sub-space through the target thread according to the current starting address; The output module is used to output the target execution time information in the target memory sub-space.
7. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method steps of any one of claims 1 to 5 by running the computer program stored in the memory.
8. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method steps described in any one of claims 1 to 5 when executed.
Citation Information
Patent Citations
Method for collecting and tracking trace call chain and electronic equipment
CN113448815A