CN114780330A - Code monitoring method and device - Google Patents

Code monitoring method and device Download PDF

Info

Publication number
CN114780330A
CN114780330A CN202210269081.XA CN202210269081A CN114780330A CN 114780330 A CN114780330 A CN 114780330A CN 202210269081 A CN202210269081 A CN 202210269081A CN 114780330 A CN114780330 A CN 114780330A
Authority
CN
China
Prior art keywords
code
target
original
feature
feature code
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.)
Pending
Application number
CN202210269081.XA
Other languages
Chinese (zh)
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.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network 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 Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN202210269081.XA priority Critical patent/CN114780330A/en
Publication of CN114780330A publication Critical patent/CN114780330A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Abstract

The invention discloses a code monitoring method and a code monitoring device. The method comprises the following steps: modifying the original code to obtain a target code; generating a target abstract syntax tree corresponding to the target code; traversing a target abstract syntax tree to generate a target feature code, wherein the target feature code is used for representing a part of code statements with target features in the target code; and comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code or not. The invention solves the technical problem that the code monitoring scheme in the related technology can only monitor diff information modified each time and can not locate which interface the modified code belongs to.

Description

Code monitoring method and device
Technical Field
The invention relates to the technical field of computers, in particular to a code monitoring method and device.
Background
In software development, there are many universal underlying interfaces or underlying protocols, and once the code of the underlying interface is changed, many calling relationships are often affected, so that monitoring the change of the interface content is very important. However, the current monitoring scheme for the interface codes can only monitor the difference diff of each modification, and cannot locate which interface the modified code belongs to.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
At least part of embodiments of the present invention provide a code monitoring method and apparatus, so as to solve at least the technical problem that in the related art, a code monitoring scheme can only monitor diff information of each modification, and cannot locate which interface the modified code belongs to.
According to an embodiment of the present invention, there is provided a code monitoring method, including: modifying the original code to obtain a target code; generating a target abstract syntax tree corresponding to the target code; traversing the target abstract syntax tree to generate a target feature code, wherein the target feature code is used for representing a partial code statement with target features in the target code; and comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code or not.
Optionally, traversing the target abstract syntax tree, and generating the target feature code comprises: traversing the target abstract syntax tree, and extracting target nodes corresponding to target features in the target abstract syntax tree; and reversely reducing the target node into a source code to obtain a target feature code.
Optionally, generating the target abstract syntax tree corresponding to the target code includes: determining a target programming language corresponding to the target code; and generating a target abstract syntax tree based on the syntax structure of the target programming language.
Optionally, the method further comprises: generating an original abstract syntax tree corresponding to an original code; and traversing the original abstract syntax tree to generate an original feature code.
Optionally, after comparing the target feature code with the original feature code to generate a monitoring result, the method further includes: responding to the monitoring result that the target feature code is different from the original feature code, and generating difference information between the target feature code and the original feature code; generating early warning information based on the original feature codes, the target feature codes and the difference information; and outputting the early warning information to the first terminal.
Optionally, a first terminal corresponding to the first touch instruction is determined in response to the first touch instruction acting on the first control.
Optionally, after outputting the warning information to the first terminal, the method further includes: generating a test scheme corresponding to the target code based on the early warning information; and testing the target code based on the test scheme to obtain a test result.
Optionally, in response to a second touch instruction acting on the second control, determining that the test result is that the target code passes the test.
Optionally, modifying the original code to obtain the target code includes: monitoring the original code; responding to the modification of the original code, and acquiring code information corresponding to the target code; the object code is acquired based on the code information.
According to an embodiment of the present invention, there is also provided a code monitoring apparatus including: the modification module is used for modifying the original code to obtain a target code; the generating module is used for generating a target abstract syntax tree corresponding to the target code; the traversal module is used for traversing the target abstract syntax tree and generating a target feature code, wherein the target feature code is used for representing a part of code statements with target features in the target code; and the comparison module is used for comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a part of code statements with target features in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code or not.
According to an embodiment of the present invention, there is further provided a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the code monitoring method when running.
There is further provided, according to an embodiment of the present invention, an electronic apparatus, including a memory and a processor, where the memory stores a computer program, and the processor is configured to execute the computer program to perform the code monitoring method.
In at least some embodiments of the present invention, after modifying an original code to obtain a target code, a target abstract syntax tree corresponding to the target code may be generated, and then the target abstract syntax tree is traversed to generate a target feature code, so that by comparing the target feature code with the original feature code, it may be determined whether the target feature code is the same as the original feature code, thereby achieving the purpose of code monitoring. It is easy to notice that any feature code in the code is extracted through an abstract syntax rule, and then whether the feature code is changed or not can be monitored by comparing the feature code, so that the technical effects of accurately positioning which interface the modified code belongs to and reducing the quality risk of code testing are achieved, and the technical problem that in the related technology, a code monitoring scheme can only monitor diff information of each modification and cannot position which interface the modified code belongs to is solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention and do not constitute a limitation of the invention. In the drawings:
fig. 1 is a block diagram of a hardware configuration of a computer terminal of a code monitoring method according to an embodiment of the present invention;
FIG. 2 is a flow diagram of a code monitoring method according to one embodiment of the invention;
FIG. 3 is a flowchart illustrating an implementation process of a multilingual code monitoring apparatus based on an abstract syntax tree according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a project configuration center according to one embodiment of the invention;
FIG. 5 is a diagram of a custom extraction logical page according to one embodiment of the invention;
FIG. 6 is a schematic diagram of a feature code version 1 presentation page in accordance with one embodiment of the present invention;
FIG. 7 is a schematic diagram of a feature code change list presentation page in accordance with one embodiment of the present invention;
FIG. 8 is a schematic illustration of a pre-and post-alteration comparison and diff information presentation page in accordance with one embodiment of the present invention;
fig. 9 is a block diagram of a code monitoring apparatus according to an alternative embodiment of the present invention.
Detailed Description
In order to make those skilled in the art better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without making any creative effort based on the embodiments in the present invention, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Moreover, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In the current monitoring scheme of interface codes, the following modes are mainly adopted: the first is a code diff tool, and by virtue of version management tools such as svn and git, diff modified each time is extracted for monitoring; the second is to locate which function the modified content belongs to by means of text scan code analysis after each modification.
However, the first scheme can only display diff content, but displays are all based on context, and can only display changed line number and correspondingly changed codes, and cannot locate which function the changed codes belong to; in the second scheme, by means of a text scanning code analysis interface method, function keywords are analyzed to obtain content of function definition, and the extracted logic is not universal and the accuracy is not high.
In accordance with one embodiment of the present invention, there is provided an embodiment of a code monitoring method, it should be noted that the steps illustrated in the flowchart of the accompanying drawings may be performed in a computer system such as a set of computer-executable instructions, and that while a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than that described herein.
The method embodiments may be performed in a mobile terminal, a computer terminal or a similar computing device. Taking the example of running on a computer terminal, the computer terminal may be a personal PC, a notebook computer, or other terminal equipment. Fig. 1 is a block diagram of a hardware structure of a computer terminal of a code monitoring method according to an embodiment of the present invention. As shown in fig. 1, a computer terminal may include one or more (only one shown in fig. 1) processors 102 (processor 102 may include, but is not limited to, a processing device such as a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Digital Signal Processing (DSP) chip, a Microprocessor (MCU), a programmable logic device (FPGA), a neural Network Processor (NPU), a Tensor Processor (TPU), an Artificial Intelligence (AI) type processor, etc.) and a memory 104 for storing data. Optionally, the computer terminal may further include a transmission device 106, an input/output device 108, and a display device 110 for communication functions. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the computer terminal. For example, the computer terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store computer programs, for example, software programs and modules of application software, such as computer programs corresponding to the code monitoring method in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the code monitoring method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to a computer terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet via wireless.
The inputs in the input output Device 108 may come from a plurality of Human Interface Devices (HIDs). For example: keyboard and mouse, game pad, other special game controller (such as steering wheel, fishing rod, dance mat, remote controller, etc.). In addition to providing input functionality, some human interface devices may also provide output functionality, such as: force feedback and vibration of the gamepad, audio output of the controller, etc.
The display device 110 may be, for example, a head-up display (HUD), a touch screen type Liquid Crystal Display (LCD), and a touch display (also referred to as a "touch screen" or "touch display screen"). The liquid crystal display may enable a user to interact with a user interface of the computer terminal. In some embodiments, the computer terminal has a Graphical User Interface (GUI) with which a user can interact by touching finger contacts and/or gestures on a touch-sensitive surface, where the human interaction functionality optionally includes the following interactions: executable instructions for creating web pages, drawing, word processing, making electronic documents, games, video conferencing, instant messaging, emailing, call interfacing, playing digital video, playing digital music, and/or web browsing, etc., for performing the above-described human-computer interaction functions, are configured/stored in one or more processor-executable computer program products or readable storage media.
In one possible implementation, an embodiment of the present invention provides a code monitoring method. Fig. 2 is a flow chart of a code monitoring method according to an embodiment of the present invention, as shown in fig. 2, the method includes the following steps:
and step S202, modifying the original code to obtain a target code.
The original code in the above steps may be an original version code that needs to be monitored for changes in the user project, and the target code may be a new version code generated by a software developer modifying a part of code statements in the original code in the software development process.
In an optional embodiment, in the iteration process of the project version, a software developer may modify a code file in the project to generate a code file of a different version, the code file before modification each time may be used as an original code, and the modified code file may be used as an object code.
Step S204, generating a target abstract syntax tree corresponding to the target code.
The abstract syntax tree in the above steps may be an abstract representation of the syntax structure of the source code, the syntax structure of the programming language is represented in the form of tree, and each node on the tree identifies a structure in the source code.
In an alternative embodiment, the syntax rules of the programming language may be used to perform lexical parsing on the target code and generate the corresponding abstract syntax tree statically.
And step S206, traversing the target abstract syntax tree to generate a target feature code, wherein the target feature code is used for representing a partial code statement with target features in the target code.
The target feature code in the above steps may be a feature code desired to be monitored in a user project, including but not limited to a communication protocol, an engine interface, an underlying general function, a critical variable, and the like, and there is a great quality risk if an important protocol and an interface are modified and a test is not found in time.
In an alternative embodiment, a user may customize the extraction logic of the abstract syntax tree in the web front end, so that after the target abstract syntax tree is generated, the pre-formulated extraction logic may be executed to extract the target feature code to be monitored from the target abstract syntax tree. It should be noted that, the user may specify a keyword of the code that the user wishes to monitor, so that the corresponding target feature code can be extracted from the abstract syntax tree based on the keyword.
And step S208, comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code.
The original feature code in the above steps may be a feature code extracted from the original code by using an abstract syntax tree rule and an extraction logic specified by a user, and the extraction processes of the original feature code and the target feature code are the same and the same extraction logic is adopted. In addition, the original feature codes can be stored in a database, so that comparison between target feature codes is facilitated.
In an alternative embodiment, the original feature code may be used as version 1 of the feature code that the user wishes to monitor, the target feature code may be used as version 2 of the code that the user wishes to monitor, the version 1 and the version 2 may be compared by using a diff tool, and if the two are the same, it indicates that the feature code that the user wishes to monitor is not modified in the modified content of the target code at this time, that is, the generated monitoring result is that the target feature code is the same as the original feature code; if the two are different, diff information can be generated to indicate that the feature code which is expected to be monitored in the modification content of the target code at this time is modified, that is, the generated monitoring shows that the target feature code is different from the original feature code.
It should be noted that if the monitoring result is that the target feature code is different from the original feature code, an alarm is required to remind the tester to schedule a special test.
According to the scheme provided by the embodiment of the invention, after the original code is modified to obtain the target code, the target abstract syntax tree corresponding to the target code can be generated, and then the target abstract syntax tree is traversed to generate the target feature code, so that whether the target feature code is the same as the original feature code can be determined by comparing the target feature code with the original feature code, and the purpose of monitoring the code is achieved. It is easy to notice that any feature code in the code is extracted through an abstract syntax rule, and then whether the feature code is changed or not can be monitored by comparing the feature code, so that the technical effects of accurately positioning which interface the modified code belongs to and reducing the quality risk of code testing are achieved, and the technical problem that in the related technology, a code monitoring scheme can only monitor diff information of each modification and cannot position which interface the modified code belongs to is solved.
In the above embodiment of the present invention, traversing the target abstract syntax tree and generating the target feature code includes: traversing the target abstract syntax tree, and extracting target nodes corresponding to target features in the target abstract syntax tree; and reversely reducing the target node into a source code to obtain a target feature code.
The target feature in the above steps may be a feature of a feature code that the user wishes to monitor, and may be, for example, a keyword specified by the user, but is not limited thereto. The user can customize the extraction logic according to project characteristics and monitor any statement in the code.
In an alternative embodiment, the formulated extraction logic may be executed to traverse the target abstract syntax tree, extract the target node in the target abstract syntax tree according to the keyword of the feature code that the user wishes to monitor, and then reversely restore the target node to the source code according to the syntax rules of different programming languages, i.e. generate the target feature code.
In the above embodiment of the present invention, generating the target abstract syntax tree corresponding to the target code includes: determining a target programming language corresponding to the target code; and generating a target abstract syntax tree based on the syntax structure of the target programming language.
The target programming language in the above steps may be a programming language used by the user project, and may be any one of a plurality of programming languages.
In an alternative embodiment, the target abstract syntax tree can be generated statically based on this parsing of different programming languages, which helps to cover programming test environments for different projects.
In the above embodiment of the present invention, the method further includes: generating an original abstract syntax tree corresponding to an original code; and traversing the original abstract syntax tree to generate an original feature code.
In an optional embodiment, for the original code, all feature codes under the code path of the original code may be extracted in full and stored in the database, and the extraction process here is the same as the extraction process of the target feature code, and is not described here again.
In the above embodiment of the present invention, after comparing the target feature code with the original feature code to generate a monitoring result, the method further includes: responding to the monitoring result that the target feature code is different from the original feature code, and generating difference information between the target feature code and the original feature code; generating early warning information based on the original feature codes, the target feature codes and the difference information; and outputting the early warning information to the first terminal.
The first terminal in the above steps may be a pre-designated test responsible person, and the tester arranges the test scheme and the test plan according to the modification.
In an alternative embodiment, a diff difference comparison may be performed on the target feature code and the original feature code by using a diff tool, if there is a modification, the diff information is generated and stored in the corresponding database entry, and the modification is marked on the feature code; if not, then no changes to the database are required. Further, under the condition that modification is confirmed, the testing responsible person is informed of early warning and arranging special tests through a communication tool or chat software, so that the testing responsible person can accurately know the modification range of the feature codes conveniently, early warning information can be generated based on the feature codes and diff information before and after modification, and the early warning information is sent to the testing responsible person.
In the above embodiment of the present invention, in response to the first touch instruction acting on the first control, the first terminal corresponding to the first touch instruction is determined.
The first control in the above steps may be a button provided to the user in the web front end for assigning a responsible person. The user assigns a test responsible person for the code modification of the time by operating the button, and the test is carried out by the tester.
In an alternative embodiment, in the case that the target feature code and the original feature code are different, in order to facilitate the user to visually check the change of the feature code, an entry containing the original feature code, the target feature code and diff information may be displayed in the web front end, and a button for assigning a responsible person may be provided for the entry, and the user may select the test responsible person by clicking the button.
In the above embodiment of the present invention, after outputting the warning information to the first terminal, the method further includes: generating a test scheme corresponding to the target code based on the early warning information; and testing the target code based on the test scheme to obtain a test result.
In an optional embodiment, after receiving the warning information, the tester can check the feature codes and diff information before and after modification, that is, check the original feature codes, the target feature codes and the diff information, and can know the specific modification paradigm, confirm the regression range, wait for the tester to finish the regression test, and complete the whole monitoring test flow under the condition that the test is passed, and the target codes can be placed outside, so that the test flow forms a closed-loop operation.
In the above embodiment of the present invention, the second touch instruction acting on the second control is responded, and the test result is determined as that the target code passes the test.
The first control in the above step may be a button in the web front end that provides the user with entry confirmation. The user confirms that the object code passes the test by operating the button.
In an alternative embodiment, an entry containing the original feature code, the target feature code and diff information is displayed in the web front end, and a button for entry confirmation is provided for the entry, after the tester tests the target code, if the target code passes the test, the tester can click the button to confirm that the modification passes the test, and the modification is free from problems and can be played.
In the above embodiment of the present invention, modifying the original code to obtain the target code includes: monitoring the original code; responding to the modification of the original code, and acquiring code information corresponding to the target code; the object code is acquired based on the code information.
The code information in the above steps may be, but is not limited to, a submission author, a submission version, a submission file, a submission time, submission log information, and the like of version management.
In an alternative embodiment, the version change of the original code may be monitored by a version management tool, and by using a hook principle of the version management tool, once the version of the code warehouse is modified, the version management tool immediately sends code information, that is, triggers a post _ commit event of the version management tool, and after receiving the code information, a file of the version change may be obtained according to the information, that is, a target code is obtained.
A preferred embodiment of the present invention will be described in detail with reference to fig. 3 to 8, and the present invention provides a multilingual code monitoring apparatus based on an abstract syntax tree, as shown in fig. 3, the apparatus is implemented as follows:
step S301, the user registers and logs in the apparatus, as shown in fig. 4, newly creates a project, and fills in project information, for example: the server address of the project, the path of the monitored code, the programming language type, the extraction logic for making the feature code and the like, and the interface for customizing the extraction logic is shown in figure 5.
Step S302, based on the item information filled by the user, all feature codes in the code path are extracted for the first time and stored in the database, at this time, the feature code entries in the database are all recorded as feature code version 1, as shown in fig. 6. The extraction process of the feature code is as follows: and traversing all files under the monitoring code path. Reading the content of each file, generating a corresponding abstract syntax tree according to lexical syntax analysis of the programming language type, executing formulated extraction logic, traversing the abstract syntax tree, extracting feature nodes corresponding to feature codes on the syntax tree, and reversely reducing the feature nodes into source codes, namely generating the feature codes.
Step S303, monitoring the version change of the code file by the version management tool, and immediately sending code information to inform the device by the version management tool once the version of the code warehouse is changed by utilizing the hook principle of the version management tool, wherein the information comprises a submission author, a submission version, a submission file, a submission time, submission log information and the like of version management.
Step S304, after receiving the notification information of the version management tool, the device obtains the file modified by the version according to the information, and the device re-extracts the feature code for the modified file, where the extraction process is as described in S302, and the feature code extracted at this time is written as the feature code version 2.
Step S305, the difference comparison of diff is carried out on the feature code version 2 and the feature code version 1 stored in the database, if the difference is modified, the diff is generated and stored in the corresponding database entry, the feature code is marked to be modified, and the corresponding responsible person is informed through chatting software to carry out early warning; if not, then no changes to the database are required.
Step S306, the device displays the feature code item modified at this time according to the mark of the stored item in the database, as shown in FIG. 7, including the code before modification, the code after modification, and the diff difference before and after modification, as shown in FIG. 8, and each item provides a button for assigning a responsible person and confirming the item for the user to operate.
And S307, the tester receives the early warning information, opens the device, can check which feature codes are modified by the version, knows the modification range through the information before and after modification and diff, confirms the regression range, and operates the test confirmation on the device after the regression test of the tester is finished, thereby completing the whole monitoring test process.
Through the description of the foregoing embodiments, it is clear to those skilled in the art that the method according to the foregoing embodiments may be implemented by software plus a necessary general hardware platform, and certainly may also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention or portions thereof contributing to the prior art may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (which may be a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
In this embodiment, a code monitoring apparatus is further provided, which is used to implement the foregoing embodiments and preferred embodiments, and is not described again after being described. As used below, the terms "module", "unit" may implement a combination of software and/or hardware of predetermined functions. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 9 is a block diagram of a code monitoring apparatus according to an embodiment of the present invention, as shown in fig. 9, the apparatus including:
a modifying module 92, configured to modify the original code to obtain a target code;
a generating module 94, configured to generate a target abstract syntax tree corresponding to the target code;
a traversing module 96, configured to traverse the target abstract syntax tree to generate a target feature code, where the target feature code is used to represent a partial code statement with a target feature in the target code;
and the comparing module 98 is configured to compare the target feature code with the original feature code to generate a monitoring result, where the original feature code is used to characterize a partial code statement having a target feature in the original code, and the monitoring result is used to characterize whether the target feature code is the same as the original feature code.
In the above embodiment of the present invention, the traversing module includes: the extraction unit is used for traversing the target abstract syntax tree and extracting target nodes corresponding to target features in the target abstract syntax tree; and the restoring unit is used for reversely restoring the target node into the source code to obtain the target feature code.
In the above embodiments of the present invention, the generating module includes: the determining unit is used for determining a target programming language corresponding to the target code; and the generating unit is used for generating a target abstract syntax tree based on the syntax structure of the target programming language.
In the above embodiment of the present invention, the generating module is further configured to generate an original abstract syntax tree corresponding to the original code; the traversing module is also used for traversing the original abstract syntax tree to generate an original characteristic code.
In the above embodiment of the present invention, the apparatus further includes: the difference generation module is used for responding to the monitoring result that the target feature code is different from the original feature code and generating difference information between the target feature code and the original feature code; the early warning generation module is used for generating early warning information based on the original characteristic code, the target characteristic code and the difference information; and the output module is used for outputting the early warning information to the first terminal.
In the above embodiment of the present invention, the apparatus further includes: and the terminal determining module is used for responding to a first touch instruction acting on the first control and determining a first terminal corresponding to the first touch instruction.
In the above embodiment of the present invention, the apparatus further includes: the scheme generation module is used for generating a test scheme corresponding to the target code based on the early warning information; and the test module is used for testing the target code based on the test scheme to obtain a test result.
In the above embodiment of the present invention, the apparatus further includes: and the test determining module is used for responding to a second touch instruction acting on the second control and determining that the test result is that the target code passes the test.
In the above embodiment of the present invention, the modifying module includes: the monitoring unit is used for monitoring the original code; the first acquisition unit is used for responding to the modification of the original code and acquiring code information corresponding to the target code; a second acquisition unit configured to acquire the object code based on the code information.
It should be noted that, the above modules and units can be implemented by software or hardware, and for the latter, the following modes can be implemented, but are not limited to the following modes: the modules and the units are all positioned in the same processor; alternatively, the modules and units may be located in different processors in any combination.
Embodiments of the present invention also provide a non-volatile storage medium having a computer program stored therein, wherein the computer program is configured to perform the steps of any of the above method embodiments when executed.
Alternatively, in this embodiment, the above-mentioned nonvolatile storage medium may be configured to store a computer program for executing the steps of:
s1, modifying the original code to obtain a target code;
s2, generating a target abstract syntax tree corresponding to the target code;
s3, traversing the target abstract syntax tree to generate a target feature code, wherein the target feature code is used for representing a partial code statement with a target feature in the target code;
and S4, comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code.
Optionally, in this embodiment, the nonvolatile storage medium may include but is not limited to: various media capable of storing computer programs, such as a usb disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk.
Embodiments of the present invention further provide an electronic device, comprising a memory in which a computer program is stored and a processor configured to execute the computer program to perform the steps in any of the above method embodiments.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, modifying the original code to obtain a target code;
s2, generating a target abstract syntax tree corresponding to the target code;
s3, traversing the target abstract syntax tree to generate a target feature code, wherein the target feature code is used for representing a partial code statement with a target feature in the target code;
and S4, comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation manners, and this embodiment is not described herein again.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other manners. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit may be implemented in the form of hardware, or may also be implemented in the form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention, which is substantially or partly contributed by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (12)

1. A code monitoring method, comprising:
modifying the original code to obtain a target code;
generating a target abstract syntax tree corresponding to the target code;
traversing the target abstract syntax tree to generate a target feature code, wherein the target feature code is used for representing a partial code statement with a target feature in the target code;
and comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code.
2. The method of claim 1, wherein traversing the target abstract syntax tree, generating the target feature code, comprises:
traversing the target abstract syntax tree, and extracting a target node corresponding to the target feature in the target abstract syntax tree;
and reversely reducing the target node into a source code to obtain the target feature code.
3. The method of claim 1, wherein generating the target abstract syntax tree for the target code comprises:
determining a target programming language corresponding to the target code;
generating the target abstract syntax tree based on a syntax structure of the target programming language.
4. The method of claim 1, further comprising:
generating an original abstract syntax tree corresponding to the original code;
and traversing the original abstract syntax tree to generate the original feature code.
5. The method of any one of claims 1 to 4, wherein after comparing the target feature code with the original feature code to generate a monitoring result, the method further comprises:
in response to the monitoring result that the target feature code is different from the original feature code, generating difference information between the target feature code and the original feature code;
generating early warning information based on the original feature codes, the target feature codes and the difference information;
and outputting the early warning information to a first terminal.
6. The method according to claim 5, wherein the first terminal corresponding to the first touch instruction is determined in response to the first touch instruction acting on the first control.
7. The method of claim 5, wherein after outputting the warning information to the first terminal, the method further comprises:
generating a test scheme corresponding to the target code based on the early warning information;
and testing the target code based on the test scheme to obtain a test result.
8. The method of claim 7, wherein the test result is determined to be that the target code passes the test in response to a second touch command applied to a second control.
9. The method of any of claims 1-4, wherein modifying the original code to obtain the object code comprises:
monitoring the original code;
responding to the modification of the original code, and acquiring code information corresponding to the target code;
and acquiring the target code based on the code information.
10. A code monitoring device, comprising:
the modification module is used for modifying the original code to obtain a target code;
the generating module is used for generating a target abstract syntax tree corresponding to the target code;
a traversing module, configured to traverse the target abstract syntax tree to generate a target feature code, where the target feature code is used to characterize a partial code statement with a target feature in the target code;
and the comparison module is used for comparing the target feature code with the original feature code to generate a monitoring result, wherein the original feature code is used for representing a partial code statement with the target feature in the original code, and the monitoring result is used for representing whether the target feature code is the same as the original feature code or not.
11. A computer-readable storage medium, in which a computer program is stored, wherein the computer program is arranged to perform the code monitoring method of any of claims 1 to 9 when executed.
12. An electronic device comprising a memory and a processor, wherein the memory has a computer program stored therein, and the processor is configured to run the computer program to perform the code monitoring method according to any one of claims 1 to 9.
CN202210269081.XA 2022-03-18 2022-03-18 Code monitoring method and device Pending CN114780330A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210269081.XA CN114780330A (en) 2022-03-18 2022-03-18 Code monitoring method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210269081.XA CN114780330A (en) 2022-03-18 2022-03-18 Code monitoring method and device

Publications (1)

Publication Number Publication Date
CN114780330A true CN114780330A (en) 2022-07-22

Family

ID=82424932

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210269081.XA Pending CN114780330A (en) 2022-03-18 2022-03-18 Code monitoring method and device

Country Status (1)

Country Link
CN (1) CN114780330A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116756052A (en) * 2023-08-18 2023-09-15 建信金融科技有限责任公司 Data processing method and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116756052A (en) * 2023-08-18 2023-09-15 建信金融科技有限责任公司 Data processing method and device
CN116756052B (en) * 2023-08-18 2023-11-14 建信金融科技有限责任公司 Data processing method and device

Similar Documents

Publication Publication Date Title
US10990367B2 (en) Application development method, tool, and device, and storage medium
CN105511873B (en) User interface control display method and device
US9218324B2 (en) Method of encapsulating diverse user interface components while consistently enforcing external constraints
JPH07114468A (en) Computer system
CN108830383B (en) Method and system for displaying machine learning modeling process
CN113741898B (en) Form generation method, device and equipment
US20230229406A1 (en) Page rendering method, apparatus, electronic device, computer-readable storage medium, and computer program product
CN112988752A (en) Resource management method, device, storage medium and electronic equipment
CN113268260A (en) Routing method and device for web front end
CN114780330A (en) Code monitoring method and device
CN115469849B (en) Service processing system, method, electronic equipment and storage medium
CN111338626A (en) Interface rendering method and device, electronic equipment and medium
CN114816389B (en) Management system building method, device, equipment and medium based on meta-model
JP2024505316A (en) Application testing methods, equipment, electronic equipment and storage media
CN110968311A (en) Front-end page construction method and device and electronic equipment
CN111338609B (en) Information acquisition method, device, storage medium and terminal
CN112948264A (en) Test task execution method, device, system, storage medium and electronic device
CN108960433B (en) Method and system for running machine learning modeling process
CN113342341A (en) Page creating method, device and system and storage medium
CN111460235A (en) Atlas data processing method, device, equipment and storage medium
CN113076728A (en) Data filling method of dialog box and related equipment
CN113806327A (en) Database design method and device and related equipment
CN112667141A (en) Input revocation method, device, electronic equipment and computer-readable storage medium
CN112988138A (en) System and method for application in an integrated development environment
KR102651294B1 (en) Method for assisting collect information about screen component

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