CN-121979568-A - Code usage rate calculation method and device, electronic equipment and computer medium
Abstract
The disclosure provides a code usage rate calculation method and device, electronic equipment and a computer medium, relates to the technical field of data processing, and particularly relates to the technical fields of application program development, data compression and the like. The method comprises the steps of obtaining a link mapping file generated by compiling an application program, analyzing symbol information of defined classes in the application program from the link mapping file, constructing a first class set, recording class information corresponding to triggered initialization events by intercepting an initialization method of each class to be monitored in a runtime environment of the application program, constructing a second class set, and determining code utilization rate information of the application program according to comparison results of the first class set and the second class set.
Inventors
- SHI MINGLI
Assignees
- 北京度友信息技术有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251218
Claims (14)
- 1. A code usage computing method, comprising: obtaining a link mapping file generated by compiling the application program, analyzing symbol information of a class defined in the application program from the link mapping file, and constructing a first class set; By intercepting an initializing method of each class to be monitored in the runtime environment of the application program, recording class information corresponding to the triggered initializing event, and constructing a second class set; And determining the code utilization rate information of the application program according to the comparison result of the first class set and the second class set.
- 2. The method of claim 1, wherein the step of recording class information corresponding to the triggered initialization event by intercepting the initialization method of each class to be monitored in the runtime environment of the application program, and constructing the second class set includes: traversing the registered classes in the runtime environment in response to the application launch; and for each traversed class, replacing the original implementation of the initializing method of the class with a custom implementation, wherein when the custom implementation is called, corresponding class information is recorded to the second class set, and the original implementation is called.
- 3. The method of claim 2, wherein the recording corresponding class information to the second class set when the custom implementation is invoked comprises: Temporarily storing the corresponding class information into a cache queue; and responding to the triggering of a preset persistence storage condition, and adding the class information temporarily stored in the cache queue to the second class set in batches.
- 4. The method of claim 3, wherein the persistent storage condition comprises at least one of: the application program exits or enters a background; The quantity of the class information temporarily stored in the cache queue reaches a threshold value; the time interval from the last batch addition operation reaches a threshold.
- 5. The method of claim 2, wherein the runtime environment is an Objective-C runtime, and the initialization method is an Objective-C class +initialization method; The replacing the original implementation of the class initialization method with the custom implementation comprises the following steps: the original implementation of the initialization method is replaced with the custom implementation using the method exchange mechanism of the Objective-C runtime.
- 6. The method of claim 1, wherein the parsing the symbolic information of the class defined in the application program from the link map file to construct a first class set includes: Identifying a symbol in the link map file identified by a predetermined prefix, the predetermined prefix being used to indicate a class defined using a predetermined programming language; and determining a corresponding class according to the identified symbol, and adding the class name of the class to the first class set.
- 7. The method of claim 6, wherein the determining a corresponding class from the identified symbol, adding a class name of the class to the first set of classes, comprises: Determining a corresponding class and module information to which the class belongs according to the symbol, and adding the class name of the class and the corresponding module information as symbol information of the class to the first class set; And determining the code usage information of the application program according to the comparison result of the first class set and the second class set, including: And respectively counting the ratio of the number of classes belonging to the second class set in each module to the number of classes belonging to the first class set in each module according to the module information to obtain the code utilization rate of module dimension.
- 8. The method of claim 1, wherein the recording class information corresponding to the triggered initialization event comprises: And recording at least one of a corresponding class name, a time stamp of the initialization time and context information, wherein the context information comprises the runtime environment information of the application program.
- 9. The method of claim 1, wherein the determining code usage information of the application program according to the comparison result of the first class set and the second class set comprises: And calculating the ratio of the number of the classes in the second class set to the number of the classes in the first class set as the overall code utilization rate of the application program.
- 10. The method of claim 1, wherein the method is performed in an online production environment of the application.
- 11. A code usage computing device, comprising: The static analysis module is configured to acquire a link mapping file generated by compiling the application program, analyze sign information of a class defined in the application program from the link mapping file and construct a first class set; the dynamic monitoring module is configured to record class information corresponding to the triggered initialization event by intercepting an initialization method of each class to be monitored in the runtime environment of the application program, and construct a second class set; and the calculation analysis module is configured to determine the code utilization rate information of the application program according to the comparison result of the first class set and the second class set.
- 12. An electronic device, comprising: at least one processor, and A memory communicatively coupled to the at least one processor, wherein, The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-10.
- 13. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of any one of claims 1-10.
- 14. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any of claims 1-10.
Description
Code usage rate calculation method and device, electronic equipment and computer medium Technical Field The present disclosure relates to the field of data processing technologies, and in particular, to the technical fields of application development, data compression, and the like. Specifically, the present disclosure relates to a code usage rate calculation method and apparatus, an electronic device, and a computer-readable storage medium. Background With rapid iteration and function expansion of mobile internet applications, especially the continuous evolution of large-scale application programs such as network disks, the installation package volume of the application programs has a growing trend. In this process, there are often large numbers of business codes and class libraries that have never been invoked or loaded in an on-line real running environment in the application due to historical code accumulation, functional module redundancy, or demand changes. The codes not only unnecessarily increase the volume of the application installation package and influence the downloading and installation experience of users, but also increase the memory occupation when the application is started, and the complexity of the maintenance of the code library is improved. Disclosure of Invention The present disclosure provides a code usage rate calculation method and apparatus for calculating a code usage rate of an application program, an electronic device, and a computer-readable storage medium. According to a first aspect of the present disclosure, there is provided a code usage calculating method, the method comprising: obtaining a link mapping file generated by compiling the application program, analyzing symbol information of a class defined in the application program from the link mapping file, and constructing a first class set; By intercepting an initializing method of each class to be monitored in the runtime environment of the application program, recording class information corresponding to the triggered initializing event, and constructing a second class set; And determining the code utilization rate information of the application program according to the comparison result of the first class set and the second class set. According to a second aspect of the present disclosure, there is provided a code usage calculating apparatus, the apparatus comprising: The static analysis module is configured to acquire a link mapping file generated by compiling the application program, analyze sign information of a class defined in the application program from the link mapping file and construct a first class set; the dynamic monitoring module is configured to record class information corresponding to the triggered initialization event by intercepting an initialization method of each class to be monitored in the runtime environment of the application program, and construct a second class set; and the calculation analysis module is configured to determine the code utilization rate information of the application program according to the comparison result of the first class set and the second class set. According to a third aspect of the present disclosure, there is provided an electronic device comprising: at least one processor, and A memory communicatively coupled to the at least one processor, wherein, The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the code usage calculation method. According to a fourth aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the above-described code usage calculating method. According to a fifth aspect of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the above-described code usage calculation method. It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the disclosure, nor is it intended to be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following specification. Drawings The drawings are for a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein: fig. 1 is a flowchart of a code usage rate calculation method according to an embodiment of the present disclosure; FIG. 2 is a flow chart illustrating partial steps of another code usage calculation method provided by an embodiment of the present disclosure; FIG. 3 is a flow chart illustrating partial steps of another code usage calculation method provided by an embodiment of the present disclosure; FIG. 4 is a block diagram of a system for performing the code usage calculation method provided by the embodiments of the present disclosure in one parti