WO2022100485A1 - Plug-in resource management method and apparatus, and electronic device and computer-readable storage medium - Google Patents

Plug-in resource management method and apparatus, and electronic device and computer-readable storage medium Download PDF

Info

Publication number
WO2022100485A1
WO2022100485A1 PCT/CN2021/128229 CN2021128229W WO2022100485A1 WO 2022100485 A1 WO2022100485 A1 WO 2022100485A1 CN 2021128229 W CN2021128229 W CN 2021128229W WO 2022100485 A1 WO2022100485 A1 WO 2022100485A1
Authority
WO
WIPO (PCT)
Prior art keywords
plug
resource
bytecode
consumed
file
Prior art date
Application number
PCT/CN2021/128229
Other languages
French (fr)
Chinese (zh)
Inventor
卢小张
刘俊峰
王新余
Original Assignee
南京中兴新软件有限责任公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 南京中兴新软件有限责任公司 filed Critical 南京中兴新软件有限责任公司
Publication of WO2022100485A1 publication Critical patent/WO2022100485A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3089Monitoring arrangements determined by the means or processing involved in sensing the monitored data, e.g. interfaces, connectors, sensors, probes, agents
    • G06F11/3093Configuration details thereof, e.g. installation, enabling, spatial arrangement of the probes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/865Monitoring of software

Definitions

  • the present disclosure relates to, but is not limited to, the technical field of resource management.
  • OSGi Open Service Gateway Initiative
  • the embedded device improves the dynamic expansion capability of the business.
  • a plug-in applies excessively or occupies virtual machine resources during the running process, it may cause other plug-ins to fail to apply for resources and affect the operation of other plug-ins.
  • the present disclosure provides a method and apparatus for plug-in resource management, an electronic device, and a computer-readable medium.
  • the present disclosure provides a plug-in resource management method, which includes: reading a bytecode file corresponding to the plug-in; inserting a monitoring bytecode at a resource consumption position of the bytecode file, the The resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, and the monitoring bytecode is used to identify the bytecode of the plug-in.
  • the present disclosure provides an apparatus for managing plug-in resources, comprising: a reading module configured to read a bytecode file corresponding to the plug-in; an inserting module configured to read a bytecode file corresponding to the plug-in;
  • the resource consumption position is inserted into the monitoring bytecode, and the resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, and the monitoring bytecode is used for Bytecode that identifies the plugin.
  • the present disclosure provides an electronic device, comprising: one or more processors, and a memory on which one or more programs are stored, when the one or more programs are processed by the one or more programs When the processor is executed, the one or more processors are made to implement any one of the plug-in resource management methods described herein; one or more I/O interfaces, connected between the processor and the memory, are configured to implement the One or more processors interact with information from the memory.
  • the present disclosure provides a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, implements any one of the plug-in resource management methods described herein.
  • FIG. 1 is a flowchart of a method for managing plug-in resources provided by the present disclosure
  • FIG. 2 is a flowchart of another plug-in resource management method provided by the present disclosure.
  • FIG. 3 is a flowchart of another plug-in resource management method provided by the present disclosure.
  • FIG. 5 is a flowchart of another plug-in resource management method provided by the present disclosure.
  • FIG. 6 is a flowchart of another plug-in resource management method provided by the present disclosure.
  • FIG. 7 is a block diagram of a composition of an apparatus for managing plug-in resources provided by the present disclosure.
  • FIG. 9 is a block diagram of the composition of a computer-readable medium provided by the present disclosure.
  • Embodiments of the present disclosure may be described with reference to plan views and/or cross-sectional views with the aid of idealized schematic illustrations of the present disclosure. Accordingly, example illustrations may be modified according to manufacturing techniques and/or tolerances.
  • Embodiments of the present disclosure are not limited to the embodiments shown in the drawings, but include modifications of configurations formed based on manufacturing processes.
  • the regions illustrated in the figures have schematic properties and the shapes of regions illustrated in the figures are illustrative of the specific shapes of regions of elements and are not intended to be limiting.
  • multiple plug-ins deployed in basic software frameworks run in the same virtual machine (such as JAVA virtual machine), and all plug-ins run consume resources, such as threads, CPU (Central Processing Unit, CPU), memory (such as Java heap, stack, direct memory), etc., all depend on the resources of the virtual machine itself.
  • resources such as threads, CPU (Central Processing Unit, CPU), memory (such as Java heap, stack, direct memory), etc., all depend on the resources of the virtual machine itself.
  • a plug-in When a plug-in is running, it applies for too many virtual machine resources or occupies virtual machine resources for a long time, which may affect the operation of other plug-ins. If a plug-in occupies the CPU for a long time, the business operation of other plug-ins may be affected; if a plug-in occupies memory for a long time, other plug-ins may fail to apply for memory, affecting the business operation of other plug-ins.
  • the plug-in excessively applies for virtual machine resources or excessively occupies virtual machine resources during the running process, it will bring huge security risks to the operation of the plug-in.
  • the total amount of resources consumed by all plug-ins can be obtained by counting the resources consumed by the entire virtual machine, unified management of all plug-ins can be achieved.
  • the resources consumed by each plug-in cannot be counted, it is impossible to determine the plug-ins that excessively apply for virtual machine resources or occupy virtual machine resources from multiple plug-ins, and it is also impossible to achieve refined management of resources.
  • the present disclosure provides a method for plug-in resource management, and the method for plug-in resource management of the present disclosure can be used for deploying a basic software framework (such as an OSGi framework), in the same virtual machine (such as The resources of each plug-in in multiple plug-ins running on a JAVA virtual machine can be managed.
  • a basic software framework such as an OSGi framework
  • the plug-in resource management method of the present disclosure may include steps S101 and S102.
  • step S101 the bytecode file corresponding to the plug-in is read.
  • the device system reads all bytecode files corresponding to a plug-in (ie, a plug-in that needs to perform resource management).
  • the device system when receiving a class loading request for a class in a plug-in, the device system reads all bytecode files of the plug-in from the plug-in cache directory of the OSGi framework.
  • class loading refers to loading a bytecode file related to a class into the memory of the virtual machine when a certain class needs to be used during the running process of the virtual machine, running the bytecode file, and generating a virtual machine that can The process of using the object directly.
  • a class loading request is a request for class loading of a certain class
  • a class loading request corresponding to a plug-in refers to a class that needs to be used when the plug-in is running on the virtual machine (or in the process of running the plug-in). class loading request.
  • the bytecode file that is, the file with the extension ".class" is the target file generated by the JAVA compiler compiling the JAVA source file (that is, the file with the extension ".java”).
  • the JAVA A bytecode file is generated for each class in the source file.
  • the bytecode file corresponding to the plug-in refers to the bytecode file corresponding to the class that needs to be used during the process of the plug-in running on the virtual machine.
  • the bytecode files related to the class of the plug-in will be loaded into the virtual machine memory (or cache), which can be easily retrieved from the cache directory. Get the bytecode file corresponding to the plugin.
  • step S102 the monitoring bytecode is inserted into the resource consumption position of the bytecode file, the resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, the monitoring bytecode is Bytecode is used to identify the plugin's bytecode.
  • the device system analyzes the read bytecode file, analyzes whether there is a resource consumption position in the bytecode file, and if so, inserts a monitoring bytecode in the resource consumption position.
  • the resource consumption location refers to the location of the bytecode corresponding to the resource function in the bytecode file.
  • the resource consumption function refers to the function that needs to consume the resources of the virtual machine during the running process of the virtual machine, or the execution process of the JAVA source file, such as the thread creation function.
  • the monitoring bytecode is used to identify the plug-in corresponding to the bytecode file where the resource consumption location exists, for example, it can be the ID (unique code) of the plug-in.
  • the device system After completing the insertion of the monitoring bytecode, the device system performs the class loading process according to the class loading request, that is, loads the corresponding bytecode file into the memory of the virtual machine, and runs the bytecode file.
  • the corresponding relationship between the plug-in and the resource function corresponding to the bytecode inserted with the monitoring bytecode can be established.
  • a relationship table may be established in the system to record the corresponding relationship between plug-ins and resource functions.
  • the resources consumed by the resource function can be obtained during the operation of the plug-in, the resources consumed by each plug-in can be easily obtained through the corresponding relationship between each plug-in and the resource function, as well as the resources consumed by each resource function. .
  • the plug-in resource management method of the present disclosure inserts monitoring bytecode into the resource consumption position of the bytecode file corresponding to the plug-in before the class corresponding to the plug-in is loaded, and performs the class operation in the class corresponding to the plug-in by monitoring the bytecode. During the loading process, establish a corresponding relationship between resource functions and plug-ins.
  • the monitoring bytecode is inserted before class loading, and the corresponding relationship between resource functions and plug-ins is established during the class loading process, which has little impact on the original class loading process and is easy to implement; on the other hand, through resource functions and plug-ins You can obtain the resources consumed by each plug-in, so as to realize the refined control and management of resources and plug-ins, and improve the stability, reliability and security of device operation.
  • the method further includes: step S103, determining the resource consumed by the resource function corresponding to the bytecode file Resources consumed for plugins.
  • the device system After completing the insertion of the monitoring bytecode, the device system performs the class loading process according to the class loading request, that is, loads the corresponding bytecode file into the memory of the virtual machine, and runs the bytecode file.
  • the device system can determine the plug-in corresponding to the resource function according to the plug-in identifier in the monitoring bytecode.
  • the resource consumed by the resource function is can be obtained, so the resources consumed by the plugin are determined by the resources consumed by the corresponding resource function when the bytecode inserted into the monitoring bytecode is run.
  • the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in ( S103 ), including steps S1031 and S1032 .
  • step S1031 the corresponding relationship between the resource function and the plug-in is established according to the monitoring bytecode.
  • step S1032 according to the corresponding relationship, the resource function corresponding to the plug-in is determined, and it is determined that the resource consumed by the resource function corresponding to the plug-in is the resource consumed by the plug-in.
  • the device system After completing the insertion of the monitoring bytecode, the device system performs the class loading process according to the class loading request, that is, loads the corresponding bytecode file into the memory of the virtual machine, and runs the bytecode file.
  • the bytecode with the monitoring bytecode inserted into the device system is run, according to the plug-in identifier in the monitoring bytecode, the corresponding relationship between the plug-in and the resource function corresponding to the bytecode inserted with the monitoring bytecode can be established. .
  • a relationship table may be established in the system to record the corresponding relationship between plug-ins and resource functions.
  • the resources consumed by the resource function can be obtained during the operation of the plug-in, the resources consumed by each plug-in can be easily obtained through the corresponding relationship between each plug-in and the resource function, as well as the resources consumed by each resource function. .
  • the resource function includes a thread creation function that is used to create a plug-in thread.
  • the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in ( S103 ), including steps S1033 and/or S1034 .
  • step S1033 count the CPU time occupied by the plug-in thread created by the thread creation function corresponding to the bytecode file, and use the sum of the CPU time occupied by all plug-in threads as the CPU time occupied by the plug-in.
  • step S1034 the number of plug-in threads created by the thread creation function corresponding to the bytecode file is counted, and the number of plug-in threads is taken as the number of threads consumed by the plug-in.
  • the device system can determine the correspondence between the plug-in and the thread created by the thread creation function according to the plug-in identifier in the monitoring bytecode.
  • the thread creation function (or the thread constructor) is a function for creating a thread, and there are many ways to create a thread, for example, a thread can be created by extending a thread class.
  • a thread is the execution unit of the plug-in. Each thread has an ID that is different from other threads. Multiple threads form a process, and multiple threads that form a process share all the resources of the process.
  • the corresponding relationship between the plug-in and the thread created by the thread creation function is determined, for example, the corresponding relationship between the ID of the plug-in thread and the plug-in ID can be established.
  • the thread and the resources consumed by the thread can be obtained. Therefore, through the corresponding relationship between each plug-in and the thread, as well as the resources consumed by each thread, the resources consumed by each plug-in can be easily obtained.
  • the device system calculates the CPU time occupied by the plug-in by counting the CPU time occupied by all threads corresponding to the plug-in. For example, the sum of the CPU time occupied by all threads corresponding to a plug-in may be used as the CPU time occupied by the plug-in.
  • the device system After establishing the correspondence between plug-ins and threads, the device system obtains the number of threads consumed by a plug-in by counting the number of all threads corresponding to a plug-in.
  • the resource function includes an entry function
  • the entry function includes a start function and a stop function.
  • the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in ( S103 ), including: S1035 , counting the memory space consumed by each plug-in object, and using all plug-in objects to consume The sum of the memory space of the plug-in is used as the memory space consumed by the plug-in, and the plug-in object is the object created during the operation of the start function and stop function corresponding to the bytecode file.
  • the device system When the bytecodes corresponding to the start function and the stop function are run, the device system establishes the correspondence between the plug-in and the plug-in object according to the plug-in identifier in the monitoring bytecode.
  • each plug-in has only one start function, which is the start of the plug-in operation, and one stop function, which is the end of the plug-in operation.
  • the objects created are all plug-in objects.
  • the monitoring bytecode when the monitoring bytecode is inserted into the bytecode corresponding to the start function and the stop function, the monitoring bytecode needs to be inserted in the bytecode corresponding to the start and end of the start function and the stop function in the word
  • the location in the section code file in order to monitor all the plug-in objects created by the plug-in from the beginning to the end of the operation, and establish the corresponding relationship between the plug-in objects and the plug-ins.
  • the device system calculates the memory space consumed by the plug-in by counting the memory space consumed by all plug-in objects corresponding to a plug-in. For example, the sum of the memory space consumed by all plug-in objects corresponding to a plug-in may be used as the memory space consumed by the plug-in.
  • the method further includes: S104, controlling the plug-in according to the resources consumed by the plug-in .
  • the resources consumed by the resource function such as threads, CPU time, memory space, etc.
  • the resources consumed by each plug-in are calculated, and all plug-ins are controlled according to the resources consumed by each plug-in.
  • controlling the plug-in may be: calculating the resource consumption risk level of each plug-in according to the resources that the plug-in may consume during the plug-in running process.
  • the The resource consumption risk level is high; on the contrary, when the amount of resources that the plug-in may consume during the plug-in running process is small, the resource consumption risk level of the plug-in is low.
  • plug-ins can be classified according to their types, for example, plug-ins are divided into system plug-ins (plug-ins used by the OSGi framework), preset plug-ins (plug-ins necessary for device services), and open plug-ins (plug-ins that may be required by device services). ), generate a plug-in classification file, and record the classification information of each plug-in in the plug-in classification file, such as plug-in name, plug-in version number, plug-in type (one of system plug-ins, preset plug-ins, and open plug-ins), and plug-in resource consumption risk level, description of plug-in functions, etc.
  • system plug-ins plug-ins used by the OSGi framework
  • preset plug-ins plug-ins necessary for device services
  • open plug-ins plug-ins that may be required by device services.
  • plug-in classification information in the plug-in classification file is read, and plug-ins whose resource consumption risk levels are high and medium risk are regarded as key monitoring objects. Control Groups) technology to control it.
  • controlling the plug-in may also be: setting a resource consumption threshold of a single plug-in, such as setting thresholds for the CPU time occupied by the plug-in, the consumed memory and the number of threads consumed, when the resources consumed by a plug-in are If the set threshold is exceeded, the plug-in is controlled.
  • setting a resource consumption threshold of a single plug-in such as setting thresholds for the CPU time occupied by the plug-in, the consumed memory and the number of threads consumed, when the resources consumed by a plug-in are If the set threshold is exceeded, the plug-in is controlled.
  • the threshold of the CPU time occupied by the plug-in can be set; by setting Bundle.Resource.Memory.Threshold in the resource consumption configuration file, set Set the threshold of memory consumed by the plug-in; set the threshold of the number of threads consumed by the plug-in by setting Bundle.Resource.Thread.Threshold in the resource consumption configuration file.
  • the plug-in During the running process of the plug-in, read the threshold value set in the resource consumption configuration file, and use it as the basis for judging whether to control the plug-in. When the resources consumed by a plug-in exceed the set threshold, the plug-in is controlled by the Linux security control technology.
  • control the plug-in it can also be: count the resource consumption value of each plug-in, and store the records in the plug-in resource consumption table, and calculate the JAVA virtual value according to the data corresponding to each plug-in in the plug-in resource consumption table.
  • the historical average value of each resource consumed by each plug-in under the computer, and the calculated historical average value is used as the judgment basis for plug-in control.
  • the plug-in is a plug-in that operates based on the Open Services Gateway Protocol.
  • the basic software framework of the embodiments of the present disclosure may be, for example, an OSGi framework.
  • the OSGi framework When the OSGi framework deploys the plug-in, it uses the plug-in dynamic deployment technology. Compared with the traditional plug-in static deployment technology, the dynamic deployment has the characteristics of light weight and flexibility.
  • the method of the embodiment of the present disclosure may include steps A01 to A04.
  • step A01 before the JAVA virtual machine starts the class loading of the class corresponding to the plug-in, the class loading process is intercepted by the JavaAgent class library, and the bytecode file corresponding to the plug-in is obtained from the cache directory.
  • step A02 the acquired bytecode file is analyzed and edited through the JavaSsist class library.
  • the monitoring bytecode can be the plug-in ID; at the same time, it is also judged whether the function corresponding to the bytecode is a thread creation function.
  • the bytecode corresponding to the creation function inserts the monitoring bytecode word at the position in the bytecode file, and the monitoring bytecode can be the plug-in ID.
  • step A03 the class loading process is performed, the bytecode file inserted into the monitoring bytecode is run, and according to the monitoring bytecode, a relationship table of the correspondence between the plug-in and the thread is established in the JAVA virtual machine to record the correspondence between the plug-in and the thread relation.
  • Javax.Bundle.ResourceInfo and JNI Java Native Interface, JAVA native interface
  • Javax.Bundle.CPUUsage class By defining the JAVA extension class Javax.Bundle.ResourceInfo and JNI (Java Native Interface, JAVA native interface) to implement the statistics and calculation of the resources consumed by the plug-in, and by defining the Javax.Bundle.CPUUsage class, it provides a method to obtain the calculated resources consumed by the plug-in. Interfaces, such as defining the getBundleID function, which is an interface for obtaining the plug-in ID; and defining the getCPUTime function, which is an interface for obtaining the CPU time occupied by the plug-in.
  • the method of counting and calculating the CPU time occupied by the plug-in is as follows: when all threads of the JAVA virtual machine are started, the start time of the thread is set, and when the CPU time occupied by the plug-in needs to be counted and calculated, the JNI of the JAVA virtual machine Get all currently running threads, calculate the difference between the most recent CPU occupied time point of each running thread and its starting time, to obtain the occupied CPU time of the thread, and assign the thread corresponding to the plug-in among the running threads The occupied CPU time is accumulated and calculated to obtain the CPU time occupied by the plug-in.
  • step A04 the data of the resources consumed by the plug-in is acquired by calling the interface, and the acquired data is processed and recorded in the internal log file of the device, or printed to the interface.
  • step S104 of the plug-in resource management method according to the embodiment of the present disclosure may further include steps B01 to B04.
  • step B01 a plug-in running under the OSGi framework is obtained, and the name of the running plug-in is obtained by calling the OSGi service interface.
  • step B02 according to the plug-in classification file, the resource consumption risk level of each plug-in is judged in turn. If the resource consumption risk level of the plug-in is high risk or medium risk, it belongs to the need for refined control of the plug-in.
  • step B03 periodically update the resource consumption data of the plug-in that needs refined control, calculate the CPU time occupied by the plug-in in each cycle under the JAVA virtual machine, and determine whether the CPU time occupied by the plug-in continues for T (for example, you can is greater than the set threshold for 5) cycles.
  • step B04 if yes, then according to the corresponding relationship between the plug-in and the thread, obtain all the running threads corresponding to the plug-in, and set the IDs of these threads as control parameters to limit the CPU time occupied by these threads during execution .
  • the present disclosure provides an apparatus for managing plug-in resources, which includes: a reading module configured to read a bytecode file corresponding to the plug-in; an inserting module configured to The resource consumption position is inserted into the monitoring bytecode.
  • the resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process.
  • the monitoring bytecode is used to identify the bytecode of the plug-in .
  • the monitoring bytecode is inserted into the resource consumption position of the bytecode file corresponding to the plug-in, and the In the process of class loading, the corresponding relationship between resource functions and plug-ins is established.
  • the monitoring bytecode is inserted before class loading, and the corresponding relationship between resource functions and plug-ins is established during the class loading process, which has little impact on the original class loading process and is easy to implement; on the other hand, through resource functions and plug-ins You can obtain the resources consumed by each plug-in, so as to realize the refined control and management of resources and plug-ins, and improve the stability, reliability and security of device operation.
  • the present disclosure provides an electronic device comprising: one or more processors, and a memory having one or more programs stored thereon, when the one or more programs are processed by one or more When the processor is executed, one or more processors are made to implement any one of the above plug-in resource management methods; one or more I/O interfaces are connected between the processor and the memory and are configured to realize the information between the processor and the memory interact.
  • the processor is a device with data processing capability, which includes but is not limited to a central processing unit (CPU), etc.
  • the memory is a device with data storage capability, which includes but is not limited to random access memory (RAM, more specifically such as SDRAM) , DDR, etc.), read-only memory (ROM), electrified erasable programmable read-only memory (EEPROM), flash memory (FLASH); I/O interface (read and write interface) is connected between the processor and the memory to realize the memory Information interaction with the processor, including but not limited to a data bus (Bus) and the like.
  • RAM random access memory
  • ROM read-only memory
  • EEPROM electrified erasable programmable read-only memory
  • FLASH flash memory
  • I/O interface read and write interface
  • the present disclosure provides a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, any one of the above plug-in resource management methods is implemented.
  • the processor is a device with data processing capability, which includes but is not limited to a central processing unit (CPU), etc.
  • the memory is a device with data storage capability, which includes but is not limited to random access memory (RAM, more specifically such as SDRAM) , DDR, etc.), read-only memory (ROM), electrified erasable programmable read-only memory (EEPROM), flash memory (FLASH); I/O interface (read and write interface) is connected between the processor and the memory, which can realize the memory and the memory.
  • the information exchange of the processor which includes but is not limited to the data bus (Bus) and the like.
  • the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be composed of several physical components Components execute cooperatively.
  • Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit (CPU), digital signal processor or microprocessor, or as hardware, or as an integrated circuit such as Application-specific integrated circuits.
  • a processor such as a central processing unit (CPU), digital signal processor or microprocessor, or as hardware, or as an integrated circuit such as Application-specific integrated circuits.
  • Such software may be distributed on computer-readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media).
  • computer storage media includes both volatile and nonvolatile implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data flexible, removable and non-removable media.
  • Computer storage media include, but are not limited to, random access memory (RAM, more specifically SDRAM, DDR, etc.), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory (FLASH), or other disk storage ; compact disc read only (CD-ROM), digital versatile disk (DVD), or other optical disk storage; magnetic cartridge, tape, magnetic disk storage or other magnetic storage; any other storage that can be used to store desired information and that can be accessed by a computer medium.
  • communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and can include any information delivery media, as is well known to those of ordinary skill in the art .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

Provided is a plug-in resource management method. The method comprises: reading a bytecode file corresponding to a plug-in; and interpolating a monitoring bytecode into a resource consumption location in the bytecode file, wherein the resource consumption location is a location, in the bytecode file, of a bytecode corresponding to a resource function that requires resource consumption during a running process, and the monitoring bytecode is used for marking a bytecode of the plug-in. Further provided are a plug-in resource management apparatus, an electronic device, and a computer-readable medium.

Description

插件资源管理的方法和装置、电子设备、计算机可读介质Plug-in resource management method and apparatus, electronic device, and computer-readable medium
相关申请的交叉引用CROSS-REFERENCE TO RELATED APPLICATIONS
本申请要求2020年11月10提交给中国专利局的第202011249572.5号专利申请的优先权,其全部内容通过引用合并于此。This application claims priority to Patent Application No. 202011249572.5 filed with the China Patent Office on November 10, 2020, the entire contents of which are incorporated herein by reference.
技术领域technical field
本公开涉及但不限于资源管理技术领域。The present disclosure relates to, but is not limited to, the technical field of resource management.
背景技术Background technique
现有的基础软件框架,如OSGi(Open Service Gateway Initiative,开放服务网关协议)框架,越来越多的被应用于各种嵌入式设备中,如智能家庭网关、机顶盒等家庭组网设备。Existing basic software frameworks, such as OSGi (Open Service Gateway Initiative) framework, are increasingly used in various embedded devices, such as smart home gateways, set-top boxes and other home networking devices.
利用OSGi框架的插件动态部署技术,嵌入式设备提升了业务动态扩展能力。Using the plug-in dynamic deployment technology of the OSGi framework, the embedded device improves the dynamic expansion capability of the business.
但若在运行过程中,某个插件过度申请或占用虚拟机资源,可能会导致其他插件申请资源失败,影响其他插件的运行。However, if a plug-in applies excessively or occupies virtual machine resources during the running process, it may cause other plug-ins to fail to apply for resources and affect the operation of other plug-ins.
发明内容SUMMARY OF THE INVENTION
本公开提供一种插件资源管理的方法和装置、电子设备、计算机可读介质。The present disclosure provides a method and apparatus for plug-in resource management, an electronic device, and a computer-readable medium.
第一方面,本公开提供一种插件资源管理的方法,其包括:读取与所述插件对应的字节码文件;在所述字节码文件的资源消耗位置***监控字节码,所述资源消耗位置为,在运行过程中需要消耗资源的资源函数对应的字节码在所述字节码文件中的位置,所述监控字节码用于标识所述插件的字节码。In a first aspect, the present disclosure provides a plug-in resource management method, which includes: reading a bytecode file corresponding to the plug-in; inserting a monitoring bytecode at a resource consumption position of the bytecode file, the The resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, and the monitoring bytecode is used to identify the bytecode of the plug-in.
第二方面,本公开提供一种插件资源管理的装置,其包括:读取模块,配置为读取与所述插件对应的字节码文件;***模块,配置为在所述字节码文件的资源消耗位置***监控字节码,所述资源消耗位 置为,在运行过程中需要消耗资源的资源函数对应的字节码在所述字节码文件中的位置,所述监控字节码用于标识所述插件的字节码。In a second aspect, the present disclosure provides an apparatus for managing plug-in resources, comprising: a reading module configured to read a bytecode file corresponding to the plug-in; an inserting module configured to read a bytecode file corresponding to the plug-in; The resource consumption position is inserted into the monitoring bytecode, and the resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, and the monitoring bytecode is used for Bytecode that identifies the plugin.
第三方面,本公开提供一种电子设备,其包括:一个或多个处理器,存储器,其上存储有一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行时,使得所述一个或多个处理器实现本文所述任意一项的插件资源管理的方法;一个或多个I/O接口,连接在处理器与存储器之间,配置为实现所述一个或多个处理器与存储器的信息交互。In a third aspect, the present disclosure provides an electronic device, comprising: one or more processors, and a memory on which one or more programs are stored, when the one or more programs are processed by the one or more programs When the processor is executed, the one or more processors are made to implement any one of the plug-in resource management methods described herein; one or more I/O interfaces, connected between the processor and the memory, are configured to implement the One or more processors interact with information from the memory.
第四方面,本公开提供一种计算机可读介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现本文所述任意一种插件资源管理的方法。In a fourth aspect, the present disclosure provides a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, implements any one of the plug-in resource management methods described herein.
附图说明Description of drawings
图1为本公开提供的一种插件资源管理的方法的流程图;1 is a flowchart of a method for managing plug-in resources provided by the present disclosure;
图2为本公开提供的另一种插件资源管理的方法的流程图;2 is a flowchart of another plug-in resource management method provided by the present disclosure;
图3为本公开提供的另一种插件资源管理的方法的流程图;3 is a flowchart of another plug-in resource management method provided by the present disclosure;
图4为本公开提供的另一种插件资源管理的方法的流程图;4 is a flowchart of another plug-in resource management method provided by the present disclosure;
图5为本公开提供的另一种插件资源管理的方法的流程图;5 is a flowchart of another plug-in resource management method provided by the present disclosure;
图6为本公开提供的另一种插件资源管理的方法的流程图;6 is a flowchart of another plug-in resource management method provided by the present disclosure;
图7为本公开提供的一种插件资源管理的装置的组成框图;7 is a block diagram of a composition of an apparatus for managing plug-in resources provided by the present disclosure;
图8为本公开提供的一种电子设备的组成框图;8 is a block diagram of the composition of an electronic device provided by the present disclosure;
图9为本公开提供的一种计算机可读介质的组成框图。FIG. 9 is a block diagram of the composition of a computer-readable medium provided by the present disclosure.
具体实施方式Detailed ways
为使本领域的技术人员更好地理解本公开实施方式的技术方案,下面结合附图对本公开实施方式提供的插件资源管理的方法和装置、电子设备、计算机可读介质进行详细描述。To make those skilled in the art better understand the technical solutions of the embodiments of the present disclosure, the method and apparatus, electronic device, and computer-readable medium for managing plug-in resources provided by the embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
在下文中将参考附图更充分地描述本公开实施方式,但是所示的实施方式可以以不同形式来体现,且不应当被解释为限于本公开阐述的实施方式。反之,提供这些实施方式的目的在于使本公开透彻和 完整,并将使本领域技术人员充分理解本公开的范围。Embodiments of the present disclosure will be described more fully hereinafter with reference to the accompanying drawings, but the illustrated embodiments may be embodied in different forms and should not be construed as limited to the embodiments set forth in this disclosure. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
本公开实施方式的附图用来提供对本公开实施方式的进一步理解,并且构成说明书的一部分,与本公开实施方式一起用于解释本公开,并不构成对本公开的限制。通过参考附图对详细示例实施方式进行描述,以上和其他特征和优点对本领域技术人员将变得更加显而易见,The accompanying drawings of the embodiments of the present disclosure are used to provide further understanding of the embodiments of the present disclosure, and constitute a part of the specification, and together with the embodiments of the present disclosure, they are used to explain the present disclosure, and do not limit the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art from the description of detailed example embodiments with reference to the accompanying drawings,
本公开实施方式可借助本公开的理想示意图而参考平面图和/或截面图进行描述。因此,可根据制造技术和/或容限来修改示例图示。Embodiments of the present disclosure may be described with reference to plan views and/or cross-sectional views with the aid of idealized schematic illustrations of the present disclosure. Accordingly, example illustrations may be modified according to manufacturing techniques and/or tolerances.
在不冲突的情况下,本公开各实施方式及实施方式中的各特征可相互组合。Various embodiments of the present disclosure and individual features of embodiments may be combined with each other without conflict.
本公开所使用的术语仅用于描述特定实施方式,且不意欲限制本公开。如本公开所使用的术语“和/或”包括一个或多个相关列举条目的任何和所有组合。如本公开所使用的单数形式“一个”和“该”也意欲包括复数形式,除非上下文另外清楚指出。如本公开所使用的术语“包括”、“由……制成”,指定存在所述特征、整体、步骤、操作、元件和/或组件,但不排除存在或添加一个或多个其他特征、整体、步骤、操作、元件、组件和/或其群组。The terminology used in this disclosure is used to describe particular embodiments only, and is not intended to limit the disclosure. As used in this disclosure, the term "and/or" includes any and all combinations of one or more of the associated listed items. As used in this disclosure, the singular forms "a" and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. The terms "comprising", "made of", as used in this disclosure, specify the presence of stated features, integers, steps, operations, elements and/or components, but do not preclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and/or groups thereof.
除非另外限定,否则本公开所用的所有术语(包括技术和科学术语)的含义与本领域普通技术人员通常理解的含义相同。还将理解,诸如那些在常用字典中限定的那些术语应当被解释为具有与其在相关技术以及本公开的背景下的含义一致的含义,且将不解释为具有理想化或过度形式上的含义,除非本公开明确如此限定。Unless otherwise defined, all terms (including technical and scientific terms) used in this disclosure have the same meaning as commonly understood by one of ordinary skill in the art. It will also be understood that terms such as those defined in common dictionaries should be construed as having meanings consistent with their meanings in the context of the related art and the present disclosure, and will not be construed as having idealized or over-formal meanings, Unless this disclosure expressly so limited.
本公开实施方式不限于附图中所示的实施方式,而是包括基于制造工艺而形成的配置的修改。因此,附图中例示的区具有示意性属性,并且图中所示区的形状例示了元件的区的具体形状,但并不是旨在限制性的。Embodiments of the present disclosure are not limited to the embodiments shown in the drawings, but include modifications of configurations formed based on manufacturing processes. Thus, the regions illustrated in the figures have schematic properties and the shapes of regions illustrated in the figures are illustrative of the specific shapes of regions of elements and are not intended to be limiting.
在一些相关技术中,部署在基础软件框架(如OSGi框架)的多个插件,在同一个虚拟机(如JAVA虚拟机)运行,所有插件运行消耗的资源,如线程、CPU(Central Processing Unit,中央处理器)、 内存(如Java堆、栈、直接内存)等,都依赖于虚拟机本身的资源。In some related technologies, multiple plug-ins deployed in basic software frameworks (such as OSGi framework) run in the same virtual machine (such as JAVA virtual machine), and all plug-ins run consume resources, such as threads, CPU (Central Processing Unit, CPU), memory (such as Java heap, stack, direct memory), etc., all depend on the resources of the virtual machine itself.
当某个插件在运行过程中,申请过多的虚拟机资源或长时间占用虚拟机的资源,可能会影响其他插件的运行。如某个插件长时间占用CPU,可能导致其他插件的业务运行受到影响;某个插件长时间占用内存,可能导致其他插件申请内存失败,影响其他插件的业务运行。When a plug-in is running, it applies for too many virtual machine resources or occupies virtual machine resources for a long time, which may affect the operation of other plug-ins. If a plug-in occupies the CPU for a long time, the business operation of other plug-ins may be affected; if a plug-in occupies memory for a long time, other plug-ins may fail to apply for memory, affecting the business operation of other plug-ins.
特别的,若插件在运行过程中过度申请虚拟机资源或过度占用虚拟机资源,会给插件运行带来巨大的安全隐患。In particular, if the plug-in excessively applies for virtual machine resources or excessively occupies virtual machine resources during the running process, it will bring huge security risks to the operation of the plug-in.
通过对整个虚拟机消耗的资源进行统计虽然可以获取所有插件消耗的资源总量,以实现对所有插件的统一管理。但由于无法统计各个插件各自消耗的资源,因此无法从多个插件中判断出过度申请虚拟机资源或占用虚拟机资源的插件,也无法实现对资源的精细化管理。Although the total amount of resources consumed by all plug-ins can be obtained by counting the resources consumed by the entire virtual machine, unified management of all plug-ins can be achieved. However, since the resources consumed by each plug-in cannot be counted, it is impossible to determine the plug-ins that excessively apply for virtual machine resources or occupy virtual machine resources from multiple plug-ins, and it is also impossible to achieve refined management of resources.
第一方面,参照图1,本公开提供一种插件资源管理的方法,本公开的插件资源管理的方法可以用于,对部署于基础软件框架(如OSGi框架),在同一个虚拟机(例如可以是JAVA虚拟机)上运行的多个插件中每个插件的资源进行管理。In the first aspect, referring to FIG. 1 , the present disclosure provides a method for plug-in resource management, and the method for plug-in resource management of the present disclosure can be used for deploying a basic software framework (such as an OSGi framework), in the same virtual machine (such as The resources of each plug-in in multiple plug-ins running on a JAVA virtual machine can be managed.
如图1所示,本公开的插件资源管理方法可以包括步骤S101和S102。As shown in FIG. 1 , the plug-in resource management method of the present disclosure may include steps S101 and S102.
在步骤S101,读取与插件对应的字节码文件。In step S101, the bytecode file corresponding to the plug-in is read.
设备***读取与某个插件(即需要进行资源管理的插件)对应的所有字节码文件。The device system reads all bytecode files corresponding to a plug-in (ie, a plug-in that needs to perform resource management).
示例性地,设备***在接收到插件中的类的类加载请求的情况下,从OSGi框架的插件缓存目录中读取该插件的所有字节码文件。Exemplarily, when receiving a class loading request for a class in a plug-in, the device system reads all bytecode files of the plug-in from the plug-in cache directory of the OSGi framework.
其中,类加载是指在虚拟机的运行过程中,在需要使用某个类的情况下,将与该类相关的字节码文件加载到虚拟机内存,运行字节码文件,生成虚拟机可以直接使用的对象的过程。Among them, class loading refers to loading a bytecode file related to a class into the memory of the virtual machine when a certain class needs to be used during the running process of the virtual machine, running the bytecode file, and generating a virtual machine that can The process of using the object directly.
类加载请求即对某个类进行类加载的请求,插件对应的类加载请求,是指请求加载的类为插件在虚拟机上运行的过程中(或者说在插件运行过程中)需要使用的类的类加载请求。A class loading request is a request for class loading of a certain class, and a class loading request corresponding to a plug-in refers to a class that needs to be used when the plug-in is running on the virtual machine (or in the process of running the plug-in). class loading request.
字节码文件,即扩展名为“.class”的文件,是JAVA编译器编 译JAVA源文件(即扩展名为“.java”文件)产生的目标文件,在JAVA编译器的编译过程中,JAVA源文件中每个类都会生成一个字节码文件。The bytecode file, that is, the file with the extension ".class", is the target file generated by the JAVA compiler compiling the JAVA source file (that is, the file with the extension ".java"). During the compilation process of the JAVA compiler, the JAVA A bytecode file is generated for each class in the source file.
与插件对应的字节码文件,是指在插件在虚拟机上运行的过程中,需要使用的类对应的字节码文件。The bytecode file corresponding to the plug-in refers to the bytecode file corresponding to the class that needs to be used during the process of the plug-in running on the virtual machine.
因此,在接收到插件中的类的类加载请求的情况下,与该插件的类相关的字节码文件都会被加载至虚拟机内存(或者说缓存中),从缓存目录中可以较为容易的获取与插件对应的字节码文件。Therefore, when a class loading request for a class in a plug-in is received, the bytecode files related to the class of the plug-in will be loaded into the virtual machine memory (or cache), which can be easily retrieved from the cache directory. Get the bytecode file corresponding to the plugin.
在步骤S102,在字节码文件的资源消耗位置***监控字节码,资源消耗位置为,在运行过程中需要消耗资源的资源函数对应的字节码在字节码文件中的位置,监控字节码用于标识插件的字节码。In step S102, the monitoring bytecode is inserted into the resource consumption position of the bytecode file, the resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, the monitoring bytecode is Bytecode is used to identify the plugin's bytecode.
设备***对读取的字节码文件进行分析,分析字节码文件中是否存在资源消耗位置,若存在,则在资源消耗位置***监控字节码。The device system analyzes the read bytecode file, analyzes whether there is a resource consumption position in the bytecode file, and if so, inserts a monitoring bytecode in the resource consumption position.
其中,资源消耗位置是指,资源函数对应的字节码在字节码文件中的位置。资源消耗函数,是指在虚拟机的运行过程中,或者说JAVA源文件被执行过程中,需要消耗虚拟机资源的函数,如线程创建函数等。The resource consumption location refers to the location of the bytecode corresponding to the resource function in the bytecode file. The resource consumption function refers to the function that needs to consume the resources of the virtual machine during the running process of the virtual machine, or the execution process of the JAVA source file, such as the thread creation function.
监控字节码则用于标识存在资源消耗位置的字节码文件对应的插件,例如可以是插件的ID(唯一编码)。The monitoring bytecode is used to identify the plug-in corresponding to the bytecode file where the resource consumption location exists, for example, it can be the ID (unique code) of the plug-in.
设备***在完成监控字节码的***后,根据类加载请求,进行类加载过程,即将对应的字节码文件加载至虚拟机内存,运行字节码文件。After completing the insertion of the monitoring bytecode, the device system performs the class loading process according to the class loading request, that is, loads the corresponding bytecode file into the memory of the virtual machine, and runs the bytecode file.
设备***在***了监控字节码的字节码被运行时,根据监控字节码中插件的标识,可以建立插件与***了监控字节码的字节码对应的资源函数之间的对应关系。例如可以是,在***中建立一张关系表,记录插件与资源函数的对应关系。When the bytecode with the monitoring bytecode inserted into the device system is run, according to the plug-in identifier in the monitoring bytecode, the corresponding relationship between the plug-in and the resource function corresponding to the bytecode inserted with the monitoring bytecode can be established. . For example, a relationship table may be established in the system to record the corresponding relationship between plug-ins and resource functions.
由于在插件运行过程中,资源函数消耗的资源是可以获取的,因此通过每个插件与资源函数的对应关系,以及每个资源函数消耗的资源,可以较为容易的得到每个插件所消耗的资源。Since the resources consumed by the resource function can be obtained during the operation of the plug-in, the resources consumed by each plug-in can be easily obtained through the corresponding relationship between each plug-in and the resource function, as well as the resources consumed by each resource function. .
在获取每个插件所消耗的资源后,一方面,当存在过度申请虚拟 机资源或占用虚拟机资源的插件,可以根据每个插件消耗的资源,从多个插件中判断出过度申请虚拟机资源或占用虚拟机资源的插件;另一方面,以插件为粒度,可以对虚拟机的资源进行精细化的控制和管理。After obtaining the resources consumed by each plug-in, on the one hand, when there are plug-ins that excessively apply for virtual machine resources or occupy virtual machine resources, you can judge the excessive application of virtual machine resources from multiple plug-ins according to the resources consumed by each plug-in. Or plug-ins that occupy virtual machine resources; on the other hand, with plug-ins as granularity, the resources of virtual machines can be finely controlled and managed.
本公开的插件资源管理的方法,在插件对应的类进行类加载之前,在插件对应的字节码文件的资源消耗位置***监控字节码,通过监控字节码,在插件对应的类进行类加载的过程中,将资源函数与插件建立对应关系。一方面,在类加载之前***监控字节码,在类加载过程中建立资源函数与插件的对应关系,对原有的类加载过程影响较小,易于实现;另一方面,通过资源函数与插件的对应关系以及资源函数消耗的资源,可以获取每个插件消耗的资源,从而实现对资源以及插件的精细化控制与管理,提升设备运行稳定性、可靠性和安全性。The plug-in resource management method of the present disclosure inserts monitoring bytecode into the resource consumption position of the bytecode file corresponding to the plug-in before the class corresponding to the plug-in is loaded, and performs the class operation in the class corresponding to the plug-in by monitoring the bytecode. During the loading process, establish a corresponding relationship between resource functions and plug-ins. On the one hand, the monitoring bytecode is inserted before class loading, and the corresponding relationship between resource functions and plug-ins is established during the class loading process, which has little impact on the original class loading process and is easy to implement; on the other hand, through resource functions and plug-ins You can obtain the resources consumed by each plug-in, so as to realize the refined control and management of resources and plug-ins, and improve the stability, reliability and security of device operation.
在一些实施方式中,参照图2,在字节码文件的资源消耗位置***监控字节码(S102)之后,所述方法还包括:步骤S103、确定字节码文件对应的资源函数消耗的资源为插件消耗的资源。In some embodiments, referring to FIG. 2 , after inserting the monitoring bytecode in the resource consumption position of the bytecode file (S102), the method further includes: step S103, determining the resource consumed by the resource function corresponding to the bytecode file Resources consumed for plugins.
设备***在完成监控字节码的***后,根据类加载请求,进行类加载过程,即将对应的字节码文件加载至虚拟机内存,运行字节码文件。After completing the insertion of the monitoring bytecode, the device system performs the class loading process according to the class loading request, that is, loads the corresponding bytecode file into the memory of the virtual machine, and runs the bytecode file.
设备***在***了监控字节码的字节码被运行时,根据监控字节码中插件的标识,可以确定资源函数对应的插件,同时,由于在插件运行过程中,资源函数消耗的资源是可以获取的,因此通过***了监控字节码的字节码被运行时,对应的资源函数消耗的资源来确定插件消耗的资源。When the bytecode into which the monitoring bytecode is inserted is executed, the device system can determine the plug-in corresponding to the resource function according to the plug-in identifier in the monitoring bytecode. At the same time, since the resource consumed by the resource function is can be obtained, so the resources consumed by the plugin are determined by the resources consumed by the corresponding resource function when the bytecode inserted into the monitoring bytecode is run.
在一些实施方式中,参照图3,确定字节码文件对应的资源函数消耗的资源为插件消耗的资源(S103),包括步骤S1031和S1032。In some embodiments, referring to FIG. 3 , it is determined that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in ( S103 ), including steps S1031 and S1032 .
在步骤S1031,根据监控字节码建立资源函数与插件的对应关系。In step S1031, the corresponding relationship between the resource function and the plug-in is established according to the monitoring bytecode.
在步骤S1032,根据对应关系,确定插件对应的资源函数,并确 定插件对应的资源函数消耗的资源为插件消耗的资源。In step S1032, according to the corresponding relationship, the resource function corresponding to the plug-in is determined, and it is determined that the resource consumed by the resource function corresponding to the plug-in is the resource consumed by the plug-in.
设备***在完成监控字节码的***后,根据类加载请求,进行类加载过程,即将对应的字节码文件加载至虚拟机内存,运行字节码文件。After completing the insertion of the monitoring bytecode, the device system performs the class loading process according to the class loading request, that is, loads the corresponding bytecode file into the memory of the virtual machine, and runs the bytecode file.
设备***在***了监控字节码的字节码被运行时,根据监控字节码中插件的标识,可以建立插件与***了监控字节码的字节码对应的资源函数之间的对应关系。When the bytecode with the monitoring bytecode inserted into the device system is run, according to the plug-in identifier in the monitoring bytecode, the corresponding relationship between the plug-in and the resource function corresponding to the bytecode inserted with the monitoring bytecode can be established. .
例如可以是,在***中建立一张关系表,记录插件与资源函数的对应关系。For example, a relationship table may be established in the system to record the corresponding relationship between plug-ins and resource functions.
由于在插件运行过程中,资源函数消耗的资源是可以获取的,因此通过每个插件与资源函数的对应关系,以及每个资源函数消耗的资源,可以较为容易的得到每个插件所消耗的资源。Since the resources consumed by the resource function can be obtained during the operation of the plug-in, the resources consumed by each plug-in can be easily obtained through the corresponding relationship between each plug-in and the resource function, as well as the resources consumed by each resource function. .
在获取每个插件所消耗的资源后,一方面,当存在过度申请虚拟机资源或占用虚拟机资源的插件,可以根据每个插件消耗的资源,从多个插件中判断出过度申请虚拟机资源或占用虚拟机资源的插件;另一方面,以插件为粒度,可以对虚拟机的资源进行精细化的控制和管理。After obtaining the resources consumed by each plug-in, on the one hand, when there are plug-ins that excessively apply for virtual machine resources or occupy virtual machine resources, you can judge the excessive application of virtual machine resources from multiple plug-ins according to the resources consumed by each plug-in. Or plug-ins that occupy virtual machine resources; on the other hand, with plug-ins as granularity, the resources of virtual machines can be finely controlled and managed.
在一些实施方式中,资源函数包括线程创建函数,线程创建函数用于创建插件线程。In some implementations, the resource function includes a thread creation function that is used to create a plug-in thread.
在一些实施方式中,参照图4,确定字节码文件对应的资源函数消耗的资源为插件消耗的资源(S103),包括步骤S1033和/或S1034。In some embodiments, referring to FIG. 4 , it is determined that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in ( S103 ), including steps S1033 and/or S1034 .
在步骤S1033,统计字节码文件对应的线程创建函数创建的插件线程占用的中央处理器时间,以所有插件线程占用的中央处理器时间之和作为插件占用的中央处理器时间。In step S1033, count the CPU time occupied by the plug-in thread created by the thread creation function corresponding to the bytecode file, and use the sum of the CPU time occupied by all plug-in threads as the CPU time occupied by the plug-in.
在步骤S1034,统计字节码文件对应的线程创建函数创建的插件线程的数量,以插件线程的数量作为插件消耗的线程数量。In step S1034, the number of plug-in threads created by the thread creation function corresponding to the bytecode file is counted, and the number of plug-in threads is taken as the number of threads consumed by the plug-in.
设备***在线程创建函数对应的字节码被运行时,根据监控字节码中插件的标识,可以确定插件与线程创建函数创建的线程之间的对应关系。When the bytecode corresponding to the thread creation function is executed, the device system can determine the correspondence between the plug-in and the thread created by the thread creation function according to the plug-in identifier in the monitoring bytecode.
其中,线程创建函数(或者说线程构造函数)是用于创建线程的函数,创建线程的方式有多种,如可以通过扩展线程类创建线程。Among them, the thread creation function (or the thread constructor) is a function for creating a thread, and there are many ways to create a thread, for example, a thread can be created by extending a thread class.
线程是插件运行的执行单元,每个线程都有区别于其他线程的ID,多个线程组成一个进程,这组成一个进程的多个线程共享该进程的全部资源。A thread is the execution unit of the plug-in. Each thread has an ID that is different from other threads. Multiple threads form a process, and multiple threads that form a process share all the resources of the process.
确定插件与线程创建函数创建的线程之间的对应关系,例如可以是建立插件线程的ID与插件ID的对应关系。The corresponding relationship between the plug-in and the thread created by the thread creation function is determined, for example, the corresponding relationship between the ID of the plug-in thread and the plug-in ID can be established.
在插件的运行过程中,线程以及线程消耗的资源是可以获取的,因此通过每个插件与线程的对应关系,以及每个线程消耗的资源,可以较为容易的得到每个插件所消耗的资源。During the operation of the plug-in, the thread and the resources consumed by the thread can be obtained. Therefore, through the corresponding relationship between each plug-in and the thread, as well as the resources consumed by each thread, the resources consumed by each plug-in can be easily obtained.
示例性地,设备***在创建插件与线程的对应关系后,通过统计一个插件对应的所有线程占用的CPU时间来计算该插件占用的CPU时间。例如可以是,以一个插件对应的所有线程所占用的CPU时间之和作为该插件占用的CPU时间。Exemplarily, after creating the corresponding relationship between the plug-in and the thread, the device system calculates the CPU time occupied by the plug-in by counting the CPU time occupied by all threads corresponding to the plug-in. For example, the sum of the CPU time occupied by all threads corresponding to a plug-in may be used as the CPU time occupied by the plug-in.
设备***在建立插件与线程的对应关系后,通过统计一个插件对应的所有线程数量获取该插件消耗的线程数量。After establishing the correspondence between plug-ins and threads, the device system obtains the number of threads consumed by a plug-in by counting the number of all threads corresponding to a plug-in.
在一些实施方式中,资源函数包括入口函数,入口函数包括启动函数和停止函数。In some embodiments, the resource function includes an entry function, and the entry function includes a start function and a stop function.
在一些实施方式中,参照图5,确定字节码文件对应的资源函数消耗的资源为插件消耗的资源(S103),包括:S1035、统计每个插件对象消耗的内存空间,以所有插件对象消耗的内存空间之和作为插件消耗的内存空间,插件对象为字节码文件对应的启动函数和停止函数运行过程中创建的对象。In some embodiments, referring to FIG. 5 , it is determined that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in ( S103 ), including: S1035 , counting the memory space consumed by each plug-in object, and using all plug-in objects to consume The sum of the memory space of the plug-in is used as the memory space consumed by the plug-in, and the plug-in object is the object created during the operation of the start function and stop function corresponding to the bytecode file.
设备***在启动函数和停止函数对应的字节码被运行时,根据监控字节码中插件的标识,建立插件与插件对象之间的对应关系。When the bytecodes corresponding to the start function and the stop function are run, the device system establishes the correspondence between the plug-in and the plug-in object according to the plug-in identifier in the monitoring bytecode.
其中,每个插件只有一个启动函数,作为插件运行的开始,一个停止函数,作为插件运行的结束。从启动函数开始运行到停止函数运行结束的过程中,创建的对象都是插件对象。Among them, each plug-in has only one start function, which is the start of the plug-in operation, and one stop function, which is the end of the plug-in operation. During the process from the start of the start function to the end of the stop function, the objects created are all plug-in objects.
因此,在将监控字节码***启动函数和停止函数对应的字节码 时,需要将监控字节码被***在,启动函数和停止函数的起始处和结束处对应的字节码在字节码文件中的位置处,以便监测插件从开始运行到结束运行创建的所有插件对象,建立插件对象与插件的对应关系。Therefore, when the monitoring bytecode is inserted into the bytecode corresponding to the start function and the stop function, the monitoring bytecode needs to be inserted in the bytecode corresponding to the start and end of the start function and the stop function in the word The location in the section code file, in order to monitor all the plug-in objects created by the plug-in from the beginning to the end of the operation, and establish the corresponding relationship between the plug-in objects and the plug-ins.
设备***在创建插件与插件对象的对应关系后,通过统计一个插件对应的所有插件对象消耗的内存空间来计算该插件消耗的内存空间。例如可以是,以一个插件对应的所有插件对象所消耗的内存空间之和作为该插件消耗的内存空间。After creating the correspondence between the plug-in and the plug-in object, the device system calculates the memory space consumed by the plug-in by counting the memory space consumed by all plug-in objects corresponding to a plug-in. For example, the sum of the memory space consumed by all plug-in objects corresponding to a plug-in may be used as the memory space consumed by the plug-in.
在一些实施方式中,参照图6,确定字节码文件对应的资源函数消耗的资源为插件消耗的资源(S103)之后,所述方法还包括:S104、根据插件消耗的资源,对插件进行控制。In some embodiments, referring to FIG. 6 , after determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in (S103), the method further includes: S104, controlling the plug-in according to the resources consumed by the plug-in .
根据资源函数消耗的资源(如线程、CPU时间、内存空间等),计算得到每个插件消耗的资源,根据每个插件消耗的资源,对所有插件进行控制。According to the resources consumed by the resource function (such as threads, CPU time, memory space, etc.), the resources consumed by each plug-in are calculated, and all plug-ins are controlled according to the resources consumed by each plug-in.
示例性地,对插件进行控制,可以是:根据插件在插件运行过程中可能消耗的资源,计算每个插件的资源消耗风险等级,当插件在插件运行过程中可能消耗大量资源,则该插件的资源消耗风险等级为高;相反,当插件在插件运行过程中可能消耗的资源量较小,则该插件的资源消耗风险等级为低。Exemplarily, controlling the plug-in may be: calculating the resource consumption risk level of each plug-in according to the resources that the plug-in may consume during the plug-in running process. When the plug-in may consume a large amount of resources during the plug-in running process, the The resource consumption risk level is high; on the contrary, when the amount of resources that the plug-in may consume during the plug-in running process is small, the resource consumption risk level of the plug-in is low.
示例性地,可以按照插件的类型对插件进行分类,如将插件分为***插件(OSGi框架使用的插件)、预置插件(设备业务所必需的插件)、开放插件(设备业务可能需要的插件),生成插件分类文件,在插件分类文件中记录每个插件的分类信息,如插件名称、插件版本号、插件类型(***插件、预置插件、开放插件中的一个)以及插件的资源消耗风险等级、插件功能描述等。Exemplarily, plug-ins can be classified according to their types, for example, plug-ins are divided into system plug-ins (plug-ins used by the OSGi framework), preset plug-ins (plug-ins necessary for device services), and open plug-ins (plug-ins that may be required by device services). ), generate a plug-in classification file, and record the classification information of each plug-in in the plug-in classification file, such as plug-in name, plug-in version number, plug-in type (one of system plug-ins, preset plug-ins, and open plug-ins), and plug-in resource consumption risk level, description of plug-in functions, etc.
在插件运行过程中,读取插件分类文件中插件的分类信息,将资源消耗风险等级为高风险和中风险的插件作为重点监控对象,通过Linux(一种操作***)安全控制技术,如Cgroup(Control Groups,控制群组)技术对其进行控制。During the plug-in running process, the plug-in classification information in the plug-in classification file is read, and plug-ins whose resource consumption risk levels are high and medium risk are regarded as key monitoring objects. Control Groups) technology to control it.
示例性地,对插件进行控制,也可以是:设定单个插件的资源消 耗阈值,如对插件的占用的CPU时间、消耗的内存和消耗的线程数量设定阈值,当某个插件消耗的资源超过设定的阈值,则对该插件进行控制。Exemplarily, controlling the plug-in may also be: setting a resource consumption threshold of a single plug-in, such as setting thresholds for the CPU time occupied by the plug-in, the consumed memory and the number of threads consumed, when the resources consumed by a plug-in are If the set threshold is exceeded, the plug-in is controlled.
示例性地,可以通过在资源消耗配置文件中设定Bundle.Resource.CPU.Threshold,设定插件占用的CPU时间的阈值;通过在资源消耗配置文件中设定Bundle.Resource.Memory.Threshold,设定插件消耗的内存的阈值;通过在资源消耗配置文件中设定Bundle.Resource.Thread.Threshold,设定插件消耗的线程数量的阈值。Exemplarily, by setting Bundle.Resource.CPU.Threshold in the resource consumption configuration file, the threshold of the CPU time occupied by the plug-in can be set; by setting Bundle.Resource.Memory.Threshold in the resource consumption configuration file, set Set the threshold of memory consumed by the plug-in; set the threshold of the number of threads consumed by the plug-in by setting Bundle.Resource.Thread.Threshold in the resource consumption configuration file.
在插件的运行过程中,读取资源消耗配置文件中设定的阈值,将其是否对插件进行控制的判断依据。当个插件消耗的资源超过设定的阈值,则通过Linux安全控制技术对该插件进行控制。During the running process of the plug-in, read the threshold value set in the resource consumption configuration file, and use it as the basis for judging whether to control the plug-in. When the resources consumed by a plug-in exceed the set threshold, the plug-in is controlled by the Linux security control technology.
示例性地,对插件进行控制,还可以是:统计每个插件的资源消耗值,并将其记录存储至插件资源消耗表中,根据插件资源消耗表中每个插件对应的数据,计算JAVA虚拟机下每个插件消耗的每种资源的历史平均值,并将计算得到的历史平均值作为对插件进行控制的判断依据。Exemplarily, to control the plug-in, it can also be: count the resource consumption value of each plug-in, and store the records in the plug-in resource consumption table, and calculate the JAVA virtual value according to the data corresponding to each plug-in in the plug-in resource consumption table. The historical average value of each resource consumed by each plug-in under the computer, and the calculated historical average value is used as the judgment basis for plug-in control.
在一些实施方式中,插件为基于开放服务网关协议运行的插件。In some implementations, the plug-in is a plug-in that operates based on the Open Services Gateway Protocol.
本公开实施方式的基础软件框架,例如可以是OSGi框架。The basic software framework of the embodiments of the present disclosure may be, for example, an OSGi framework.
OSGi框架在对插件进行部署时,使用插件动态部署技术,相比于传统的插件静态部署技术,动态部署具有轻量、灵活的特点。When the OSGi framework deploys the plug-in, it uses the plug-in dynamic deployment technology. Compared with the traditional plug-in static deployment technology, the dynamic deployment has the characteristics of light weight and flexibility.
基于OSGi框架,本公开实施方式的方法可以包括步骤A01至A04。Based on the OSGi framework, the method of the embodiment of the present disclosure may include steps A01 to A04.
在步骤A01,在JAVA虚拟机启动插件对应的类的类加载之前,通过JavaAgent类库对类加载过程进行拦截,从缓存目录中获取与插件对应的字节码文件。In step A01, before the JAVA virtual machine starts the class loading of the class corresponding to the plug-in, the class loading process is intercepted by the JavaAgent class library, and the bytecode file corresponding to the plug-in is obtained from the cache directory.
在步骤A02,通过JavaSsist类库对获取的字节码文件进行分析与编辑。In step A02, the acquired bytecode file is analyzed and edited through the JavaSsist class library.
利用JavaSsist对字节码文件中字节码进行分析,判断字节码对应的函数是否为该插件的启动函数或停止函数,如果是,则在插件的 启动函数或停止函数的开始和结束位置对应的字节码在字节码文件中的位置处***监控字节码字,监控字节码可以为插件ID;同时也判断字节码对应的函数是否是线程创建函数,如果是,则在线程创建函数对应的字节码在字节码文件中的位置处***监控字节码字,监控字节码可以为插件ID。Use JavaSsist to analyze the bytecode in the bytecode file to determine whether the function corresponding to the bytecode is the start function or stop function of the plug-in. If so, it corresponds to the start and end positions of the start function or stop function of the plug-in Insert the monitoring bytecode word at the position in the bytecode file. The monitoring bytecode can be the plug-in ID; at the same time, it is also judged whether the function corresponding to the bytecode is a thread creation function. The bytecode corresponding to the creation function inserts the monitoring bytecode word at the position in the bytecode file, and the monitoring bytecode can be the plug-in ID.
在步骤A03,进行类加载过程,运行***监控字节码的字节码文件,根据监控字节码,在JAVA虚拟机内部建立插件与线程对应关系的关系表,用来记录插件与线程的对应关系。In step A03, the class loading process is performed, the bytecode file inserted into the monitoring bytecode is run, and according to the monitoring bytecode, a relationship table of the correspondence between the plug-in and the thread is established in the JAVA virtual machine to record the correspondence between the plug-in and the thread relation.
通过定义JAVA扩展类Javax.Bundle.ResourceInfo和JNI(Java Native Interface,JAVA本地接口)的实现插件消耗的资源的统计与计算,通过定义Javax.Bundle.CPUUsage类提供获取计算得到的插件消耗的资源的接口,如定义getBundleID函数,其为获取插件ID的接口;定义getCPUTime函数,其为获取插件占用的CPU时间的接口。By defining the JAVA extension class Javax.Bundle.ResourceInfo and JNI (Java Native Interface, JAVA native interface) to implement the statistics and calculation of the resources consumed by the plug-in, and by defining the Javax.Bundle.CPUUsage class, it provides a method to obtain the calculated resources consumed by the plug-in. Interfaces, such as defining the getBundleID function, which is an interface for obtaining the plug-in ID; and defining the getCPUTime function, which is an interface for obtaining the CPU time occupied by the plug-in.
其中,统计并计算插件占用的CPU时间的方法为:在JAVA虚拟机的所有线程启动时都设置该线程的起始时间,当需要统计并计算插件占用的CPU时间时,通过JAVA虚拟机的JNI获取当前运行的所有线程,计算每个正在运行的线程最近的占用CPU的时间点与其起始时间的差值,以获取该线程的占用的CPU时间,将正在运行的线程中与插件对应的线程占用的CPU时间进行累加计算得到插件占用的CPU时间。Among them, the method of counting and calculating the CPU time occupied by the plug-in is as follows: when all threads of the JAVA virtual machine are started, the start time of the thread is set, and when the CPU time occupied by the plug-in needs to be counted and calculated, the JNI of the JAVA virtual machine Get all currently running threads, calculate the difference between the most recent CPU occupied time point of each running thread and its starting time, to obtain the occupied CPU time of the thread, and assign the thread corresponding to the plug-in among the running threads The occupied CPU time is accumulated and calculated to obtain the CPU time occupied by the plug-in.
在步骤A04,通过调用接口获取插件消耗的资源的数据,对获取的数据进行数据处理加工后记录到设备内部日志文件中,或打印至界面。In step A04, the data of the resources consumed by the plug-in is acquired by calling the interface, and the acquired data is processed and recorded in the internal log file of the device, or printed to the interface.
基于OSGi框架,本公开实施方式的插件资源管理方法的步骤S104,即根据插件消耗的资源,对插件进行控制,还可以包括步骤B01至B04。Based on the OSGi framework, step S104 of the plug-in resource management method according to the embodiment of the present disclosure, that is, controlling the plug-in according to the resources consumed by the plug-in, may further include steps B01 to B04.
在步骤B01,获取在OSGi框架下运行的插件,通过调用OSGi服务接口获取正在运行的插件的名称。In step B01, a plug-in running under the OSGi framework is obtained, and the name of the running plug-in is obtained by calling the OSGi service interface.
在步骤B02,根据插件分类文件依次判断每个插件的资源消耗 风险等级,若存在插件的资源消耗风险等级为高风险或中风险,属于需要对该插件进行精细化控制。In step B02, according to the plug-in classification file, the resource consumption risk level of each plug-in is judged in turn. If the resource consumption risk level of the plug-in is high risk or medium risk, it belongs to the need for refined control of the plug-in.
在步骤B03,周期性更新需要精细化控制的插件的资源消耗数据,计算JAVA虚拟机下该插件每个周期内的占用的CPU时间,判断该插件占用的CPU时间是否在持续T个(例如可以是5个)周期内大于设定的阈值。In step B03, periodically update the resource consumption data of the plug-in that needs refined control, calculate the CPU time occupied by the plug-in in each cycle under the JAVA virtual machine, and determine whether the CPU time occupied by the plug-in continues for T (for example, you can is greater than the set threshold for 5) cycles.
在步骤B04,如果是,则依据插件与线程的对应关系,获取与该插件对应的所有正在运行的线程,并将这些线程的ID作为控制参数进行设定,限制这些线程执行时占用的CPU时间。In step B04, if yes, then according to the corresponding relationship between the plug-in and the thread, obtain all the running threads corresponding to the plug-in, and set the IDs of these threads as control parameters to limit the CPU time occupied by these threads during execution .
第二方面,参照图7,本公开提供一种插件资源管理的装置,其包括:读取模块,配置为读取与插件对应的字节码文件;***模块,配置为在字节码文件的资源消耗位置***监控字节码,资源消耗位置为,在运行过程中需要消耗资源的资源函数对应的字节码在字节码文件中的位置,监控字节码用于标识插件的字节码。In a second aspect, referring to FIG. 7 , the present disclosure provides an apparatus for managing plug-in resources, which includes: a reading module configured to read a bytecode file corresponding to the plug-in; an inserting module configured to The resource consumption position is inserted into the monitoring bytecode. The resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process. The monitoring bytecode is used to identify the bytecode of the plug-in .
本公开实施方式的插件资源管理的装置中,在插件对应的类进行类加载之前,在插件对应的字节码文件的资源消耗位置***监控字节码,通过监控字节码,在插件对应的类进行类加载的过程中,将资源函数与插件建立对应关系。一方面,在类加载之前***监控字节码,在类加载过程中建立资源函数与插件的对应关系,对原有的类加载过程影响较小,易于实现;另一方面,通过资源函数与插件的对应关系以及资源函数消耗的资源,可以获取每个插件消耗的资源,从而实现对资源以及插件的精细化控制与管理,提升设备运行稳定性、可靠性和安全性。In the plug-in resource management device according to the embodiment of the present disclosure, before the class corresponding to the plug-in is loaded, the monitoring bytecode is inserted into the resource consumption position of the bytecode file corresponding to the plug-in, and the In the process of class loading, the corresponding relationship between resource functions and plug-ins is established. On the one hand, the monitoring bytecode is inserted before class loading, and the corresponding relationship between resource functions and plug-ins is established during the class loading process, which has little impact on the original class loading process and is easy to implement; on the other hand, through resource functions and plug-ins You can obtain the resources consumed by each plug-in, so as to realize the refined control and management of resources and plug-ins, and improve the stability, reliability and security of device operation.
第三方面,参照图8,本公开提供一种电子设备,其包括:一个或多个处理器,存储器,其上存储有一个或多个程序,当一个或多个程序被一个或多个处理器执行时,使得一个或多个处理器实现上述任意一项的插件资源管理的方法;一个或多个I/O接口,连接在处理器与存储器之间,配置为实现处理器与存储器的信息交互。In a third aspect, referring to FIG. 8 , the present disclosure provides an electronic device comprising: one or more processors, and a memory having one or more programs stored thereon, when the one or more programs are processed by one or more When the processor is executed, one or more processors are made to implement any one of the above plug-in resource management methods; one or more I/O interfaces are connected between the processor and the memory and are configured to realize the information between the processor and the memory interact.
其中,处理器为具有数据处理能力的器件,其包括但不限于中央处理器(CPU)等;存储器为具有数据存储能力的器件,其包括但不限于随机存取存储器(RAM,更具体如SDRAM、DDR等)、只读存储器(ROM)、带电可擦可编程只读存储器(EEPROM)、闪存(FLASH);I/O接口(读写接口)连接在处理器于存储器间,用于实现存储器与处理器的信息交互,其包括但不限于数据总线(Bus)等。Wherein, the processor is a device with data processing capability, which includes but is not limited to a central processing unit (CPU), etc.; the memory is a device with data storage capability, which includes but is not limited to random access memory (RAM, more specifically such as SDRAM) , DDR, etc.), read-only memory (ROM), electrified erasable programmable read-only memory (EEPROM), flash memory (FLASH); I/O interface (read and write interface) is connected between the processor and the memory to realize the memory Information interaction with the processor, including but not limited to a data bus (Bus) and the like.
第四方面,参照图9,本公开提供一种计算机可读介质,其上存储有计算机程序,计算机程序被处理器执行时实现上述任意一种插件资源管理的方法。In a fourth aspect, referring to FIG. 9 , the present disclosure provides a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, any one of the above plug-in resource management methods is implemented.
其中,处理器为具有数据处理能力的器件,其包括但不限于中央处理器(CPU)等;存储器为具有数据存储能力的器件,其包括但不限于随机存取存储器(RAM,更具体如SDRAM、DDR等)、只读存储器(ROM)、带电可擦可编程只读存储器(EEPROM)、闪存(FLASH);I/O接口(读写接口)连接在处理器与存储器间,能实现存储器与处理器的信息交互,其包括但不限于数据总线(Bus)等。Wherein, the processor is a device with data processing capability, which includes but is not limited to a central processing unit (CPU), etc.; the memory is a device with data storage capability, which includes but is not limited to random access memory (RAM, more specifically such as SDRAM) , DDR, etc.), read-only memory (ROM), electrified erasable programmable read-only memory (EEPROM), flash memory (FLASH); I/O interface (read and write interface) is connected between the processor and the memory, which can realize the memory and the memory. The information exchange of the processor, which includes but is not limited to the data bus (Bus) and the like.
本领域普通技术人员可以理解,上文中所公开的全部或某些步骤、***、装置中的功能模块/单元可以被实施为软件、固件、硬件及其适当的组合。Those of ordinary skill in the art can understand that all or some of the steps, systems, and functional modules/units in the apparatus disclosed above can be implemented as software, firmware, hardware, and appropriate combinations thereof.
在硬件实施方式中,在以上描述中提及的功能模块/单元之间的划分不一定对应于物理组件的划分;例如,一个物理组件可以具有多个功能,或者一个功能或步骤可以由若干物理组件合作执行。In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be composed of several physical components Components execute cooperatively.
某些物理组件或所有物理组件可以被实施为由处理器,如中央处理器(CPU)、数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质(或非暂时性介质)和通信介质(或暂时性介质)。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息(诸如计算机可读指令、数据结构、程序模块或其他数据)的任何方法或技术 中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于随机存取存储器(RAM,更具体如SDRAM、DDR等)、只读存储器(ROM)、带电可擦可编程只读存储器(EEPROM)、闪存(FLASH)或其他磁盘存储器;只读光盘(CD-ROM)、数字多功能盘(DVD)或其他光盘存储器;磁盒、磁带、磁盘存储或其他磁存储器;可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit (CPU), digital signal processor or microprocessor, or as hardware, or as an integrated circuit such as Application-specific integrated circuits. Such software may be distributed on computer-readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). As is known to those of ordinary skill in the art, the term computer storage media includes both volatile and nonvolatile implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data flexible, removable and non-removable media. Computer storage media include, but are not limited to, random access memory (RAM, more specifically SDRAM, DDR, etc.), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory (FLASH), or other disk storage ; compact disc read only (CD-ROM), digital versatile disk (DVD), or other optical disk storage; magnetic cartridge, tape, magnetic disk storage or other magnetic storage; any other storage that can be used to store desired information and that can be accessed by a computer medium. In addition, communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and can include any information delivery media, as is well known to those of ordinary skill in the art .
本公开已经公开了示例实施方式,并且虽然采用了具体术语,但它们仅用于并仅应当被解释为一般说明性含义,并且不用于限制的目的。在一些实例中,对本领域技术人员显而易见的是,除非另外明确指出,否则可单独使用与特定实施方式相结合描述的特征、特性和/或元素,或可与其他实施方式相结合描述的特征、特性和/或元件组合使用。因此,本领域技术人员将理解,在不脱离由所附的权利要求阐明的本公开的范围的情况下,可进行各种形式和细节上的改变。This disclosure has disclosed example embodiments, and although specific terms have been employed, they are used and should only be construed in a general descriptive sense and not for purposes of limitation. In some instances, it will be apparent to those skilled in the art that features, characteristics and/or elements described in connection with a particular embodiment may be used alone or in combination with other embodiments, unless expressly stated otherwise. Features and/or elements are used in combination. Accordingly, it will be understood by those of ordinary skill in the art that various changes in form and details may be made therein without departing from the scope of the present disclosure as set forth in the appended claims.

Claims (14)

  1. 一种插件资源管理的方法,包括:A method for plug-in resource management, comprising:
    读取与插件对应的字节码文件;Read the bytecode file corresponding to the plugin;
    在所述字节码文件的资源消耗位置***监控字节码,所述资源消耗位置为,在运行过程中需要消耗资源的资源函数对应的字节码在所述字节码文件中的位置,所述监控字节码用于标识所述插件的字节码。Insert monitoring bytecode in the resource consumption position of the bytecode file, where the resource consumption position is the position in the bytecode file of the bytecode corresponding to the resource function that needs to consume resources during the running process, The monitoring bytecode is used to identify the bytecode of the plug-in.
  2. 根据权利要求1所述的方法,其中,所述在所述字节码文件的资源消耗位置***监控字节码之后,所述方法还包括:The method according to claim 1, wherein after the monitoring bytecode is inserted in the resource consumption position of the bytecode file, the method further comprises:
    确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源。It is determined that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in.
  3. 根据权利要求2所述的方法,其中,所述确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源,包括:The method according to claim 2, wherein the determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in comprises:
    根据所述监控字节码建立所述资源函数与所述插件的对应关系;Establish a corresponding relationship between the resource function and the plug-in according to the monitoring bytecode;
    根据所述对应关系,确定所述插件对应的资源函数,并确定所述插件对应的资源函数消耗的资源为所述插件消耗的资源。According to the corresponding relationship, the resource function corresponding to the plug-in is determined, and it is determined that the resource consumed by the resource function corresponding to the plug-in is the resource consumed by the plug-in.
  4. 根据权利要求2所述的方法,其中,所述资源函数包括线程创建函数,所述线程创建函数用于创建插件线程。The method of claim 2, wherein the resource function includes a thread creation function for creating a plug-in thread.
  5. 根据权利要求4所述的方法,其中,所述确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源,包括:The method according to claim 4, wherein the determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in comprises:
    统计所述字节码文件对应的线程创建函数创建的插件线程占用的中央处理器时间,以所有所述插件线程占用的中央处理器时间之和作为所述插件占用的中央处理器时间。The CPU time occupied by the plug-in thread created by the thread creation function corresponding to the bytecode file is counted, and the sum of the CPU time occupied by all the plug-in threads is used as the CPU time occupied by the plug-in.
  6. 根据权利要求4所述的方法,其中,所述确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源,包括:The method according to claim 4, wherein the determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in comprises:
    统计所述字节码文件对应的线程创建函数创建的插件线程的数量,以所述插件线程的数量作为所述插件消耗的线程数量。The number of plug-in threads created by the thread creation function corresponding to the bytecode file is counted, and the number of plug-in threads is taken as the number of threads consumed by the plug-in.
  7. 根据权利要求4所述的方法,其中,所述确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源,包括:The method according to claim 4, wherein the determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in comprises:
    统计所述字节码文件对应的线程创建函数创建的插件线程占用的中央处理器时间,以所有所述插件线程占用的中央处理器时间之和作为所述插件占用的中央处理器时间;并且Counting the CPU time occupied by the plug-in thread created by the thread creation function corresponding to the bytecode file, and taking the sum of the CPU time occupied by all the plug-in threads as the CPU time occupied by the plug-in; and
    统计所述字节码文件对应的线程创建函数创建的插件线程的数量,以所述插件线程的数量作为所述插件消耗的线程数量。The number of plug-in threads created by the thread creation function corresponding to the bytecode file is counted, and the number of plug-in threads is taken as the number of threads consumed by the plug-in.
  8. 根据权利要求2所述的方法,其中,所述资源函数包括入口函数,所述入口函数包括启动函数和停止函数。The method of claim 2, wherein the resource function includes an entry function, and the entry function includes a start function and a stop function.
  9. 根据权利要求8所述的方法,其中,所述确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源,包括:The method according to claim 8, wherein the determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in comprises:
    统计每个插件对象消耗的内存空间,以所有所述插件对象消耗的内存空间之和作为所述插件消耗的内存空间,所述插件对象为所述字节码文件对应的启动函数和停止函数运行过程中创建的对象。Count the memory space consumed by each plug-in object, and use the sum of the memory space consumed by all the plug-in objects as the memory space consumed by the plug-in. The plug-in object is the start function and stop function corresponding to the bytecode file. objects created during the process.
  10. 根据权利要求2所述的方法,其中,所述确定所述字节码文件对应的资源函数消耗的资源为所述插件消耗的资源之后,所述方法还包括:The method according to claim 2, wherein after determining that the resource consumed by the resource function corresponding to the bytecode file is the resource consumed by the plug-in, the method further comprises:
    根据所述插件消耗的资源,对所述插件进行控制。The plug-in is controlled according to the resources consumed by the plug-in.
  11. 根据权利要求1所述的方法,其中,所述插件为基于开放服务网关协议运行的插件。The method according to claim 1, wherein the plug-in is a plug-in running based on the Open Services Gateway Protocol.
  12. 一种插件资源管理的装置,包括:An apparatus for managing plug-in resources, comprising:
    读取模块,配置为读取与插件对应的字节码文件;Read module, configured to read the bytecode file corresponding to the plugin;
    ***模块,配置为在所述字节码文件的资源消耗位置***监控字节码,所述资源消耗位置为,在运行过程中需要消耗资源的资源函数对应的字节码在所述字节码文件中的位置,所述监控字节码用于标识所述插件的字节码。The insertion module is configured to insert the monitoring bytecode in the resource consumption position of the bytecode file, where the resource consumption position is that the bytecode corresponding to the resource function that needs to consume resources during the running process is in the bytecode The location in the file where the monitoring bytecode is used to identify the plug-in's bytecode.
  13. 一种电子设备,包括:An electronic device comprising:
    一个或多个处理器;one or more processors;
    存储器,其上存储有一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行时,使得所述一个或多个处理器实现权利要求1至11中任意一项所述的插件资源管理的方法;a memory having stored thereon one or more programs which, when executed by the one or more processors, cause the one or more processors to implement any one of claims 1 to 11 The method for plug-in resource management described in item;
    一个或多个I/O接口,连接在所述处理器与存储器之间,配置为 实现所述处理器与存储器的信息交互。One or more I/O interfaces, connected between the processor and the memory, are configured to realize the information interaction between the processor and the memory.
  14. 一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现根据权利要求1至11中任意一项所述的插件资源管理的方法。A computer-readable medium on which a computer program is stored, and when the program is executed by a processor, implements the plug-in resource management method according to any one of claims 1 to 11.
PCT/CN2021/128229 2020-11-10 2021-11-02 Plug-in resource management method and apparatus, and electronic device and computer-readable storage medium WO2022100485A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011249572.5A CN114461482A (en) 2020-11-10 2020-11-10 Method and device for managing plug-in resource, electronic equipment and computer readable medium
CN202011249572.5 2020-11-10

Publications (1)

Publication Number Publication Date
WO2022100485A1 true WO2022100485A1 (en) 2022-05-19

Family

ID=81403958

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/128229 WO2022100485A1 (en) 2020-11-10 2021-11-02 Plug-in resource management method and apparatus, and electronic device and computer-readable storage medium

Country Status (2)

Country Link
CN (1) CN114461482A (en)
WO (1) WO2022100485A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060156072A1 (en) * 2004-01-10 2006-07-13 Prakash Khot System and method for monitoring a computer apparatus
CN104346148A (en) * 2013-07-30 2015-02-11 阿里巴巴集团控股有限公司 Method, device and system for acquiring program performance consumption information
US20160117236A1 (en) * 2014-10-23 2016-04-28 Canon Kabushiki Kaisha Information processing apparatus, method for controlling the same, and non-transitory computer-readable medium
CN110134400A (en) * 2019-04-02 2019-08-16 北京奇艺世纪科技有限公司 Data capture method, device, electronic equipment and computer readable storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060156072A1 (en) * 2004-01-10 2006-07-13 Prakash Khot System and method for monitoring a computer apparatus
CN104346148A (en) * 2013-07-30 2015-02-11 阿里巴巴集团控股有限公司 Method, device and system for acquiring program performance consumption information
US20160117236A1 (en) * 2014-10-23 2016-04-28 Canon Kabushiki Kaisha Information processing apparatus, method for controlling the same, and non-transitory computer-readable medium
CN110134400A (en) * 2019-04-02 2019-08-16 北京奇艺世纪科技有限公司 Data capture method, device, electronic equipment and computer readable storage medium

Also Published As

Publication number Publication date
CN114461482A (en) 2022-05-10

Similar Documents

Publication Publication Date Title
US9274798B2 (en) Multi-threaded logging
KR101116615B1 (en) Resource management system and method for applications and threads in JAVA Virtual Machine
US20070240134A1 (en) Software packaging model supporting multiple entity types
US9213562B2 (en) Garbage collection safepoint system using non-blocking asynchronous I/O call to copy data when the garbage collection safepoint is not in progress or is completed
US8918776B2 (en) Self-adapting software system
JP2005276192A (en) Method and apparatus for increasing data storage capacity
US10747638B2 (en) Computing memory health metrics
TW201820131A (en) Process management method and apparatus
CN108509215B (en) System software replacing method and device, terminal equipment and storage medium
US20040060043A1 (en) Method and apparatus for instrumentation ON/OFF
WO2022095844A1 (en) Elastic block service mounting method and apparatus thereof
WO2014082583A1 (en) Method and device for generating dynamic partition information in nand flash memory
CN110515795A (en) A kind of monitoring method of big data component, device, electronic equipment
JP2021530756A (en) Methods and devices for representing activation frames for poseless garbage collection
WO2022100485A1 (en) Plug-in resource management method and apparatus, and electronic device and computer-readable storage medium
US9047180B2 (en) Computing system, method and computer-readable medium processing debug information in computing system
US10545909B2 (en) Computing system management using shared memory
CN112559565A (en) Abnormity detection method, system and device
CN110535724B (en) Application program network read-write limiting method and device, electronic equipment and storage medium
CN114610243B (en) Method, system, storage medium and equipment for converting thin volume
US10817204B1 (en) Migration of versioned data between storage devices
US20230100110A1 (en) Computing resource management method, electronic equipment and program product
CN115017062A (en) Method, system, device and medium for optimizing terminal memory
CN105511918B (en) A kind of data memory format automatic maintenance method of intelligent electric energy meter
CN115309421A (en) Static variable synchronization method, device, equipment and storage medium of single-point system

Legal Events

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

Ref document number: 21891012

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21891012

Country of ref document: EP

Kind code of ref document: A1