JavaScript memory visualization analysis and management method, system, device and storage medium
By parsing and running JavaScript code, generating abstract syntax trees and recording execution context stack and heap memory snapshots, rendering memory usage in real time and drawing call relationship diagrams, solving the complexity of JavaScript code memory analysis, reducing development costs and increasing code quality.
Patent Information
- Application Number
- CN202110798605.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-16
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2041-07-16
AI Technical Summary
In the prior art, the memory analysis of JavaScript code depends on the browser, and the operation is complex and not intuitive, which increases the technical requirements and learning costs of front-end developers.
By parsing JavaScript object code, generating abstract syntax trees and variable scopes, running the code to record execution context stack and heap memory snapshots, rendering memory usage in real time, and drawing call relationship diagrams, providing memory leak warnings and optimization suggestions.
Reduces the learning and labor costs of JavaScript developers for code performance analysis and optimization, and improves code quality and performance management capabilities.
Smart Images

Figure CN113688189B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data analysis and management, and in particular relates to a JavaScript memory visualization analysis and management method, system, device and storage medium. Background Art
[0002] JavaScript, abbreviated as JS, is an interpreted scripting language. It is a dynamically typed, weakly typed, prototype-based language with built-in type support. Its interpreter, called the JavaScript engine, is part of the browser and is widely used as a client-side scripting language. It was first used on HTML (an application of the Standard Generalized Markup Language) web pages to add dynamic functionality to HTML pages.
[0003] In the current front-end development landscape, runtime memory analysis of JavaScript code relies heavily on the browser (some browsers don't offer this feature). This is complex and unintuitive, requiring JavaScript developers to manually analyze and locate problematic code. This places high demands on the technical skills of these front-end developers. Most junior and mid-level developers don't pay attention to code performance when implementing their company's business code, leading to security and quality risks. JavaScript code performance analysis is also expensive to learn, and the labor cost of optimizing performance is also high. Summary of the Invention
[0004] To address the aforementioned technical issues, the present invention proposes a JavaScript memory visualization analysis and management method, system, device, and storage medium. This method provides an effective and convenient way to visualize and analyze issues like memory leaks, reducing the learning and labor costs for JavaScript developers performing code performance analysis and optimization. This facilitates front-end development teams to comprehensively control code performance and improve code quality.
[0005] To achieve the above object, the present invention adopts the following technical solutions:
[0006] The JavaScript memory visualization analysis and management method includes the following steps:
[0007] Parse JavaScript target code and generate corresponding abstract syntax tree and variable scope;
[0008] Run the JavaScript target code and record the execution context stack and heap memory snapshot information during the code running process;
[0009] According to the abstract syntax tree, execution context stack and heap memory snapshot information, the JavaScript heap memory usage is rendered in real time, and a call relationship diagram between variable nodes in the scope is drawn.
[0010] Furthermore, when parsing the JavaScript target code and generating the corresponding abstract syntax tree and variable scope, it also includes statically analyzing the JavaScript target code based on a common memory leak tracking library and marking problem scopes that may cause leaks.
[0011] Furthermore, the method also includes providing optimization suggestions for the JavaScript target code based on the results of the static analysis of the JavaScript target code.
[0012] Furthermore, the method also includes: automatically updating the common memory leak tracking library according to the self-learning method, and automatically identifying memory leak problems based on the updated common memory leak tracking library, and issuing corresponding warning information and locating problem nodes.
[0013] Furthermore, the specific process of running the JavaScript target code and recording the execution context stack and heap memory snapshot information during the code running process is:
[0014] Running the JavaScript target code, recording a heap memory snapshot of the problem scope and a heap memory snapshot of the non-problem scope;
[0015] Record the execution context stack and heap memory snapshot information during code execution; if the memory is normal, update the memory snapshot information regularly; if the memory is abnormal, continue to record the memory snapshot information at fixed time intervals;
[0016] Monitor and record system-level monitoring information and garbage collection mechanism during code execution.
[0017] Furthermore, the specific process of rendering the JavaScript heap memory usage in real time and drawing the call relationship graph between variable nodes in the scope according to the abstract syntax tree, execution context stack and heap memory snapshot information is as follows:
[0018] Based on the abstract syntax tree and execution context stack, draw a call relationship graph between variable nodes in the scope and mark the garbage collection status;
[0019] In the call relationship graph, identifying the memory health status of the node;
[0020] The JavaScript memory data at the target moment is rendered according to the heap memory snapshot information, and a visual chart of indicators such as system-level memory is rendered in real time.
[0021] Furthermore, in the call relationship graph, the method for identifying the memory health status of a node is:
[0022] Gray is used to indicate that the variable node has gone through the complete memory life cycle;
[0023] Yellow indicates that the variable node is still referenced and alive in memory;
[0024] Red is used to represent free variable nodes.
[0025] The present invention also proposes a JavaScript memory visualization analysis and management system, including a code pre-parsing device, a data acquisition device, and a visualization rendering device;
[0026] The code pre-parsing device is used to parse JavaScript target code and generate corresponding abstract syntax trees and variable scopes;
[0027] The data acquisition device is used to run the JavaScript target code and record the execution context stack and heap memory snapshot information during the code running process;
[0028] The visualization rendering device is used to render the JavaScript heap memory usage in real time based on the abstract syntax tree, execution context stack and heap memory snapshot information, and draw a call relationship diagram between variable nodes in the scope.
[0029] The present invention also provides a device comprising:
[0030] memory for storing computer programs;
[0031] A processor is configured to implement the method steps when executing the computer program.
[0032] The present invention also provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method steps are implemented.
[0033] The effects provided in the summary of the invention are only the effects of the embodiments, not all the effects of the invention. One of the above technical solutions has the following advantages or beneficial effects:
[0034] The present invention proposes a JavaScript memory visualization analysis and management method, system, device and storage medium, which includes parsing JavaScript target code, generating a corresponding abstract syntax tree and variable scope; running JavaScript target code, recording the execution context stack and heap memory snapshot information during the code running process; based on the abstract syntax tree, execution context stack and heap memory snapshot information, rendering the JavaScript heap memory occupancy in real time, and drawing a call relationship diagram between variable nodes in the scope. It also includes statically analyzing the JavaScript target code based on a common memory leak tracking library, marking the problem scope that may cause leaks, automatically updating the common memory leak tracking library based on a self-learning method, and automatically identifying memory leak problems based on the updated common memory leak tracking library, and issuing corresponding warning information and locating problem nodes. On the one hand, the present invention can render the memory monitoring data of the JavaScript code in real time and save the heap memory snapshot. On the other hand, it can draw the execution context stack (call stack) relationship diagram of the JavaScript code and identify the problem node and its call path, so that JavaScript developers can simply and clearly understand the underlying operations performed during the code execution process and visually track the changes in memory occupancy. By pre-parsing JavaScript code, collecting and recording heap memory snapshots and execution context stacks when the code is running, a convenient and effective way for JavaScript developers to visually analyze memory leaks and other problems is provided, which reduces the learning and labor costs of JavaScript developers for code performance analysis and optimization, and is beneficial for the front-end development team to control the overall code performance and improve code quality. At the same time, the present invention continuously updates the common memory problem library through self-learning algorithms, which is beneficial to the technology and experience accumulation of the company's development team.
[0035] Based on the JavaScript memory visualization analysis and management method, a JavaScript memory visualization analysis and management system, device, and storage medium are also proposed. They also have the functions of the above method and are not described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] like Figure 1 This is a flowchart of the JavaScript memory visualization analysis and management method according to Example 1 of the present invention;
[0037] like Figure 2 This is a schematic diagram of the JavaScript stack memory in Example 1 of the present invention;
[0038] like Figure 3 This is a schematic diagram of the JavaScript memory visualization analysis and management system according to embodiment 2 of the present invention. DETAILED DESCRIPTION
[0039] In order to clearly illustrate the technical features of this solution, the present invention is described in detail below through specific implementation methods and in conjunction with the accompanying drawings. The disclosure below provides many different embodiments or examples for realizing different structures of the present invention. In order to simplify the disclosure of the present invention, the components and settings of specific examples are described below. In addition, the present invention may repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplicity and clarity and does not itself indicate the relationship between the various embodiments and / or settings discussed. It should be noted that the components illustrated in the accompanying drawings are not necessarily drawn to scale. The present invention omits descriptions of well-known components and processing technologies and processes to avoid unnecessary limitations on the present invention.
[0040] Example 1
[0041] Example 1 of the present invention proposes a JavaScript memory visualization analysis and management method. On the one hand, it can render the memory monitoring data of the JavaScript code in real time and save the heap memory snapshot. On the other hand, it can draw the execution context stack (call stack) relationship diagram of the JavaScript code and identify the problem node and its call path, so that JavaScript developers can simply and clearly understand the underlying operations performed during the code execution process and visually track the changes in memory usage.
[0042] like Figure 1 A roadmap of the JavaScript memory visualization analysis and management method according to embodiment 1 of the present invention is provided;
[0043] In step S101, the JavaScript target code is parsed to generate the corresponding abstract syntax tree and variable scope;
[0044] In this step, the JavaScript code is first lexically analyzed and parsed to generate the corresponding AST abstract syntax tree, variable scope, and function scope chain.
[0045] Among them, the Abstract Syntax Tree (AST) is an abstract representation of the grammatical structure of the source code. It represents the grammatical structure of the programming language in the form of a tree, and each node on the tree represents a structure in the source code.
[0046] Based on the common memory leak tracking library, static analysis of JavaScript target code is performed to mark the problem scopes that may cause leaks for subsequent analysis and tracking.
[0047] In step S102, the JavaScript target code is executed, and the execution context stack and heap memory snapshot information are recorded during the code execution process. The JavaScript code is executed, and heap memory snapshots of the problem scope or other target scopes focused on by the code pre-parsing device are recorded according to the developer's needs. Simultaneously, during the JavaScript code execution process, the corresponding ECS execution context stack is recorded to facilitate observing the call depth of the target scope and tracking the reference relationships of the target node.
[0048] The Execution Context Stack (ECS), also known as the Call Stack, stores all execution contexts created during code execution, using a LIFO (last in, first out) approach. When code is run, a global execution context is created and pushed to the bottom of the stack. Each time a function call occurs, a corresponding execution context is created and pushed onto the Call Stack. When the function call ends, the execution context at the top of the Call Stack is destroyed, and control of the context is transferred to the new execution context at the top of the Call Stack.
[0049] The execution process of this step is:
[0050] Run the JavaScript target code and record a heap memory snapshot of the problem scope and a heap memory snapshot of the non-problem scope;
[0051] Record the execution context stack during code execution and pay attention to memory changes during execution context changes, so as to track the reference relationships of nodes later;
[0052] Record heap memory snapshot information during code execution; if the memory is normal, update the memory snapshot information regularly; if the memory is abnormal, continue to record memory snapshot information at fixed time intervals;
[0053] Monitor and record system-level monitoring information and garbage collection mechanism status during code execution, facilitating comparative analysis of memory status. System-level monitoring information includes indicators such as system memory and CPU usage.
[0054] In step S103, the JavaScript heap memory usage is rendered in real time based on the abstract syntax tree, execution context stack, and heap memory snapshot information, and a call relationship diagram between variable nodes in the scope is drawn.
[0055] The visualization rendering device loads the heap memory snapshot information stored by the data acquisition device, as well as the AST abstract syntax tree and ECS scope chain, and renders the JavaScript heap memory usage in real time, draws the call relationship diagram between the variable nodes in the scope, and marks the garbage collection path and problem nodes. Figure 2This is a schematic diagram of the JavaScript stack memory in Example 1 of the present invention; JavaScript data types are divided into basic data types and reference data types, where basic types include Undefined, Null, Boolean, Number, String, and Symbol, and reference types include Object;
[0056] JavaScript memory space: JavaScript memory uses stack memory (Stack) and heap memory (Heap). Stack memory provides an environment for JavaScript code execution and stores basic data types; heap memory stores reference data types.
[0057] The specific implementation process of this step is: based on the abstract syntax tree and the execution context stack, draw a call relationship diagram between the variable nodes in the scope, and mark the garbage collection situation; garbage collection includes reference counting method and mark-sweep method.
[0058] In the call graph, identify the memory health status of the node. In the call graph, the method for identifying the memory health status of the node is:
[0059] Gray is used to indicate that the variable node has gone through the complete memory life cycle; the memory life cycle includes memory allocation, memory usage, and memory deallocation;
[0060] Yellow indicates that the variable node is still referenced and alive in memory;
[0061] Red is used to represent free variable nodes.
[0062] Renders JavaScript memory data at the target moment based on heap memory snapshot information, and renders real-time visualization charts of system-level memory and other metrics. Visualization charts include but are not limited to line charts, bar charts, and stack charts.
[0063] In step S104, the common memory leak tracking library is automatically updated according to the self-learning method, and memory leak problems are automatically identified based on the updated common memory leak tracking library. Corresponding warning information and problem node location are issued, that is, the scope and call path of the variable node are recorded, or code optimization suggestions are given based on the static analysis results. Memory leaks are caused by unused memory that is not released in time.
[0064] The JavaScript memory visualization analysis and management method proposed in the present invention provides JavaScript developers with a convenient and effective way to visualize and analyze memory leaks and other problems by pre-parsing JavaScript code, collecting and recording heap memory snapshots and execution context stacks during code runtime. It reduces the learning and labor costs of JavaScript developers for code performance analysis and optimization, and is beneficial for the front-end development team to control the overall code performance and improve code quality. At the same time, the present invention continuously updates the common memory problem library through a self-learning algorithm, which is beneficial to the company's development team's accumulation of technology and experience.
[0065] Example 2
[0066] Based on the JavaScript memory visualization analysis and management method proposed in Example 1 of the present invention, Example 2 of the present invention further proposes a JavaScript memory visualization analysis and management system, such as Figure 3 A schematic diagram of a JavaScript memory visualization analysis and management system according to embodiment 2 of the present invention is provided. The system includes a code pre-parsing device, a data acquisition device, and a visualization rendering device.
[0067] The code pre-parsing device is used to parse the JavaScript target code and generate the corresponding abstract syntax tree and variable scope;
[0068] The data acquisition device is used to run JavaScript target code and record the execution context stack and heap memory snapshot information during the code running process;
[0069] The visualization rendering device is used to render the JavaScript heap memory usage in real time based on the abstract syntax tree, execution context stack and heap memory snapshot information, and draw the call relationship diagram between variable nodes in the scope.
[0070] The system also includes a memory leak warning device, which is used to automatically update the common memory leak tracking library according to the self-learning method, and automatically identify memory leak problems based on the updated common memory leak tracking library, and issue corresponding warning information and locate problem nodes.
[0071] The code pre-parsing device implements the process of: performing lexical analysis and grammatical analysis on JavaScript code, generating the corresponding AST abstract syntax tree, variable scope and function scope chain.
[0072] Among them, the Abstract Syntax Tree (AST) is an abstract representation of the grammatical structure of the source code. It represents the grammatical structure of the programming language in the form of a tree, and each node on the tree represents a structure in the source code.
[0073] Based on the common memory leak tracking library, static analysis of JavaScript target code is performed to mark the problem scopes that may cause leaks for subsequent analysis and tracking.
[0074] The data collection device runs JavaScript code and, based on the developer's needs, records heap memory snapshots of the problem scope or other target scopes targeted by the code pre-parsing device. Simultaneously, during JavaScript code execution, the corresponding ECS execution context stack is recorded to facilitate observing the call depth of the target scope and tracking reference relationships of the target node.
[0075] The Execution Context Stack (ECS), also known as the Call Stack, stores all execution contexts created during code execution, using a LIFO (last in, first out) approach. When code is run, a global execution context is created and pushed to the bottom of the stack. Each time a function call occurs, a corresponding execution context is created and pushed onto the Call Stack. When the function call ends, the execution context at the top of the Call Stack is destroyed, and control of the context is transferred to the new execution context at the top of the Call Stack.
[0076] Run the JavaScript target code and record a heap memory snapshot of the problem scope and a heap memory snapshot of the non-problem scope;
[0077] Record the execution context stack during code execution and pay attention to memory changes during execution context changes, so as to track the reference relationships of nodes later;
[0078] Record heap memory snapshot information during code execution; if the memory is normal, update the memory snapshot information regularly; if the memory is abnormal, continue to record memory snapshot information at fixed time intervals;
[0079] Monitor and record system-level monitoring information and garbage collection mechanism status during code execution, facilitating comparative analysis of memory status. System-level monitoring information includes indicators such as system memory and CPU usage.
[0080] The visualization rendering device loads the heap memory snapshot information stored by the data acquisition device, as well as the AST abstract syntax tree and ECS scope chain, renders the JavaScript heap memory usage in real time, draws the call relationship diagram between the variable nodes in the scope, and marks the garbage collection path and problem nodes.
[0081] The specific implementation process of this module is as follows: based on the abstract syntax tree and execution context stack, it draws a call relationship graph between variable nodes in the scope and marks the garbage collection status;
[0082] In the call graph, identify the memory health status of the node. In the call graph, the method for identifying the memory health status of the node is:
[0083] Gray is used to indicate that the variable node has gone through the complete memory life cycle;
[0084] Yellow indicates that the variable node is still referenced and alive in memory;
[0085] Red is used to represent free variable nodes.
[0086] Renders JavaScript memory data at the target moment based on heap memory snapshot information, and renders real-time visualization charts of system-level memory and other metrics. Visualization charts include but are not limited to line charts, bar charts, and stack charts.
[0087] The specific implementation process of the memory leak warning device is: automatically updating the common memory leak tracking library according to the self-learning method, and automatically identifying memory leak problems based on the updated common memory leak tracking library, and issuing corresponding warning information and locating problem nodes, that is, recording the scope and call path of the variable node, etc., or giving code optimization suggestions based on the static analysis results.
[0088] Example 3
[0089] The present invention also proposes JavaScript memory visualization analysis and management, including:
[0090] memory for storing computer programs;
[0091] The processor is used to implement the following method steps when executing the computer program:
[0092] In step S101, the JavaScript target code is parsed to generate the corresponding abstract syntax tree and variable scope;
[0093] In this step, the JavaScript code is first lexically analyzed and parsed to generate the corresponding AST abstract syntax tree, variable scope, and function scope chain.
[0094] Among them, the Abstract Syntax Tree (AST) is an abstract representation of the grammatical structure of the source code. It represents the grammatical structure of the programming language in the form of a tree, and each node on the tree represents a structure in the source code.
[0095] Based on the common memory leak tracking library, static analysis of JavaScript target code is performed to mark the problem scopes that may cause leaks for subsequent analysis and tracking.
[0096] In step S102, the JavaScript target code is executed, and the execution context stack and heap memory snapshot information are recorded during the code execution process. The JavaScript code is executed, and heap memory snapshots of the problem scope or other target scopes focused on by the code pre-parsing device are recorded according to the developer's needs. Simultaneously, during the JavaScript code execution process, the corresponding ECS execution context stack is recorded to facilitate observing the call depth of the target scope and tracking the reference relationships of the target node.
[0097] The Execution Context Stack (ECS), also known as the Call Stack, stores all execution contexts created during code execution, using a LIFO (last in, first out) approach. When code is run, a global execution context is created and pushed to the bottom of the stack. Each time a function call occurs, a corresponding execution context is created and pushed onto the Call Stack. When the function call ends, the execution context at the top of the Call Stack is destroyed, and control of the context is transferred to the new execution context at the top of the Call Stack.
[0098] The execution process of this step is:
[0099] Running the JavaScript target code, recording a heap memory snapshot of the problem scope and a heap memory snapshot of the non-problem scope;
[0100] Record the execution context stack during code execution and pay attention to memory changes during execution context changes, so as to track the reference relationships of nodes later;
[0101] Record heap memory snapshot information during code execution; if the memory is normal, update the memory snapshot information regularly; if the memory is abnormal, continue to record memory snapshot information at fixed time intervals;
[0102] Monitor and record system-level monitoring information and garbage collection mechanism status during code execution, facilitating comparative analysis of memory status. System-level monitoring information includes indicators such as system memory and CPU usage.
[0103] In step S103, the JavaScript heap memory usage is rendered in real time based on the abstract syntax tree, execution context stack, and heap memory snapshot information, and a call relationship diagram between variable nodes in the scope is drawn.
[0104] The visualization rendering device loads the heap memory snapshot information stored by the data acquisition device, as well as the AST abstract syntax tree and ECS scope chain, renders the JavaScript heap memory usage in real time, draws the call relationship diagram between the variable nodes in the scope, and marks the garbage collection path and problem nodes.
[0105] The specific implementation process of this step is as follows: based on the abstract syntax tree and execution context stack, draw a call relationship graph between variable nodes in the scope and mark the garbage collection status;
[0106] In the call graph, identify the memory health status of the node. In the call graph, the method for identifying the memory health status of the node is:
[0107] Gray is used to indicate that the variable node has gone through the complete memory life cycle;
[0108] Yellow indicates that the variable node is still referenced and alive in memory;
[0109] Red is used to represent free variable nodes.
[0110] Renders JavaScript memory data at the target moment based on heap memory snapshot information, and renders real-time visualization charts of system-level memory and other metrics. Visualization charts include but are not limited to line charts, bar charts, and stack charts.
[0111] In step S104, the common memory leak tracking library is automatically updated according to the self-learning method, and the memory leak problem is automatically identified based on the updated common memory leak tracking library, and the corresponding warning information is issued and the problem node is located, that is, the scope and call path of the variable node are recorded, or code optimization suggestions are given according to the static analysis results.
[0112] It should be noted that the technical solution of the present invention also provides an electronic device, including: a communication interface, which can exchange information with other devices such as network devices; a processor, connected to the communication interface to realize information interaction with other devices, and used to execute the JavaScript memory visualization analysis and management method provided by one or more of the above technical solutions when running a computer program, and the computer program is stored on the memory. Of course, in actual application, the various components in the electronic device are coupled together through a bus system. It can be understood that the bus system is used to realize the connection and communication between these components. In addition to the data bus, the bus system also includes a power bus, a control bus and a status signal bus. The memory in the embodiment of the present application is used to store various types of data to support the operation of the electronic device. Examples of these data include: any computer program for operating on the electronic device. It can be understood that the memory can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disk, or compact disc read-only memory (CD-ROM); magnetic surface memory can be magnetic disk memory or magnetic tape memory. Volatile memory can be random access memory (RAM), which is used as an external cache.By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronized dynamic random access memory (SLDRAM), direct RAM bus random access memory (DRRAM). The memory described in the embodiments of the present application is intended to include but is not limited to these and any other suitable types of memory. The method disclosed in the above embodiments of the present application can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The above-mentioned processor can be a general-purpose processor, a DSP (Digital Signal Processing, i.e., a chip capable of implementing digital signal processing technology), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in a memory. The processor reads the program in the memory and completes the steps of the above method in combination with its hardware. When the processor executes the program, the corresponding processes in the various methods of the embodiments of the present application are implemented. For the sake of brevity, they are not described here.
[0113] Example 4
[0114] The present invention further provides a readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the following method steps are implemented:
[0115] In step S101, the JavaScript target code is parsed to generate the corresponding abstract syntax tree and variable scope;
[0116] In this step, the JavaScript code is first lexically analyzed and parsed to generate the corresponding AST abstract syntax tree, variable scope, and function scope chain.
[0117] Among them, the Abstract Syntax Tree (AST) is an abstract representation of the grammatical structure of the source code. It represents the grammatical structure of the programming language in the form of a tree, and each node on the tree represents a structure in the source code.
[0118] Based on the common memory leak tracking library, static analysis of JavaScript target code is performed to mark the problem scopes that may cause leaks for subsequent analysis and tracking.
[0119] In step S102, the JavaScript target code is executed, and the execution context stack and heap memory snapshot information are recorded during the code execution process. The JavaScript code is executed, and heap memory snapshots of the problem scope or other target scopes focused on by the code pre-parsing device are recorded according to the developer's needs. Simultaneously, during the JavaScript code execution process, the corresponding ECS execution context stack is recorded to facilitate observing the call depth of the target scope and tracking the reference relationships of the target node.
[0120] The Execution Context Stack (ECS), also known as the Call Stack, stores all execution contexts created during code execution, using a LIFO (last in, first out) approach. When code is run, a global execution context is created and pushed to the bottom of the stack. Each time a function call occurs, a corresponding execution context is created and pushed onto the Call Stack. When the function call ends, the execution context at the top of the Call Stack is destroyed, and control of the context is transferred to the new execution context at the top of the Call Stack.
[0121] The execution process of this step is:
[0122] Run the JavaScript target code and record a heap memory snapshot of the problem scope and a heap memory snapshot of the non-problem scope;
[0123] Record the execution context stack during code execution and pay attention to memory changes during execution context changes, so as to track the reference relationships of nodes later;
[0124] Record heap memory snapshot information during code execution; if the memory is normal, update the memory snapshot information regularly; if the memory is abnormal, continue to record memory snapshot information at fixed time intervals;
[0125] Monitor and record system-level monitoring information and garbage collection mechanism status during code execution, facilitating comparative analysis of memory status. System-level monitoring information includes indicators such as system memory and CPU usage.
[0126] In step S103, the JavaScript heap memory usage is rendered in real time based on the abstract syntax tree, execution context stack, and heap memory snapshot information, and a call relationship diagram between variable nodes in the scope is drawn.
[0127] The visualization rendering device loads the heap memory snapshot information stored by the data acquisition device, as well as the AST abstract syntax tree and ECS scope chain, renders the JavaScript heap memory usage in real time, draws the call relationship diagram between the variable nodes in the scope, and marks the garbage collection path and problem nodes.
[0128] The specific implementation process of this step is as follows: based on the abstract syntax tree and execution context stack, draw a call relationship graph between variable nodes in the scope and mark the garbage collection status;
[0129] In the call graph, identify the memory health status of the node. In the call graph, the method for identifying the memory health status of the node is:
[0130] Gray is used to indicate that the variable node has gone through the complete memory life cycle;
[0131] Yellow indicates that the variable node is still referenced and alive in memory;
[0132] Red is used to represent free variable nodes.
[0133] Renders JavaScript memory data at the target moment based on heap memory snapshot information, and renders real-time visualization charts of system-level memory and other metrics. Visualization charts include but are not limited to line charts, bar charts, and stack charts.
[0134] In step S104, the common memory leak tracking library is automatically updated according to the self-learning method, and the memory leak problem is automatically identified based on the updated common memory leak tracking library, and the corresponding warning information is issued and the problem node is located, that is, the scope and call path of the variable node are recorded, or code optimization suggestions are given according to the static analysis results.
[0135] For the description of the relevant parts of the device and storage medium for JavaScript memory visualization analysis and management provided in the embodiment of this application, please refer to the detailed description of the corresponding parts of the JavaScript memory visualization analysis and management method provided in Example 1 of this application, and will not be repeated here.
[0136] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device comprising a series of elements are inherent to the elements. In the absence of further restrictions, the elements limited by the statement "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device comprising the elements. In addition, the above-mentioned technical solutions provided in the embodiments of the present application are not described in detail in accordance with the corresponding technical solutions in the prior art to achieve the same principle, so as to avoid excessive elaboration.
[0137] Although the above description is of specific embodiments of the present invention in conjunction with the accompanying drawings, it does not limit the scope of protection of the present invention. For those skilled in the art, other different forms of modifications or variations can be made based on the above description. It is not necessary and impossible to list all embodiments here. Based on the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without expending creative effort are still within the scope of protection of the present invention.
Claims
1. JavaScript memory visualization analysis and management method, characterized in that: The following steps are involved: Parse JavaScript target code and generate corresponding abstract syntax tree and variable scope; Run the JavaScript target code and record the execution context stack and heap memory snapshot information during the code running process; The specific process of running the JavaScript target code and recording the execution context stack and heap memory snapshot information during the code running process is: running the JavaScript target code, recording the heap memory snapshot of the problem scope and recording the heap memory snapshot of the non-problem scope; Record the execution context stack and heap memory snapshot information during code execution; If the memory is normal, the memory snapshot information is updated regularly; If the memory is abnormal, continue to record memory snapshot information at fixed time intervals; Monitor and record system-level monitoring information and garbage collection mechanism during code execution; According to the abstract syntax tree, execution context stack and heap memory snapshot information, the JavaScript heap memory usage is rendered in real time, and a call relationship diagram between variable nodes in the scope is drawn; The specific process of rendering the JavaScript heap memory usage in real time and drawing the call relationship graph between the variable nodes in the scope according to the abstract syntax tree, execution context stack and heap memory snapshot information is as follows: drawing the call relationship graph between the variable nodes in the scope according to the abstract syntax tree and execution context stack, and marking the garbage collection situation; in the call relationship graph, identifying the memory health status of the node; The JavaScript memory data at the target time is rendered according to the heap memory snapshot information, and a visual chart of the system-level memory indicators is rendered in real time.
2. The JavaScript memory visualization analysis and management method according to claim 1 is characterized in that: When parsing the JavaScript target code and generating the corresponding abstract syntax tree and variable scope, the method also includes statically analyzing the JavaScript target code according to the memory leak tracking library and marking the problematic scopes that may cause leaks.
3. The JavaScript memory visualization analysis and management method according to claim 2 is characterized in that: The method also includes providing optimization suggestions for the JavaScript target code based on the results of the static analysis of the JavaScript target code.
4. The JavaScript memory visualization analysis and management method according to claim 2 is characterized in that: The method also includes: automatically updating the memory leak tracking library according to the self-learning method, and automatically identifying the memory leak problem according to the updated memory leak tracking library, and issuing corresponding warning information and locating the problem node.
5. The JavaScript memory visualization analysis and management method according to claim 1 is characterized in that: The method for identifying the memory health status of a node in the call relationship graph is: Gray is used to indicate that the variable node has gone through the complete memory life cycle; Yellow indicates that the variable node is still referenced and alive in memory; Free variable nodes are represented in red.
6. A JavaScript memory visualization analysis and management system, used to execute the JavaScript memory visualization analysis and management method according to any one of claims 1 to 5, characterized in that: It includes a code pre-analysis device, a data acquisition device, and a visualization rendering device; The code pre-parsing device is used to parse the JavaScript target code and generate the corresponding abstract syntax tree and variable scope; The data acquisition device is used to run the JavaScript target code and record the execution context stack and heap memory snapshot information during the code running process; The visualization rendering device is used to render the JavaScript heap memory occupancy in real time according to the abstract syntax tree, execution context stack and heap memory snapshot information, and draw a call relationship diagram between variable nodes in the scope.
7. JavaScript memory visualization analysis and management device, characterized by: include: Memory for storing computer programs; A processor, configured to implement the method steps as claimed in any one of claims 1 to 5 when executing the computer program.
8. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Method of achieving snapshot with electro-magnetic transient in DC system (EMTDC) simulation model based on data integrated access technique
CN103136407A
Environmental reconstruction based malicious-code integrity analysis method
CN104850786A
Method and device for generating heap memory snapshot file, medium and electronic equipment
CN111240801A
Code visualization analysis method and device based on abstract syntax
CN112306479A
Creating References in a Scoped Memory System
US20080294685A1
