[go: up one dir, main page]

CN113688189B - JavaScript memory visual analysis and management method, system, equipment and storage medium - Google Patents

JavaScript memory visual analysis and management method, system, equipment and storage medium Download PDF

Info

Publication number
CN113688189B
CN113688189B CN202110798605.XA CN202110798605A CN113688189B CN 113688189 B CN113688189 B CN 113688189B CN 202110798605 A CN202110798605 A CN 202110798605A CN 113688189 B CN113688189 B CN 113688189B
Authority
CN
China
Prior art keywords
memory
javascript
code
analysis
scope
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202110798605.XA
Other languages
Chinese (zh)
Other versions
CN113688189A (en
Inventor
贾少龙
符佳凤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Jinan data Technology Co ltd
Original Assignee
Inspur Jinan data Technology Co ltd
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 Inspur Jinan data Technology Co ltd filed Critical Inspur Jinan data Technology Co ltd
Priority to CN202110798605.XA priority Critical patent/CN113688189B/en
Publication of CN113688189A publication Critical patent/CN113688189A/en
Application granted granted Critical
Publication of CN113688189B publication Critical patent/CN113688189B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/285Clustering or classification
    • G06F16/287Visualization; Browsing
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • G06F11/3636Debugging of software by tracing the execution of the program
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/11File system administration, e.g. details of archiving or snapshots
    • G06F16/128Details of file system snapshots on the file-level, e.g. snapshot creation, administration, deletion
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Artificial Intelligence (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明提出了JavaScript内存可视化分析与管理方法、系统、设备和存储介质,该方法包括解析目标代码,生成相应的抽象语法树和变量的作用域;运行目标代码,记录代码运行过程中的执行上下文栈和堆内存快照信息;根据抽象语法树、执行上下文栈和堆内存快照信息,实时渲染堆内存占用情况,绘制作用域中变量节点间的调用关系图。还包括根据常见内存泄漏追踪库,对目标代码静态分析,标注有可能引发泄漏的问题作用域,基于该方法还提出了可视化分析与管理系统、设备和存储介质,本发明提供了一种便捷的可视化分析内存泄漏等问题的有效途径,降低了代码性能分析和优化的学习成本和人力成本,有利于前端开发团队对代码性能进行整体把控。

The present invention proposes a JavaScript memory visualization analysis and management method, system, device and storage medium. The method includes parsing the target code, generating a corresponding abstract syntax tree and the scope of variables; running the target code, recording the execution context stack and heap memory snapshot information during the code running process; according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, real-time rendering of the heap memory occupancy, and drawing a call relationship diagram between variable nodes in the scope. It also includes static analysis of the target code based on a common memory leak tracking library, marking the problem scope that may cause the leak. Based on this method, a visualization analysis and management system, device and storage medium are also proposed. The present invention provides an effective way to conveniently visualize and analyze memory leaks and other problems, reduces the learning cost and labor cost of code performance analysis and optimization, and is conducive to the front-end development team to control the code performance as a whole.

Description

JavaScript memory visual analysis and management method, system, equipment and storage medium
Technical Field
The invention belongs to the technical field of data analysis and management, and particularly relates to a method, a system, equipment and a storage medium for visual analysis and management of a JavaScript memory.
Background
JavaScript, abbreviated as JS, an transliteration scripting language, is a dynamic, weak, prototype-based language with built-in support types. Its interpreter is called JavaScript engine, which is a part of the browser, widely used in the scripting language of clients, and is used at the earliest on HTML (an application under standard universal markup language) web pages to add dynamic functions to HTML web pages.
In the current front-end development field, the runtime memory analysis of the JavaScript code is strongly dependent on a browser (part of the browser does not provide the function), the operation is complex and not intuitive enough, the JavaScript developer is required to manually operate and manually analyze and position the problem code, and the technical capability requirement on the front-end developer is high. Most of primary and middle level developers do not pay attention to code performance when realizing business codes of companies, so that potential safety and quality hazards exist in the codes, the learning cost of JavaScript code performance analysis is high, and the labor cost for performance optimization is high.
Disclosure of Invention
In order to solve the technical problems, the invention provides a method, a system, equipment and a storage medium for visual analysis and management of a JavaScript memory. The invention provides an effective way for conveniently and visually analyzing the problems of memory leakage and the like, reduces the learning cost and the labor cost of performance analysis and optimization of the code by JavaScript developers, and is beneficial to the front-end development team to control the code performance integrally and improve the code quality.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
The visual analysis and management method of the JavaScript memory comprises the following steps:
Analyzing the JavaScript object code to generate a corresponding abstract syntax tree and a scope of the variable;
Running the JavaScript object code, and recording the execution context stack and heap memory snapshot information in the code running process;
And rendering the occupation condition of the JavaScript heap memory in real time according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, and drawing a call relation diagram among variable nodes in the scope.
Further, when the JavaScript object code is analyzed to generate the corresponding abstract syntax tree and the scope of the variable, the JavaScript object code is statically analyzed according to a common memory leakage tracking library, and the scope of the problem that leakage is possibly caused is marked.
Further, the method further comprises the step of giving optimization suggestions of the JavaScript object code according to the result of static analysis of the JavaScript object code.
Furthermore, the method further comprises the steps of automatically updating the common memory leakage tracking library according to a self-learning method, automatically identifying memory leakage problems according to the updated common memory leakage tracking library, and sending corresponding early warning information and positioning problem nodes.
Further, the specific process of running the JavaScript object code and recording the execution context stack and heap memory snapshot information in the code running process is as follows:
Running the JavaScript object code, recording a heap memory snapshot of the problem action domain and recording a heap memory snapshot of the non-problem action domain;
Recording the execution context stack and heap memory snapshot information in the code running process, updating the memory snapshot information regularly if the memory is normal, and continuously recording the memory snapshot information at fixed time intervals if the memory is abnormal;
and monitoring and recording system-level monitoring information and garbage collection mechanism conditions in the code executing process.
Further, the specific process of rendering the call relation graph among the variable nodes in the scope according to the abstract syntax tree, the execution context stack and the heap memory snapshot information and rendering the JavaScript heap memory occupation condition in real time is as follows:
drawing a call relation diagram among variable nodes in the scope according to the abstract syntax tree and the execution upper and lower Wen Zhan, and marking a garbage recycling condition;
in the call relation diagram, the memory health state of the node is identified;
And rendering JavaScript memory data at a target moment according to the heap memory snapshot information, and rendering a visual chart of indexes such as a system level memory and the like in real time.
Further, in the call relation diagram, the method for identifying the memory health state of the node is as follows:
Gray is adopted to indicate that the variable node experiences a complete memory life cycle;
Yellow is adopted to indicate that the variable node still has references and is stored in the memory at present;
The free variable nodes are indicated by red.
The invention also provides a JavaScript memory visual analysis and management system, which comprises a code pre-analysis device, a data acquisition device and a visual rendering device;
the code pre-analysis device is used for analyzing the JavaScript object code and generating a corresponding abstract syntax tree and a scope of the variable;
The data acquisition device is used for running the JavaScript object code and recording the execution context stack and heap memory snapshot information in the code running process;
the visual rendering device is used for rendering the occupation condition of the JavaScript heap memory in real time according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, and drawing a call relation diagram among variable nodes in the scope.
The invention also proposes a device comprising:
a memory for storing a computer program;
and a processor for implementing method steps when executing the computer program.
The invention also proposes a readable storage medium on which a computer program is stored, which computer program when being executed by a processor realizes the method steps.
The effects provided in the summary of the invention are merely effects of embodiments, not all effects of the invention, and one of the above technical solutions has the following advantages or beneficial effects:
The invention provides a visual analysis and management method, a visual analysis and management system, visual analysis and management equipment for a JavaScript memory and a visual analysis and management storage medium for the JavaScript memory, wherein the visual analysis and management method comprises the steps of analyzing JavaScript object codes to generate corresponding abstract syntax trees and action fields of variables; and according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, rendering the occupation condition of the JavaScript heap memory in real time, and drawing a call relation diagram among variable nodes in the scope. The method also comprises the steps of statically analyzing the JavaScript object code according to the common memory leakage tracking library, marking a problem scope which is likely to cause leakage, automatically updating the common memory leakage tracking library according to a self-learning method, automatically identifying the memory leakage problem according to the updated common memory leakage tracking library, and sending corresponding early warning information and positioning problem nodes. The invention can render the memory monitoring data and save the heap memory snapshot when the JavaScript code runs in real time on the one hand, and can draw the relation diagram of the execution upper and lower Wen Zhan (call stack) of the JavaScript code and identify the problem node and the call path thereof on the other hand, so that JavaScript developers can simply and clearly know the bottom operation performed in the code execution process and visually track the change of the occupation condition of the memory. Through pre-analyzing the JavaScript code, collecting and recording heap memory snapshots and executing the upper and lower Wen Zhan when the code runs, an effective way for conveniently and visually analyzing the problems of memory leakage and the like is provided for JavaScript developers, the learning cost and the labor cost for the JavaScript developers to perform performance analysis and optimization on the code are reduced, the front-end development team is facilitated to integrally control the code performance, the code quality is improved, and meanwhile, the common memory problem library is continuously updated through a self-learning algorithm, and the technology and experience accumulation of the company development team are facilitated.
Based on the visual analysis and management method of the JavaScript memory, a visual analysis and management system of the JavaScript memory, a device and a storage medium are also provided. The method also has the functions of the method and is not described in detail herein.
Drawings
FIG. 1 is a flowchart of a method for visual analysis and management of a JavaScript memory according to embodiment 1 of the present invention;
FIG. 2 is a diagram of a memory stack of JavaScript of example 1;
fig. 3 is a schematic diagram of a JavaScript memory visual analysis and management system according to embodiment 2 of the present invention.
Detailed Description
In order to clearly illustrate the technical features of the present solution, the present invention will be described in detail below with reference to the following detailed description and the accompanying drawings. The following disclosure provides many different embodiments, or examples, for implementing different structures of the invention. In order to simplify the present disclosure, components and arrangements of specific examples are described below. Furthermore, the present invention may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed. It should be noted that the components illustrated in the figures are not necessarily drawn to scale. Descriptions of well-known components and processing techniques and processes are omitted so as to not unnecessarily obscure the present invention.
Example 1
The embodiment 1 of the invention provides a visual analysis and management method for a JavaScript memory, which can be used for rendering memory monitoring data and saving heap memory snapshots in real time when the JavaScript code runs, drawing a relation diagram of execution upper and lower Wen Zhan (call stack) of the JavaScript code, marking out problem nodes and call paths thereof, and enabling JavaScript developers to simply and clearly know the bottom operation performed in the code execution process and visually track the change of the occupation condition of the memory.
FIG. 1 is a path diagram of a visual analysis and management method for a JavaScript memory according to an embodiment 1 of the present invention;
in step S101, parsing the JavaScript object code to generate a corresponding abstract syntax tree and scope of the variable;
In the step, firstly, lexical analysis and grammar analysis are carried out on JavaScript codes, and corresponding AST abstract grammar trees, the scope of the variables and the scope chain of the functions are generated.
Wherein the Abstract Syntax Tree (AST) is an abstract representation of the syntax structure of the source code, which represents the syntax structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code.
According to a common memory leakage tracking library, the JavaScript object code is statically analyzed, and a problem scope which possibly causes leakage is marked for subsequent analysis and tracking.
In step S102, javaScript object code is run, and execution context stack and heap memory snapshot information in the code running process are recorded. And running JavaScript codes, and recording heap memory snapshots of a problem scope or other target scopes focused by a code preresolved device according to the requirements of developers. Meanwhile, in the execution process of the JavaScript code, the corresponding ECS execution upper and lower Wen Zhan are synchronously recorded so as to observe the call depth of the target scope and track the reference relation of the target node.
Wherein the execution context Wen Zhan (ECS), also called call stack, is used to store all execution contexts created during code execution, with the characteristics of LIFO (last in first out). And each time a function call occurs, a corresponding function execution context is created and pushed to a call stack, the execution context at the top of the call stack is destroyed and the control right of the context is transferred to the execution context at the top of a new call stack.
The execution process of the steps is as follows:
Running JavaScript object codes, recording heap memory snapshots of problem action domains and recording heap memory snapshots of non-problem action domains;
Recording execution context Wen Zhan in the code running process, focusing on memory change in the execution context changing process so as to follow up the reference relation of the tracking node;
Recording heap memory snapshot information in the code running process, updating the memory snapshot information regularly if the memory is normal, and continuously recording the memory snapshot information at fixed time intervals if the memory is abnormal;
And monitoring and recording system-level monitoring information and garbage collection mechanism conditions in the code execution process, so that the memory condition can be conveniently compared and analyzed. The system level monitoring information comprises indexes such as a system memory, CPU utilization rate and the like.
In step S103, according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, the JavaScript heap memory occupation situation is rendered in real time, and a call relation diagram between variable nodes in the scope is drawn.
The visual rendering device loads heap memory snapshot information stored by the data acquisition device, an AST abstract syntax tree and an ECS scope chain, renders the occupation condition of the JavaScript heap memory in real time, draws a call relation diagram among variable nodes in the scope and marks garbage collection paths and problem nodes. FIG. 2 is a schematic diagram of a memory stack of JavaScript data type of embodiment 1 of the invention, wherein the JavaScript data type is divided into a basic data type and a reference data type, the basic type comprises Undefined, null, boolean, number, string and Symbol, and the reference type comprises Object;
The JavaScript memory space comprises a JavaScript memory using Stack memory (Stack) and a Heap memory (Heap), wherein the Stack memory provides an environment for JavaScript code execution and stores basic data types, and the Heap memory stores reference data types.
The specific implementation process of the method comprises the steps of drawing a call relation diagram among variable nodes in a scope according to an abstract syntax tree and execution upper and lower Wen Zhan, and marking a garbage collection condition, wherein the garbage collection comprises a reference counting method and a mark clearing method.
In the call relation diagram, the memory health state of the node is identified, and in the call relation diagram, the method for identifying the memory health state of the node is as follows:
gray is adopted to indicate that the variable node experiences a complete memory life cycle, wherein the memory life cycle comprises memory allocation, memory use and memory recovery;
Yellow is adopted to indicate that the variable node still has references and is stored in the memory at present;
The free variable nodes are indicated by red.
And rendering JavaScript memory data at the target moment according to the heap memory snapshot information, and rendering a visual chart of indexes such as a system level memory and the like in real time. Wherein the visualization graphs include, but are not limited to, line graphs, bar graphs, and stack graphs.
In step S104, the common memory leakage tracking library is automatically updated according to the self-learning method, the memory leakage problem is automatically identified according to the updated common memory leakage tracking library, and corresponding early warning information and positioning problem nodes are sent out, namely, the scope and calling path of the variable nodes are recorded, or code optimization suggestions are given according to the static analysis result. The memory leakage is a memory which is not used any more, and is not released in time, so that the memory leakage is caused;
According to the visual analysis and management method for the JavaScript memory, through pre-analyzing the JavaScript code, collecting and recording the heap memory snapshot and executing the upper and lower Wen Zhan when the code runs, an effective way for conveniently and visually analyzing the problems of memory leakage and the like is provided for JavaScript developers, the learning cost and the labor cost for the JavaScript developers to perform performance analysis and optimization on the code are reduced, the front-end development team is facilitated to integrally control the code performance, the code quality is improved, and meanwhile, the common memory problem library is continuously updated through a self-learning algorithm, and the technology and experience accumulation of the company development team are facilitated.
Example 2
Based on the visual analysis and management method of the JavaScript memory provided by the embodiment 1 of the present invention, the embodiment 2 of the present invention also provides a visual analysis and management system of the JavaScript memory, as shown in fig. 3, a schematic diagram of the visual analysis and management system of the JavaScript memory provided by the embodiment 2 of the present invention is provided, and the system comprises a code pre-analysis device, a data acquisition device and a visual rendering device;
The code pre-analysis device is used for analyzing the JavaScript object code to generate a corresponding abstract syntax tree and a scope of the variable;
The data acquisition device is used for running JavaScript object codes and recording execution context stacks and heap memory snapshot information in the code running process;
The visual rendering device is used for rendering the occupation condition of the JavaScript heap memory in real time according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, and drawing a call relation diagram among variable nodes in the scope.
The system also comprises a memory leakage early warning device, wherein the memory leakage early warning device is used for automatically updating a common memory leakage tracking library according to a self-learning method, automatically identifying a memory leakage problem according to the updated common memory leakage tracking library, and sending out corresponding early warning information and positioning problem nodes.
The code pre-analysis device is used for performing lexical analysis and grammar analysis on the JavaScript code to generate a corresponding AST abstract grammar tree, a scope of a variable and a scope chain of a function.
Wherein the Abstract Syntax Tree (AST) is an abstract representation of the syntax structure of the source code, which represents the syntax structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code.
According to a common memory leakage tracking library, the JavaScript object code is statically analyzed, and a problem scope which possibly causes leakage is marked for subsequent analysis and tracking.
The data acquisition device is used for running JavaScript codes, and recording heap memory snapshots of a problem acting domain or other target acting domains focused by the code pre-analysis device according to the requirements of developers. Meanwhile, in the execution process of the JavaScript code, the corresponding ECS execution upper and lower Wen Zhan are synchronously recorded so as to observe the call depth of the target scope and track the reference relation of the target node.
Wherein the execution context Wen Zhan (ECS), also called call stack, is used to store all execution contexts created during code execution, with the characteristics of LIFO (last in first out). And each time a function call occurs, a corresponding function execution context is created and pushed to a call stack, the execution context at the top of the call stack is destroyed and the control right of the context is transferred to the execution context at the top of a new call stack.
Running JavaScript object codes, recording heap memory snapshots of problem action domains and recording heap memory snapshots of non-problem action domains;
Recording execution context Wen Zhan in the code running process, focusing on memory change in the execution context changing process so as to follow up the reference relation of the tracking node;
Recording heap memory snapshot information in the code running process, updating the memory snapshot information regularly if the memory is normal, and continuously recording the memory snapshot information at fixed time intervals if the memory is abnormal;
And monitoring and recording system-level monitoring information and garbage collection mechanism conditions in the code execution process, so that the memory condition can be conveniently compared and analyzed. The system level monitoring information comprises indexes such as a system memory, CPU utilization rate and the like.
The visual rendering device loads heap memory snapshot information stored by the data acquisition device, an AST abstract syntax tree and an ECS scope chain, renders the occupation condition of the JavaScript heap memory in real time, draws a call relation diagram among variable nodes in the scope and marks garbage collection paths and problem nodes.
Drawing a call relation diagram among variable nodes in a scope according to an abstract syntax tree and execution upper and lower Wen Zhan, and marking garbage recycling conditions;
in the call relation diagram, the memory health state of the node is identified, and in the call relation diagram, the method for identifying the memory health state of the node is as follows:
Gray is adopted to indicate that the variable node experiences a complete memory life cycle;
Yellow is adopted to indicate that the variable node still has references and is stored in the memory at present;
The free variable nodes are indicated by red.
And rendering JavaScript memory data at the target moment according to the heap memory snapshot information, and rendering a visual chart of indexes such as a system level memory and the like in real time. Wherein the visualization graphs include, but are not limited to, line graphs, bar graphs, and stack graphs.
The memory leakage early warning device comprises the specific implementation processes of automatically updating a common memory leakage tracking library according to a self-learning method, automatically identifying a memory leakage problem according to the updated common memory leakage tracking library, and sending out corresponding early warning information and positioning problem nodes, namely recording the action scope, the calling path and the like of variable nodes, or giving out code optimization suggestions according to a static analysis result.
Example 3
The invention also provides visual analysis and management of the JavaScript memory, which comprises the following steps:
a memory for storing a computer program;
The processor is used for realizing the following steps when executing the computer program:
in step S101, parsing the JavaScript object code to generate a corresponding abstract syntax tree and scope of the variable;
In the step, firstly, lexical analysis and grammar analysis are carried out on JavaScript codes, and corresponding AST abstract grammar trees, the scope of the variables and the scope chain of the functions are generated.
Wherein the Abstract Syntax Tree (AST) is an abstract representation of the syntax structure of the source code, which represents the syntax structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code.
According to a common memory leakage tracking library, the JavaScript object code is statically analyzed, and a problem scope which possibly causes leakage is marked for subsequent analysis and tracking.
In step S102, javaScript object code is run, and execution context stack and heap memory snapshot information in the code running process are recorded. And running JavaScript codes, and recording heap memory snapshots of a problem scope or other target scopes focused by a code preresolved device according to the requirements of developers. Meanwhile, in the execution process of the JavaScript code, the corresponding ECS execution upper and lower Wen Zhan are synchronously recorded so as to observe the call depth of the target scope and track the reference relation of the target node.
Wherein the execution context Wen Zhan (ECS), also called call stack, is used to store all execution contexts created during code execution, with the characteristics of LIFO (last in first out). And each time a function call occurs, a corresponding function execution context is created and pushed to a call stack, the execution context at the top of the call stack is destroyed and the control right of the context is transferred to the execution context at the top of a new call stack.
The execution process of the steps is as follows:
Running the JavaScript object code, recording a heap memory snapshot of the problem action domain and recording a heap memory snapshot of the non-problem action domain;
Recording execution context Wen Zhan in the code running process, focusing on memory change in the execution context changing process so as to follow up the reference relation of the tracking node;
Recording heap memory snapshot information in the code running process, updating the memory snapshot information regularly if the memory is normal, and continuously recording the memory snapshot information at fixed time intervals if the memory is abnormal;
And monitoring and recording system-level monitoring information and garbage collection mechanism conditions in the code execution process, so that the memory condition can be conveniently compared and analyzed. The system level monitoring information comprises indexes such as a system memory, CPU utilization rate and the like.
In step S103, according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, the JavaScript heap memory occupation situation is rendered in real time, and a call relation diagram between variable nodes in the scope is drawn.
The visual rendering device loads heap memory snapshot information stored by the data acquisition device, an AST abstract syntax tree and an ECS scope chain, renders the occupation condition of the JavaScript heap memory in real time, draws a call relation diagram among variable nodes in the scope and marks garbage collection paths and problem nodes.
Drawing a call relation diagram among variable nodes in a scope according to an abstract syntax tree and execution upper and lower Wen Zhan, and marking garbage recycling conditions;
in the call relation diagram, the memory health state of the node is identified, and in the call relation diagram, the method for identifying the memory health state of the node is as follows:
Gray is adopted to indicate that the variable node experiences a complete memory life cycle;
Yellow is adopted to indicate that the variable node still has references and is stored in the memory at present;
The free variable nodes are indicated by red.
And rendering JavaScript memory data at the target moment according to the heap memory snapshot information, and rendering a visual chart of indexes such as a system level memory and the like in real time. Wherein the visualization graphs include, but are not limited to, line graphs, bar graphs, and stack graphs.
In step S104, the common memory leakage tracking library is automatically updated according to the self-learning method, the memory leakage problem is automatically identified according to the updated common memory leakage tracking library, and corresponding early warning information and positioning problem nodes are sent out, namely, the scope and calling path of the variable nodes are recorded, or code optimization suggestions are given according to the static analysis result.
It should be noted that the technical scheme of the application also provides electronic equipment, which comprises a communication interface capable of carrying out information interaction with other equipment such as network equipment and the like, and a processor connected with the communication interface so as to realize information interaction with other equipment, wherein the processor is used for executing the visual analysis and management method of the JavaScript memory provided by one or more technical schemes when running a computer program, and the computer program is stored on a memory. Of course, in practice, the various components in the electronic device are coupled together by a bus system. It will be appreciated that a bus system is used to enable connected communications between these components. The bus system includes a power bus, a control bus, and a status signal bus in addition to the data bus. The memory in the embodiments of the present application is used to store various types of data to support the operation of the electronic device. Examples of such data include any computer program for operating on an electronic device. It will be appreciated that the memory can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. The non-volatile Memory may be, among other things, a Read Only Memory (ROM), a programmable Read Only Memory (PROM, programmable Read-Only Memory), erasable programmable Read-Only Memory (EPROM, erasable Programmable Read-Only Memory), electrically erasable programmable Read-Only Memory (EEPROM, ELECTRICALLY ERASABLE PROGRAMMABLE READ-Only Memory), magnetic random access Memory (FRAM, ferromagnetic random access Memory), flash Memory (Flash Memory), magnetic surface Memory, optical disk, or compact disk-Only Memory (CD-ROM, compact Disc Read-Only Memory), which may be disk Memory or tape Memory. the volatile memory may be random access memory (RAM, random AccessMemory) which acts as external cache memory. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM, static Random Access Memory), synchronous static random access memory (SSRAM, synchronous Static Random Access Memory), dynamic random access memory (DRAM, dynamic Random Access Memory), synchronous dynamic random access memory (SDRAM, synchronousDynamic Random Access Memory), and so forth, double data rate synchronous dynamic random access memory (DDRSDRAM, double Data Rate Synchronous Dynamic Random Access Memory), enhanced synchronous dynamic random access memory (ESDRAM, enhanced Synchronous Dynamic Random Access Memory), synchronous link dynamic random access memory (SLDRAM, syncLink Dynamic Random Access Memory), direct memory bus random access memory (DRRAM, direct Rambus Random Access Memory). The memory described by embodiments of the present application is intended to comprise, without being limited to, these and any other suitable types of memory. The method disclosed by the embodiment of the application can be applied to a processor or realized by the processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or by instructions in the form of software. The processor may be a general purpose processor, a DSP (DIGITAL SIGNAL Processing, i.e., a chip capable of implementing digital signal Processing techniques), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiment of the application can be directly embodied in the hardware of the decoding processor or can be implemented by combining hardware and software modules in the decoding processor. The software modules may be located in a storage medium having a memory, and the processor reads the program in the memory and performs the steps of the method in combination with its hardware. The corresponding flow in each method of the embodiments of the present application is implemented when the processor executes the program, and for brevity, will not be described in detail herein.
Example 4
The invention also provides a readable storage medium, the readable storage medium stores a computer program, and the computer program when executed by a processor realizes the following steps:
in step S101, parsing the JavaScript object code to generate a corresponding abstract syntax tree and scope of the variable;
In the step, firstly, lexical analysis and grammar analysis are carried out on JavaScript codes, and corresponding AST abstract grammar trees, the scope of the variables and the scope chain of the functions are generated.
Wherein the Abstract Syntax Tree (AST) is an abstract representation of the syntax structure of the source code, which represents the syntax structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code.
According to a common memory leakage tracking library, the JavaScript object code is statically analyzed, and a problem scope which possibly causes leakage is marked for subsequent analysis and tracking.
In step S102, javaScript object code is run, and execution context stack and heap memory snapshot information in the code running process are recorded. And running JavaScript codes, and recording heap memory snapshots of a problem scope or other target scopes focused by a code preresolved device according to the requirements of developers. Meanwhile, in the execution process of the JavaScript code, the corresponding ECS execution upper and lower Wen Zhan are synchronously recorded so as to observe the call depth of the target scope and track the reference relation of the target node.
Wherein the execution context Wen Zhan (ECS), also called call stack, is used to store all execution contexts created during code execution, with the characteristics of LIFO (last in first out). And each time a function call occurs, a corresponding function execution context is created and pushed to a call stack, the execution context at the top of the call stack is destroyed and the control right of the context is transferred to the execution context at the top of a new call stack.
The execution process of the steps is as follows:
Running JavaScript object codes, recording heap memory snapshots of problem action domains and recording heap memory snapshots of non-problem action domains;
Recording execution context Wen Zhan in the code running process, focusing on memory change in the execution context changing process so as to follow up the reference relation of the tracking node;
Recording heap memory snapshot information in the code running process, updating the memory snapshot information regularly if the memory is normal, and continuously recording the memory snapshot information at fixed time intervals if the memory is abnormal;
And monitoring and recording system-level monitoring information and garbage collection mechanism conditions in the code execution process, so that the memory condition can be conveniently compared and analyzed. The system level monitoring information comprises indexes such as a system memory, CPU utilization rate and the like.
In step S103, according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, the JavaScript heap memory occupation situation is rendered in real time, and a call relation diagram between variable nodes in the scope is drawn.
The visual rendering device loads heap memory snapshot information stored by the data acquisition device, an AST abstract syntax tree and an ECS scope chain, renders the occupation condition of the JavaScript heap memory in real time, draws a call relation diagram among variable nodes in the scope and marks garbage collection paths and problem nodes.
Drawing a call relation diagram among variable nodes in a scope according to an abstract syntax tree and execution upper and lower Wen Zhan, and marking garbage recycling conditions;
in the call relation diagram, the memory health state of the node is identified, and in the call relation diagram, the method for identifying the memory health state of the node is as follows:
Gray is adopted to indicate that the variable node experiences a complete memory life cycle;
Yellow is adopted to indicate that the variable node still has references and is stored in the memory at present;
The free variable nodes are indicated by red.
And rendering JavaScript memory data at the target moment according to the heap memory snapshot information, and rendering a visual chart of indexes such as a system level memory and the like in real time. Wherein the visualization graphs include, but are not limited to, line graphs, bar graphs, and stack graphs.
In step S104, the common memory leakage tracking library is automatically updated according to the self-learning method, the memory leakage problem is automatically identified according to the updated common memory leakage tracking library, and corresponding early warning information and positioning problem nodes are sent out, namely, the scope and calling path of the variable nodes are recorded, or code optimization suggestions are given according to the static analysis result.
The description of relevant parts in the JavaScript memory visual analysis and management device and the storage medium provided by the embodiment of the application can be referred to the detailed description of corresponding parts in the JavaScript memory visual analysis and management method provided by the embodiment 1 of the application, and will not be repeated here.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements is inherent to. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element. In addition, the parts of the above technical solutions provided in the embodiments of the present application, which are consistent with the implementation principles of the corresponding technical solutions in the prior art, are not described in detail, so that redundant descriptions are avoided.
While the specific embodiments of the present invention have been described above with reference to the drawings, the scope of the present invention is not limited thereto. Other modifications and variations to the present invention will be apparent to those of skill in the art upon review of the foregoing description. It is not necessary here nor is it exhaustive of all embodiments. On the basis of the technical scheme of the invention, various modifications or variations which can be made by the person skilled in the art without the need of creative efforts are still within the protection scope of the invention.

Claims (8)

  1. The visual analysis and management method for the JavaScript memory is characterized by comprising the following steps:
    Analyzing the JavaScript object code to generate a corresponding abstract syntax tree and a scope of the variable;
    The specific process of running the JavaScript object code and recording the execution context stack and heap memory snapshot information in the code running process comprises the steps of running the JavaScript object code, recording the heap memory snapshot of a problem acting domain and recording the heap memory snapshot of a non-problem acting domain, recording the execution context stack and the heap memory snapshot information in the code running process, updating the memory snapshot information at regular time if the memory is normal, continuing to record the memory snapshot information at fixed time intervals if the memory is abnormal, and monitoring and recording the system level monitoring information and the garbage recycling mechanism condition in the code executing process;
    The method comprises the steps of rendering a call relation diagram among variable nodes in a scope in real time according to the abstract syntax tree, the execution context stack and heap memory snapshot information, rendering the call relation diagram among the variable nodes in the scope in real time according to the abstract syntax tree, the execution context stack and heap memory snapshot information, and rendering a visual diagram of a system-level memory index in real time.
  2. 2. The method for visualizing analysis and management of JavaScript memory according to claim 1, wherein when the JavaScript object code is parsed to generate the corresponding abstract syntax tree and scope of the variable, the method further comprises statically analyzing the JavaScript object code according to a memory leakage tracking library, and labeling the scope of the problem which is likely to cause leakage.
  3. 3. The method for visualizing analysis and management of JavaScript memory according to claim 2, further comprising giving an optimization suggestion of JavaScript object code according to the result of static analysis of the JavaScript object code.
  4. 4. The method for visualizing analysis and management of JavaScript memory according to claim 2, further comprising automatically updating the memory leakage tracking library according to a self-learning method, automatically identifying a memory leakage problem according to the updated memory leakage tracking library, and sending out corresponding early warning information and locating problem nodes.
  5. 5. The JavaScript memory visualization analysis and management method according to claim 1, wherein the method for identifying the memory health status of the node in the call relation graph is as follows:
    Gray is adopted to indicate that the variable node experiences a complete memory life cycle;
    Yellow is adopted to indicate that the variable node still has references and is stored in the memory at present;
    The free variable nodes are indicated by red.
  6. The visual analysis and management system of JavaScript memory for executing the visual analysis and management method of JavaScript memory according to any one of claims 1 to 5, which is characterized by comprising a code pre-analysis device, a data acquisition device and a visual rendering device;
    the code pre-analysis device is used for analyzing the JavaScript object code and generating a corresponding abstract syntax tree and a scope of the variable;
    The data acquisition device is used for running the JavaScript object code and recording the execution context stack and heap memory snapshot information in the code running process;
    the visual rendering device is used for rendering the occupation condition of the JavaScript heap memory in real time according to the abstract syntax tree, the execution context stack and the heap memory snapshot information, and drawing a call relation diagram among variable nodes in the scope.
  7. The visual analysis and management device of JavaScript memory is characterized by comprising:
    a memory for storing a computer program;
    a processor for implementing the method steps of any one of claims 1 to 5 when executing said computer program.
  8. 8. A readable storage medium, characterized in that it has stored thereon a computer program which, when executed by a processor, implements the method steps of any of claims 1 to 5.
CN202110798605.XA 2021-07-16 2021-07-16 JavaScript memory visual analysis and management method, system, equipment and storage medium Active CN113688189B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110798605.XA CN113688189B (en) 2021-07-16 2021-07-16 JavaScript memory visual analysis and management method, system, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110798605.XA CN113688189B (en) 2021-07-16 2021-07-16 JavaScript memory visual analysis and management method, system, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113688189A CN113688189A (en) 2021-11-23
CN113688189B true CN113688189B (en) 2024-11-29

Family

ID=78577154

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110798605.XA Active CN113688189B (en) 2021-07-16 2021-07-16 JavaScript memory visual analysis and management method, system, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113688189B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114896946A (en) * 2022-03-10 2022-08-12 上海仁静信息技术有限公司 Method for converting text and related equipment

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306479A (en) * 2020-10-10 2021-02-02 苏州浪潮智能科技有限公司 A method and device for visual analysis of code based on abstract grammar

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB0608406D0 (en) * 2006-04-28 2006-06-07 Ibm Creating references in a scoped memory system
CN103136407B (en) * 2011-12-03 2015-06-03 南京南瑞继保电气有限公司 Method of achieving snapshot with electro-magnetic transient in DC system (EMTDC) simulation model based on data integrated access technique
CN104850786B (en) * 2015-06-03 2018-03-20 舒辉 Malicious code integrity analysis method based on environment reconstruct
CN111240801A (en) * 2020-01-06 2020-06-05 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for generating heap memory snapshot file

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306479A (en) * 2020-10-10 2021-02-02 苏州浪潮智能科技有限公司 A method and device for visual analysis of code based on abstract grammar

Also Published As

Publication number Publication date
CN113688189A (en) 2021-11-23

Similar Documents

Publication Publication Date Title
CN109144882B (en) A software fault location method and device based on program invariants
Fluri et al. Classifying change types for qualifying change couplings
US8984485B2 (en) Analysis of source code changes
CN111240689B (en) Application program construction method, device, equipment and storage medium
CN111240982A (en) Source code static analysis method
KR101581001B1 (en) Method and apparatus for dynamic analysis of program
US9697255B2 (en) Systems and/or methods for introducing semantic concepts into complex event processing environments
CN103440196B (en) A kind of operating-system resources failure detecting method
US8762949B2 (en) Method and apparatus for incremental analysis of one or more properties of a program
CN111475150B (en) Cross-language binding method, device, equipment and storage medium
CN104657402A (en) Language Tag Management On International Data Storage
CN112015467A (en) Point burying method, medium, device and computing equipment
CN114138244A (en) Method and device for automatically generating model files, storage medium and electronic equipment
CN116383832A (en) A smart contract vulnerability detection method based on graph neural network
CN113688189B (en) JavaScript memory visual analysis and management method, system, equipment and storage medium
Bosch et al. Software logs for machine learning in a DevOps environment
CN115328796A (en) Software vulnerability auxiliary positioning method and system for ARM architecture
CN113986739B (en) Method, device, storage medium and processor for monitoring website memory leaks
CN113918664B (en) Data processing method and device
Xu et al. Memory leak detection based on memory state transition graph
Cheney et al. Toward a theory of self-explaining computation
CN115344562B (en) Big data mining method and device, storage medium and electronic equipment
CN116383834B (en) Detection method for source code vulnerability detection tool abnormality and related equipment
CN117520199B (en) Numerical software defect detection method and device based on static symbolic execution
CN116502239B (en) Memory vulnerability detection method, device, equipment and medium for binary program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant