Processing method and device of program code data, electronic equipment and storage medium
By generating code call chain graphs, the problem of difficulty in analyzing the impact range of code modifications on the production and consumption of virtual items in online games is solved, improving analysis efficiency and accuracy, and reducing operational risks.
Patent Information
- Application Number
- CN202411533213.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2044-10-30
AI Technical Summary
Existing technologies make it difficult to efficiently and accurately analyze the scope of impact of code modifications on the production and consumption of virtual items in online games, leading to increased operational risks.
By acquiring server runtime data to generate code call chains, the call relationships and differences between functions are determined, and a code call chain graph is provided to intuitively understand the impact of code modifications.
It improves the efficiency and accuracy of analyzing code modifications to business functions, reduces operational risks, and ensures the stability of the game's economic system.
Smart Images

Figure CN119621525B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of program code, in particular to a program code data processing method and device, electronic equipment and storage medium. BACKGROUND
[0002] Game economy is the most core system of network games, and game economy is manifested as the output and consumption of various virtual props in the game operation process. A major problem in the daily development and testing process of virtual prop output and consumption is that the basic business code of the game server is associated with the generation and consumption of virtual props. Due to the characteristics of agile development of network games, a large amount of business code is modified daily, and it is difficult to achieve full testing. In related technologies, relevant personnel usually perform code change analysis based on code file text comparison to determine the business functions affected by the code modification. This method is low in efficiency and low in accuracy of analysis results. Some other methods analyze the upstream and downstream calling relationships of the code through code syntax trees, so that relevant personnel can analyze the influence range of the code modification based on the calling relationships. The accuracy of the analysis results of this method is usually low. SUMMARY
[0003] Therefore, the purpose of the present disclosure is to provide a program code data processing method and device, electronic equipment and storage medium to improve the efficiency of analyzing the business functions affected by the code modification and improve the analysis accuracy of the business impact.
[0004] In a first aspect, an embodiment of the present disclosure provides a program code data processing method, which includes: obtaining first running data generated by a server running a first version of target program code; obtaining a target execution statement from the first running data, and determining a code calling chain corresponding to the target execution statement based on the first running data; the code calling chain is used to indicate a plurality of functions required to execute the target execution statement and a calling relationship of the plurality of functions; and determining code difference data of the functions indicated by the code calling chain based on a second version of the target program code and the first version of the target program code.
[0005] In a second aspect, an embodiment of the present disclosure provides a program code data processing device, which includes: a running data obtaining module configured to obtain first running data generated by a server running a first version of target program code; a code calling chain generating module configured to obtain a target execution statement from the first running data, and determine a code calling chain corresponding to the target execution statement based on the first running data; the code calling chain is used to indicate a plurality of functions required to execute the target execution statement and a calling relationship of the plurality of functions; and a code difference data determining module configured to determine code difference data of the functions indicated by the code calling chain based on a second version of the target program code and the first version of the target program code.
[0006] In a third aspect, the method embodiment provides an electronic device, comprising a processor and a memory, the memory storing machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned program code data processing method.
[0007] In a fourth aspect, the method embodiment provides a machine readable storage medium, the machine readable storage medium storing machine executable instructions, and the machine executable instructions, when invoked and executed by a processor, cause the processor to implement the above-mentioned program code data processing method.
[0008] The method embodiment brings the following beneficial effects:
[0009] The above-mentioned program code data processing method, device, electronic device and storage medium, obtain first running data generated by a server running a first version of target program code; obtain a target execution statement from the first running data, determine a code call chain corresponding to the target execution statement based on the first running data; the code call chain is used to indicate a plurality of functions required to be called when executing the target execution statement, and a calling relationship of the plurality of functions; determine code difference data of the functions indicated by the code call chain based on the second version of target program code and the first version of target program code. In this way, the user can clearly understand the code execution process of the preset requirement affected by the modified function by viewing the code call chain, which improves the efficiency of analyzing the business function affected by the code modification, and the code call chain is generated based on the running data of the server, so the code call relationship is more accurate, thereby improving the analysis accuracy of the business impact effect.
[0010] Other features and advantages of the present disclosure will be set forth in the following description, and in part will become apparent to those skilled in the art from the description, or can be learned by practice of the present disclosure. The objects and other advantages of the present disclosure will be realized and achieved by the structures particularly pointed out in the description, claims and drawings.
[0011] In order to make the above-mentioned objects, features and advantages of the present disclosure more obvious and easy to understand, the following will specifically describe a preferred embodiment, and the accompanying drawings will be described in detail as follows. BRIEF DESCRIPTION OF DRAWINGS
[0012] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present disclosure, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.
[0013] Figure 1A flowchart of a processing method of program code data provided by an embodiment of the present disclosure;
[0014] Figure 2 A flowchart of a code call chain collection timing task execution work process provided by an embodiment of the present disclosure;
[0015] Figure 3 A flowchart of a code call chain collection timing task execution work process provided by an embodiment of the present disclosure;
[0016] Figure 4 A schematic diagram of a code call chain map generation timing task execution work process provided by an embodiment of the present disclosure;
[0017] Figure 5 An effect display diagram of a code call chain relationship provided by an embodiment of the present disclosure;
[0018] Figure 6 A flowchart of a function code DIFF update timing task timing execution updating each function call node code DIFF and modification state process provided by an embodiment of the present disclosure;
[0019] Figure 7 A tree structure schematic diagram of a file syntax tree provided by an embodiment of the present disclosure;
[0020] Figure 8 A structural schematic diagram of a program code data processing apparatus provided by an embodiment of the present disclosure;
[0021] Figure 9 A structural schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0022] In order to make the objectives, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions of the present disclosure will be described below in connection with the drawings, obviously, the described embodiments are some but not all of the embodiments of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present disclosure.
[0023] Game economy is the most core system of network game, game economy is manifested as the output and consumption of each virtual prop in the game operation process, once the virtual prop output or consumption is abnormal in the operation period of the game, it will cause a major operation accident, and seriously affect the game reputation and vitality, and the virtual prop output and consumption involves each link in the game running process, under the background of increasingly complex and high frequency iteration of network game system function, the risk of game economy system accident in operation period has been the biggest.
[0024] A major problem in daily development and testing of virtual prop production and consumption is that the game server's basic business code is associated with the production and consumption of virtual props. The agile development characteristics of network games result in a large amount of business code modification on a daily basis, and it is difficult to achieve full testing. Therefore, it is necessary to accurately analyze which code changes will affect the game economy system and conduct detailed testing of the affected code. Currently, there are many code change confirmation methods in the industry, but they are mainly based on code file text comparison for code change analysis, which is difficult to intuitively determine the indirect impact of business functions caused by code modification. Even some methods analyze the upstream and downstream call relationships of code modification to analyze the impact range through code syntax tree analysis, but static file syntax parsing cannot accurately analyze the game business logic developed mainly in dynamic languages such as scripts. Therefore, the above methods cannot accurately and efficiently determine the impact range of code changes on the game economy system.
[0025] Based on this, the method provided by the embodiment of the disclosure provides a program code data processing method, device, electronic equipment and storage medium, which can be applied to a scene requiring program code data processing.
[0026] Referring to Figure 1 , first, a program code data processing method provided by the method embodiment is introduced. The method includes the following steps:
[0027] Step S102, obtaining first running data generated by a server running a first version of target program code.
[0028] The above-mentioned server can be various, such as a virtual host, a virtual private server (Virtual Private Server, VPS), a cloud server, or a special server for business settings, etc., which is not limited here.
[0029] The above-mentioned target program code usually refers to a source file written by a programmer using a language supported by a development tool, or a source file generated by an artificial intelligence system through a development tool, which is not limited here. The language of the target program code can be various, and can be Java, C language, C++, Python, JavaScript, etc. These languages have different characteristics and are suitable for different development needs, which are not limited here.
[0030] The target program code is essentially a clear rule system that represents information in discrete form by characters, symbols or signal elements. The server can process business data using the rules represented by the target program code after running the target program code.
[0031] After the target program code is generated, a related person can modify the target program code to change the processing logic of the business data according to a requirement. In order to facilitate the recording of the modification of the target program code and the tracing of the code by the related person, a version number is usually set for the target program code. The version numbers of the modified target program code and the program code before the modification are usually different, that is, the versions are different.
[0032] The server generates running data in the process of running the target program code of the first version. The running data usually includes execution statements generated when the target program code is run, call stack information of the code positions of the execution statements, database names where the execution statements are located, database table names, and the like. Among them, the execution statement refers to a statement that instructs the computer to complete a certain operation. These running data can be recorded in the form of a log.
[0033] When only part of the running data related to the execution statements is needed, related functions can also be set before and after the execution statements to capture the running data related to the execution statements. For example, a hook function can be set, and when the required execution statement is executed, the hook function obtains the running data related to the execution statement.
[0034] In step S104, the target execution statement is obtained from the first running data, and based on the first running data, a code call chain corresponding to the target execution statement is determined. The code call chain is used to indicate a plurality of functions required to be called to execute the target execution statement and a call relationship between the plurality of functions.
[0035] The above target execution statement is usually set based on a preset requirement. For example, the requirement is to determine the frequency of use of a certain business processing mode, and the above target execution statement can be an execution statement generated by running a part of the program code for implementing the business processing mode. As described above, when the target program code is used to implement a game system, the preset requirement can be to determine the output and consumption of virtual props. The related information of the virtual props is usually stored in a database, and if the output and consumption of the virtual props need to be implemented, a write operation needs to be performed on the related data of the virtual props in the database, which can include deletion, writing, and the like. At this time, the target execution statement can be an execution statement for performing a write operation on the database data.
[0036] The related running data of the target execution statement can be obtained from the first running data, and based on the related running data, the functions required to be called to execute the target execution statement are determined. Generally, the execution of the target execution statement usually requires the calling of a plurality of functions. The call relationship between the plurality of functions can also be determined based on the related running data of the target execution statement, and the call relationship can reflect the call relationship between the functions.
[0037] After determining that the execution of the target execution statement generally requires the calling of multiple functions and the calling relationship between the functions, a node corresponding to each function can be generated. The nodes are connected according to the calling relationship, thereby generating a code calling chain. Generally, the last node of the code calling chain can also be generated based on the target execution statement.
[0038] In step S106, the code difference data of the function indicated by the code calling chain is determined based on the target program code of the second version and the target program code of the first version.
[0039] When the target program code is modified to generate the target program code of the second version, the code difference data of the function corresponding to the node in the code calling chain can be determined based on the target program codes of the two different versions.
[0040] First, the files related to the function corresponding to the node in the code calling chain can be determined from the files of the target program code of the second version. Then, the files are compared with the corresponding files of the target program code of the first version, i.e., the files of the target program code of the first version corresponding to the function corresponding to the node in the code calling chain. Based on the comparison result, it is determined whether the function is modified, and if the function is modified, the code difference data of the function is determined.
[0041] First, the difference between the two versions of the target program code can be determined, generally, the files modified in the second version relative to the first version need to be determined. Then, the files related to the function corresponding to the node in the code calling chain are determined from the files. Further, the files corresponding to the files in the first version are compared with the files in the second version that have been modified and are related to the function corresponding to the node. The code difference data of the function can be determined based on the comparison result.
[0042] If the file related to the function corresponding to the node in the code calling chain cannot be found in the second version, it is generally considered that the function has been deleted. At this time, the function needs to be deleted from the code calling chain, and the connection relationship of each node of the code calling chain is further adjusted.
[0043] The method for processing program code data provided in the preceding method comprises: obtaining first running data generated by a server running a first version of target program code; obtaining a target execution statement from the first running data; determining a code call chain corresponding to the target execution statement based on the first running data; the code call chain is used to indicate a plurality of functions required to be called to execute the target execution statement and a calling relationship of the plurality of functions; and determining code difference data of the functions indicated by the code call chain based on the second version of target program code and the first version of target program code. In this way, the user can clearly understand the code execution process of the preset requirement affected by the modified function by checking the code call chain, and the efficiency of analyzing the business function affected by the code modification is improved. Moreover, the code call chain is generated based on the running data of the server, and the code call relationship is more accurate, thereby improving the analysis accuracy of the business impact effect.
[0044] The following embodiments provide a specific method for determining a code call chain corresponding to a target execution statement based on first running data.
[0045] In actual application, the first target node can be generated based on the target execution statement. The target execution statement is usually implemented by a function, and the first target node can be considered to be established for the function implementing the target execution statement. Then, a plurality of first functions are determined based on the first running data. The first functions are called before the target execution statement is executed. Then, a second target node is generated based on the first functions. Generally, a second target node needs to be generated for each first function. That is, different second target nodes in the code call chain correspond to different functions. Finally, the code call chain corresponding to the target execution statement is generated based on the first target node, the second target nodes and the calling relationship of the plurality of first functions.
[0046] In practical applications, there can be a case that a function is called by multiple functions, or a case that a function calls multiple functions. For example, a possible function calling process 1 for a target specified statement is as follows: function 1 calls function 2, function 2 calls function 3, and function 3 calls a function for implementing the target specified statement; a possible function calling process 2 is as follows: function 4 calls function 2, function 2 calls function 3, and function 3 calls a function for implementing the target specified statement; a possible function calling process 3 is as follows: function 5 calls function 3, and function 3 calls a function for implementing the target specified statement. For the above three calling processes, a second target node corresponding to function 1, function 2, function 3, function 4 and function 5 needs to be generated, which are respectively referred to as node 1, node 2, node 3, node 4 and node 5; a first target node corresponding to the function for implementing the target specified statement needs to be generated, which is referred to as node 6. Based on the above three function calling processes, a corresponding code calling chain can be generated. In the code calling chain, function 2 is called multiple times, and function 3 is also called multiple times, so the corresponding nodes are connected to multiple nodes. This code calling chain can also be referred to as a code calling graph.
[0047] The functions involved in the function calling process of the above target execution statement and the related data of the corresponding code calling chain can be stored in a specified server. The user can control the terminal device to request these data from the server, and based on these data, the code calling chain (code calling graph) can be displayed on the image user interface provided by the terminal device. The user can send a certain function to the server through the terminal device, and the server can return the part of the code calling chain data related to the node corresponding to the function in the code calling chain to the user. The user can also send a target execution statement to the server through the terminal device, and the server can return the part of the code calling chain data related to the node corresponding to the target execution statement in the code calling chain to the user. The user can click a certain node in the code calling chain displayed on the graphical user interface to display the program code of the function corresponding to the node, such as the current version of the program code, the previous version of the program code, etc.
[0048] In the process of generating the first target node, the target execution statement can be parsed first to obtain a parsing result; the parsing result includes the syntax structure of the target execution statement. In specific implementation, a pre-trained statement parsing module can be used for lexical analysis, and finally a syntax tree is generated, which records each keyword, field, parameter, operator symbol, identifier, etc. in the syntax structure of the statement, and can be used to extract the operation of the statement execution, the table, field, parameter value, and condition of the statement operation, and other check information. After generating the syntax tree, the variable parameter value in the syntax tree is replaced by a placeholder, and then the syntax structure of the database execution statement is reconstructed in reverse. Further, the first target node can be generated based on the parsing result. In actual application, the processing process of a certain business data can be implemented by different target execution statements, and the parameters of these target execution statements are different, but the syntax structures are usually the same. For example, in a game, game tokens can be issued to different players through database execution statements; the syntax structure of the database execution statement for issuing game tokens is the same except that the parameters representing the player identifier and the token quantity are different, and the execution statements of the two execution behaviors can be classified into the same first target node.
[0049] When the target execution statement includes multiple database execution statements, the parsing result usually further includes the database operated by the database execution statement. In the case where the first target node has been generated based on the parsing result of the first database execution statement in the multiple database execution statements, if the syntax structure of the second database execution statement in the multiple database execution statements is the same as that of the first database execution statement, and the database operated by the second database execution statement is the same as that of the first target execution statement, the first target node corresponding to the first database execution statement can be determined as the first target node corresponding to the second database execution statement, so that a new target node does not need to be generated. The node corresponding to the function called for executing the second database execution statement can be connected to the first target node.
[0050] When the target execution statement includes a database execution statement, i.e., an execution statement for operating data in a database. The parsing result further includes the database operated by the database execution statement and the corresponding data processing operation. When the requirement is to determine the output and consumption of virtual props, a write operation needs to be performed on the corresponding data in the database storing the data of the virtual props, which can specifically include deletion, writing, etc. At this time, it is necessary to determine whether the database operated by the database execution statement is a preset database. The preset database is the database storing the data of the virtual props. If yes, it is necessary to determine whether the data processing operation corresponding to the database execution statement is a data write operation; if it is a write operation, the first target node is generated based on the parsing result.
[0051] To facilitate the user to further understand the calling relationship between the functions based on the code calling chain, and the function to the target execution statement, for each first target node, a first called node list corresponding to the first target node can be determined. The first called node list includes a second target node calling the first target node, that is, a second target node directly connected with the first target node from the code calling chain. For each second target node, a second called node list corresponding to the second target node and a calling node list need to be determined. The second called node list includes other second target nodes calling the second target node, that is, other second target nodes directly adjacent to the second target node, and the calling relationship is before the second target node. The calling node list includes other second target nodes called by the second target node, and can also include the first target node.
[0052] As described above, the code calling chain can be displayed in a graphical manner on the graphical user interface. For the node of the code calling chain, the called list, the calling list and the like of the node can be displayed around the node. The display area where each node in the graphical user interface is located can also be set to be touchable. When the user clicks the display area, the detail window corresponding to the node is displayed on the graphical user interface, and the called list, the calling list and the like of the node can be displayed in the detail window. Through the above manner, the user can quickly understand the calling situation of the node.
[0053] The following embodiments provide a specific manner of determining the code difference data corresponding to the function indicated by the code calling chain based on the target program code of the second version and the target program code of the first version.
[0054] As described above, the code calling chain includes a plurality of nodes, and each node has a corresponding function. The target program code usually includes a plurality of files. To determine the code difference data corresponding to the function indicated by the code calling chain, the files of the target program code of the second version can be compared with the files of the target program code of the first version first; based on the comparison result, the modified files in the files of the target program code of the second version are determined, that is, the files having modifications relative to the corresponding files in the first version. Then, based on the functions corresponding to the nodes of the code calling chain, the target files in the modified files are determined. These target files usually record the related parameters of the functions corresponding to the nodes of the code calling chain, or the program code implementing the functions. Further, based on the target files and the corresponding files in the target program code of the first version, the code difference data corresponding to the function indicated by the code calling chain can be determined.
[0055] After the target file is determined, for each function indicated by the code call chain, the target file corresponding to the function is searched from the target file. If the target file is searched, it indicates that the function still exists in the second version of the program code, and at this time, the code difference data corresponding to the function can be determined based on the searched target file and the corresponding file of the function in the target program code of the first version. If the target file is not searched, it can be considered that the function has been deleted in the second version of the target program code, and at this time, the node corresponding to the function in the code call chain needs to be deleted, and the code call chain is updated.
[0056] After the node corresponding to the function in the code call chain is deleted, it is also necessary to check the nodes originally connected to the deleted node in the code call chain. For convenience of writing, the nodes are referred to as related nodes. If the related node corresponds to a function for implementing the target execution statement, and there is no other node connected to the related node except the deleted node, the related node needs to be deleted. If the related node does not correspond to a function for implementing the target execution statement, and there is no other node called by the related node, the related node also needs to be deleted. If the related node is deleted, the nodes connected to the related node need to be considered until there is no node to be deleted.
[0057] As described above, the nodes in the above code call chain usually have a call list and / or a call list. The call list and the call list can be collectively referred to as a related node list, and the related node list includes other nodes called by the node and other nodes calling the node. After a certain node is deleted, it is necessary to determine the related node of the deleted node. The related node list of the related node includes the deleted node, that is, the related node originally calls the deleted node, or the deleted node calls. Then the deleted node needs to be deleted from the related node list of the related node. In some cases, the related node may also need to be deleted, and then it can be first judged whether the related node needs to be deleted, and then the deleted node is deleted from the related node list of the related node in the case that the related node does not need to be deleted.
[0058] The server generates a large amount of running data during running, and the running data generated at different time periods is usually different. If the code call chain is generated based on the running data generated at one time period, the code call chain is usually incomplete. The running data usually includes a plurality of specified execution statements. The plurality of specified execution statements can be sequentially stored in a preset cache queue according to the generation order. The cache queue can be set in the server or in other databases, which is not limited here. When the code call chain is generated, a time parameter can be set for it. The time parameter indicates the generation time of the running data used to generate the code call chain.
[0059] To ensure the code call chain covers a more complete call process of the target execution statement, second execution data can be read from the cache queue. The generation time of this second execution data must be later than the code call chain time parameter. Then, the code call chain is updated based on the second execution data. If the function call relationships during the call process of the target execution statement change, or if other functions appear during the call process of the target execution statement, the code call chain needs to be updated. Simultaneously, the time parameter of the updated code call chain is updated to the generation time of the second execution data, facilitating subsequent readings of cached execution data and updates to the code call chain.
[0060] During the code call chain update process, multiple second functions can be identified based on the second execution data. Similar to the first function, the second function is also called before the target execution statement is executed. If the current code call chain does not include a third function among the multiple second functions, a third target node is generated based on the third function; furthermore, the code call chain needs to be updated based on the third target node. At this point, the code call chain also includes cases where the target execution statement is called through the third function.
[0061] This disclosure also provides another method for processing program code data. This method... Figure 1 This method is implemented based on the method shown. Taking game program code as an example, it provides a way to collect and establish a code call chain graph related to the game's economic system in real time during server operation. Functions are used as unit nodes on the call chain graph. Based on the call chain graph, it is possible to analyze precisely whether a code change to a certain function affects the game's economic system, and through which upstream and downstream call chains the game's economic system is affected. This makes it convenient for testers to design targeted test cases to cover all the impacts of code changes on the game's economic system, and also makes it convenient for developers to accurately and reliably review the game's economic functions affected by code changes.
[0062] Since the essence of changes in the game's economic system is the production and consumption of various in-game items and resources, the production and consumption process of each player and each type of game item will have corresponding database table records modified, which means there will be corresponding database execution statements executed. Therefore, this method uses the execution of database execution statements as the target endpoint to establish the code call chain graph of the entire game.
[0063] This method is implemented in the following ways:
[0064] The server code version used in the development test link adds a hook in the underlying interface of the database execution statement, that is, the event listener callback interface triggered by the hook before and after the execution of the database execution statement in the server running process to realize the statistics of the running data of the database execution statement execution process. The data includes the database name, database table name, execution statement string, call stack information of the execution statement code position, etc.
[0065] Each piece of database execution statement running data collected by the server running process is output to the pending cache queue in real time for subsequent processing. The cache queue can be built using a cache service such as Redis.
[0066] This method needs to deploy a code call chain collection timing task, which has the permission to access the cache queue. The timing task processes the running data of each database execution statement by periodically starting and running. The timing task processes the data according to a certain processing limit each time it runs, and the data is removed from the cache queue after processing.
[0067] This method only processes data statement execution that affects the economic system, so it needs to configure the database tables related to the game economic system in advance. Generally, it is the table that records the number of virtual props of each account in the game. Other tables related to the output and consumption of valuable props in the game and accounting are also related to the economic system. Record the corresponding tables in the running configuration of the timing task.
[0068] This method needs to deploy a timing task for generating an economic system code call chain map. The task starts the call chain collection timing task to add the database execution statement execution unit and the associated code call chain generated by the processing, analyzes the content related to the game economic system, and incrementally processes the related code call chain, which is merged into the existing code call chain map. The processing flow includes:
[0069] The timing task is started and run at regular intervals. Before execution, the timing task records the time point of this execution, which is used to incrementally extract the code call chain data collected since the last execution time point for call chain map calculation. During calculation, the database execution statement execution unit and the corresponding code call chain list of each table updated since the last execution time point are queried from the background database according to the configured economic system database table.
[0070] This method will deploy a Web service site for graphical viewing of the call chain map from the web front end. Each node of the map is saved in the Web service site background database. Users can query the complete call chain map relationship network through the front-end web page, or specify the call function and database table to query the associated map relationship network.
[0071] The method needs to deploy a function code DIFF update timing task based on the established call chain map, for checking whether each function node in the map has changed compared to the code content of the baseline code version, and the code DIFF result of the specific function code content, and uploading the code DIFF content to the function node in the map for the function node with code DIFF.
[0072] The method extracts and generates code DIFF of the specific function code content under the specific class definition in the code file by incrementally obtaining files with code changes and parsing the code syntax tree.
[0073] The method is introduced by taking a MySql type relational database as an example, and other relational database types such as Oracle, PostGres, and non-relational databases such as Mongo also meet the implementation process of the method.
[0074] When the embodiment is implemented, one or more development and test servers that need to collect database execution statements for checking need to be added to support real-time collection of server access to databases, execution of database execution statement contents and related running data. In this embodiment, a hook is added to the underlying interface of the server code that executes the database execution statement, that is, an event listener callback interface triggered by the hook before and after the execution of the database execution statement in the server running process is used to realize the statistics of the running data of the database execution statement execution process. The statistical content includes the database name where the database execution statement is located, the database execution statement content and the current call stack information of the database execution statement call position, etc.
[0075] The data collected during the execution of each database execution statement is used as an independent database execution statement data unit, and the packaged data content is temporarily stored in the designated cache of each server. The saving method can be a server local log file record, a cache service such as Redis, etc. In this embodiment, the database execution statement data unit collected by each server is output to the local Redis in the key value of the list type of the specified cache check data.
[0076] When the embodiment is implemented, a code call chain processing platform needs to be independently deployed. The platform includes an HTTP service site that can support user access to the platform through a browser front end to view the code call chain map. The platform background also deploys a series of timing tasks to collect and process the database execution statement data generated by each game server, generate the code call chain map, and update the code change information, etc.
[0077] The call chain processing platform comprises a code call chain collection timing task for periodically executing the database execution statement data unit cache of each server that has started the statement collection function, and parsing and classifying the database execution statement execution unit and the associated code call stack information into the platform background database.
[0078] The call chain processing platform comprises a code call chain graph generation timing task for periodically executing the incremental processing of the database execution statement execution unit and the associated code call stack information, generating the function call node and the database execution unit node in the code call chain graph and the call relationship therebetween, and merging into the existing graph, and the graph node related data information is saved in the platform background database.
[0079] The call chain processing platform comprises a function code DIFF update timing task for checking whether each function node in the graph has changed compared with the code content of the benchmark code version, and the code DIFF result and state of the specific function code content, and saving the record to the graph node database associated information.
[0080] The embodiment realizes the establishment of the code call chain graph related to the game economic system, and is realized by the following modes:
[0081] 1. A hook is added in the server bottom layer database access interface of the development and test type server that needs to collect the database execution statement of the server, so that the database execution statement and the running data content after each statement execution are obtained, including the database name where the statement is executed, the database execution statement content and the current call stack information of the database execution statement call position. The above-mentioned content is packaged into an independent database execution statement data unit, and is cached in the specified Redis service of the server local specified Redis key value of the type list for saving.
[0082] 2. A code call chain processing platform is deployed on a fixed machine, and a code call chain collection timing task is deployed in the platform background. The task comprises a data acquisition module and a data processing module. The data acquisition module is responsible for acquiring a certain number of database execution statement data units from each server in the storage order after the process is started, and saving them in the local to-be-processed data queue in the order of acquisition. After the data acquisition of all servers is completed, the data processing module is responsible for batch processing the data units in the to-be-processed queue. The database execution statement execution unit and the associated code call stack information generated after the processing are saved in the background database of the platform.
[0083] Referring to Figure 2 is a step flowchart of the execution process of the code call chain collection timing task in the embodiment, and specifically comprises the following contents:
[0084] 1 The platform is pre-configured with the IP, port, and account password of each server's Redis service to be collected, and other information such as configuration is configured locally, corresponding to each server identification information. The data acquisition module of the timing task is built-in a Redis client. After the timing task is started, the server Redis connection information is connected to each server Redis in order, and the database execution statement data unit content of a certain number of entries is pulled to the platform local pending queue according to the configured threshold each time the operation is performed, and the data unit that has been acquired is deleted from the server Redis at the same time.
[0085] 2 The platform is pre-configured with the database table belonging to the economic system in the game server database. Generally, it is the table that records the number of each virtual prop of each account in the game. Other tables related to the output and consumption of valuable props in the game and the accounting-related tables also belong to the economic system-related tables. The table name is recorded in the platform local background configuration file, and the data processing module of the timing task takes out each data unit in the pending queue for processing.
[0086] Referring to Figure 3 is the code call chain collection timing task processing each database data unit step flowchart in this embodiment, which specifically includes the following contents:
[0087] 1 For each database execution statement unit to be processed, the database execution statement in the running data is first extracted. The database execution statement is parsed by the statement parsing module, and finally a syntax tree is generated. The syntax tree records each keyword, field, parameter, operator, identifier, etc. in the statement syntax structure, which can be used to extract the operation of the statement execution, the table, field, parameter value, and condition of the statement operation, etc. syntax information.
[0088] After generating the syntax tree, the variable parameter value in the syntax tree is replaced by a placeholder, and then the database execution statement syntax structure information is generated by reverse reconstruction. The generated syntax structure information is a placeholder that replaces the value of the variable parameter in the original statement, such as?, which only retains the syntax information in the original statement. If the statement has a variable parameter list, it can also be classified, such as?...?, which represents a variable parameter list. The purpose is to classify and aggregate different database execution statements if only the variable parameter value is different. The following is an example of a SQL statement analysis.
[0089] The SQL statement is select*from tbname where field1=5and field2='string'. After syntax tree parsing, the syntax tree diagram can be extracted
[0090] When reconstructing the syntax structure through the syntax tree, the variable parameter value such as the Integer and Single type variable parameter node can be replaced with a placeholder, that is, select*from tbname where field1=?and field2=?.
[0091] 2Here, for each database execution statement syntax structure collected, it is first determined whether it belongs to a database operation that affects the economic system. First, it is determined whether the database table of the operation belongs to the table configured in advance that belongs to the economic system. If yes, it is determined whether the database operation belongs to a write operation, including insertion, update, deletion, etc. If yes, the next step is processed. Otherwise, it is a non-economic system table or a read-only database execution statement structure, which is skipped and not processed.
[0092] For the database execution statement to be processed, the database name, database table name, and syntax structure information corresponding to the statement are combined as a unique index identifier to create a database execution statement execution unit. That is, when processing different data, if the database name, database table name, and syntax structure information extracted during data extraction are the same, they are classified into the same database execution unit. Other information collected during data processing is also classified into the same execution unit.
[0093] 3When processing data, the code call stack of the database execution statement execution position is also extracted. From the call stack, the function call chain during code execution can be completely obtained. The effective information of each node on the call chain is extracted, including the code file name, class name, function name, and call relationship before and after, packaged into a Json data format, and associated with the corresponding database execution unit for saving.
[0094] 4The database execution unit data is recorded in the platform background database and assigned a unique ID marker. The code call chain data associated with each execution unit is also stored in the database and records the associated execution unit ID. During task collection and processing, the same code call chain data corresponding to the same execution unit will only be saved in the database once. If the code call chain is different, it will be saved separately. One execution unit can be associated with multiple code call chains. The database also has a field to record the collection time of the code call chain data. When the task collects repeated code call chain data, it only needs to update the latest collection time in the already stored database record.
[0095] This embodiment needs to continuously build a code call chain graph of the game economic system, and each function call and database execution statement execution unit associated with the economic system in the graph is changed into a graph node and displayed in the graph, and the connection between the nodes is used to represent the mutual calling relationship of the function call nodes. Here, a timing task for generating the code call chain graph of the economic system is deployed, and the task is started to collect the database execution statement execution units and associated code call chains generated by the new processing, analyze the content related to the game economic system, incrementally process the related code call chains, and merge them into the existing code call chain graph.
[0096] Referring to Figure 4 is a step flowchart of the execution process of the graph generation timing task in this embodiment, and the specific steps are as follows:
[0097] 1. The timing task is started and run at a regular time, and before the timing task is executed, the time point of this execution is recorded once, and recorded in the platform background database, which is used to incrementally extract the code call chain data collected at a time greater than the last execution time point for the next execution to calculate the call chain graph. During the calculation, the database execution statement execution units and corresponding code call chain lists of each table updated incrementally since the last execution time point are obtained from the background database according to the configured economic system database table, and the node and connection relationship in the call chain graph are generated by subsequent processing.
[0098] 2. For the execution unit to be processed, first determine whether the execution unit has been recorded in the existing call chain graph. The recording method is to record a node record of the associated execution unit ID in the database graph node table. If the record has been saved, no additional new node needs to be created. If not, a new execution unit node is created in the graph table, and the ID of the execution unit is associated.
[0099] 3. The code call chain list is incrementally collected for the execution unit to be processed, and each call chain is processed to generate a function call node and a connection relationship, which is also saved in the graph node table. A unique index identifier is composed of the file name, class name, and function name of the call node. Each call function on the code call chain has a corresponding node in the graph. If the graph already has a node with the same unique index identifier of the function, no additional node needs to be created, and a node needs to be created. If not, a function call node is created, a unique index identifier is established, and a unique ID of the node is allocated.
[0100] 4After creating each function call node in the call chain, the calling and called relationship between each function node is recorded according to the calling relationship before and after the call chain. The recording method is that each function call node will additionally record two attributes, one is the called node list, and the other is the call node list. The called node list records the node ID list of all other nodes that call this node in the total graph, and the call node list records the node ID list of other nodes called by this node in the total graph. The last function call node in each call chain will additionally record a corresponding database execution unit node ID in the call list. The database execution unit node also has a called node ID list, which records the function node ID that calls it. In the graph, it is represented as: the last function node called in each code call chain finally calls the database execution statement of the database execution node.
[0101] The function call chain graph generated in this embodiment constitutes a complete code call relationship network. As long as the server runs the database operation that changes the economic system, the nodes on his entire call chain will be added to the graph. Through the calling and called relationship network of each node, it can be directly queried from the graph that a certain database table is modified, which can be caused by which function node. It can also be directly analyzed that a certain function has code modification, and from his call relationship network, it can also be directly queried that his modification will affect which database operation and thus may cause an impact on the economic system.
[0102] The code call chain graph constructed in this embodiment can be accessed and viewed by users through the HTTP service site of the call chain processing platform accessed by the front-end browser. The HTTP service will search the graph node database data from the background database according to the user query condition, and generate a directed graph data structure, which is displayed in a graphical way in the user's front-end browser interface. Users can query the complete call chain graph relationship network through the front-end web page, or specify the call function, database table or database execution statement unit to query the associated graph relationship network. The front-end display will display each node in the form of a graphical node, and the nodes with direct calling relationship will be connected by an arrow line between two nodes. The graph interface node also supports free dragging and zooming. The front-end graphical display function can be realized by using the open source and popular X6 graphical editing engine.
[0103] The effect display diagram of querying all associated code call chain relationships of a certain database execution statement execution unit in the graph is shown in Figure 5 .
[0104] By Figure 5As can be seen directly, the database execution statement execution unit of the specified query belongs to the final node in the tree structure of the call chain, and all function calls directly or indirectly affecting this database execution statement execution unit can be intuitively displayed through nodes and link relationships in the graphical structure, so that the user can clearly know which code calls will affect the database modification operation of the economic system.
[0105] On the basis of establishing the call chain graph, the embodiment also needs to deploy a function code DIFF update timing task for checking whether the code content of each function node in the graph has changed compared with the code content of the benchmark code version. Therefore, the embodiment needs to deploy two code version directories in the background of the platform, one is the working version updated in real time, which is generally the code version currently in continuous development and update, and the other is the stable benchmark version for comparing whether there is code change, which is generally the version currently in stable operation.
[0106] The function code DIFF update timing task of the embodiment aims to update the function definition code of each function call node in the entire code call chain graph in real time, calculate the DIFF difference of the code content in the working version and the basic version, and upload the difference situation and difference content to the record in the database corresponding to the function node in the code call chain graph. Users can intuitively understand and view whether each function call node has code change in the current working version compared with the benchmark version.
[0107] The embodiment deploys a working code version directory and a benchmark code version directory in the background of the platform in advance, and deploys a function code DIFF update timing task. The task updates the working code version directory in real time, incrementally checks and updates the DIFF result and change status of the function definition code of each function call node in the code call chain graph in the working version and the benchmark version. If there is code DIFF, the function node needs to upload the code DIFF content to the function node in the graph, and mark the function node as a code modification state. If there is no corresponding function in the benchmark code version, the node state is marked as new. If the function node has been created in the graph, it has been deleted in the latest code version, and the node is deleted from the node database in the graph, and all other nodes related to the deleted node are refreshed, and the ID of the deleted node is removed from the list.
[0108] Referring to Figure 6 is a step flowchart of the function code DIFF update timing task of the embodiment for updating the code DIFF and modification state of each function call node in real time, which specifically includes the following contents:
[0109] 1. The timing task is started in time, the working version directory is updated to the latest version through version control software such as Svn / Git / P4, etc., and the version number is recorded in the platform background database. Then, the current version is compared with the last update version number recorded in the background database, the file list of the code changes between the two version numbers is extracted incrementally, and all function call nodes belonging to the above changed file list are queried from the graph database. In the specific implementation, according to the last execution record of the code version number, the file list of the code changes between the two version numbers is extracted incrementally, and all function nodes belonging to the current modified file list are queried from the graph node library.
[0110] 2. The code modification state and code DIFF content of each function node are checked and updated one by one. For the function node to be processed, the corresponding latest version code file and the reference version code file for comparison are first obtained. The syntax tree of the latest code file and the syntax tree of the reference code file are parsed respectively, and the syntax tree records the specific position of each class definition and the specific position of each function under the class definition, including the starting line number and the ending line number. The position of the function node is found through the syntax tree, and then the code segment text content of the function definition is extracted from the latest code file and the reference code file according to the position. Then, the code DIFF of the two texts is calculated to determine whether the code modification state of the function node belongs to no change or modification. If the function is found in the latest code file syntax tree but not in the reference code file syntax tree, it is determined that the function node code modification state is added. Otherwise, it is deleted.
[0111] Each programming language supports parsing the syntax tree of the code file. The syntax tree represents an independent syntax tree in units of files. Each class definition and function definition inside the file is saved in the syntax tree in the form of a node, and each class definition and member function definition inside the class definition can be found in the code file through node traversal, as shown in Figure 7
[0112] For the function call node that needs to be updated, the class name and function name of the called function are obtained from the node, and the corresponding class name and function name syntax tree nodes can be found through node traversal in the corresponding file syntax tree. The syntax tree node records the starting line number and ending line number of the function in the code file, and the code content of the function can be accurately extracted from the code file text through the two line numbers.
[0113] When searching for the function syntax tree node corresponding to the call function node in the syntax tree, the following situations are divided:
[0114] If the function call node exists in the syntax tree of both the working version and the benchmark version, the function definition code content of each is extracted, and the two texts are DIFFed using a common text DIFF algorithm. If there is no DIFF, it indicates that the function has not changed in the working version and the benchmark version file, and the function node modification state is marked as unchanged. If there is a DIFF, it indicates that the function definition content has changed in the working version compared to the benchmark version, and the function node modification state is marked as modified, and the DIFF content is recorded.
[0115] If the function call node exists in the working version but cannot be obtained in the benchmark version, it is determined that the function node is a newly added function, and the function node modification state is marked as added.
[0116] If the function call node exists in the benchmark version but cannot be obtained in the working version, it is determined that the function node has been deleted in the latest working version, and the function node modification state is marked as deleted.
[0117] 3The calculated function node modification state and DIFF result are synchronized and uploaded to the database record corresponding to the function call node in the call chain graph, and finally in the call chain graph, each function call node is marked with a code modification state, which is unchanged, added, modified, and deleted. Users can click to view the details of each function call node through the front-end web page display, and the details include basic information such as the code file and class to which the node belongs, the code content of the function, and the DIFF result compared with the benchmark version. Users can also set the confirmation state of the node that has been checked and confirmed through the front-end web page.
[0118] For functions that have been deleted in the working version, users can also remove the deleted function call node from the call chain graph through front-end operations. When removing, the calling and called relationships between the node and other nodes on the upstream and downstream call chains are first removed from the graph, and then the corresponding function node record is deleted from the graph node database.
[0119] For nodes that have been set to be confirmed, subsequent scheduled tasks will automatically reset the set confirmation state when detecting changes in the function code corresponding to the node during node update, reminding users to reconfirm.
[0120] The method embodiment adopts a code call relationship chain network generated in a server runtime code call chain manner, is more reliable and accurate than a syntax tree analysis manner commonly used in the industry, and the application method for detecting the influence behavior of an economic system by taking database operation as a target can be used not only for an economic system, but also for other systems. Finally, a graphical code call chain map is established, which not only facilitates the analysis of the influence range and the logical chain of the code change process, but also improves the efficiency and accuracy of the review.
[0121] For the above method embodiment, refer to Figure 8 The device for processing program code data comprises:
[0122] The running data acquisition module 802 is configured to acquire first running data generated by a server running a first version of target program code.
[0123] The code call chain generation module 804 is configured to acquire a target execution statement from the first running data, and determine a code call chain corresponding to the target execution statement based on the first running data. The code call chain is used to indicate a plurality of functions required to be called when executing the target execution statement, and a call relationship of the plurality of functions.
[0124] The code difference data determination module 806 is configured to determine code difference data of the functions indicated by the code call chain based on the second version of target program code and the first version of target program code.
[0125] The above device for processing program code data acquires first running data generated by a server running a first version of target program code, acquires a target execution statement from the first running data, and determines a code call chain corresponding to the target execution statement based on the first running data. The code call chain is used to indicate a plurality of functions required to be called when executing the target execution statement, and a call relationship of the plurality of functions. The code difference data of the functions indicated by the code call chain is determined based on the second version of target program code and the first version of target program code. In this way, the user can clearly understand the code execution process of the modified function affecting the preset requirements by viewing the code call chain, the efficiency of analyzing the business function affected by the code modification is improved, and the code call chain is generated based on the running data of the server, so that the code call relationship is more accurate, thereby improving the analysis accuracy of the business influence effect.
[0126] The code call chain generation module is further configured to generate a first target node based on the target execution statement, determine a plurality of first functions based on the first running data, and generate a second target node based on the first functions. The first functions are called before executing the target execution statement. The code call chain corresponding to the target execution statement is generated based on the first target node, the second target node, and the call relationship of the plurality of first functions.
[0127] The code call chain generation module is further configured to: perform parsing processing on the target execution statement to obtain a parsing result; the parsing result comprises a syntax structure of the target execution statement; and generate the first target node based on the parsing result.
[0128] The target execution statement comprises a plurality of database execution statements; the parsing result further comprises a database operated by the database execution statement and a corresponding data processing operation; the code call chain generation module is further configured to generate a first target node based on a parsing result of a first database execution statement in the plurality of database execution statements; and if a syntax structure of a second database execution statement in the plurality of database execution statements is the same as that of the first target execution statement, and a database operated by the second database execution statement is the same as that operated by the first target execution statement, the first target node corresponding to the first database execution statement is determined as a first target node corresponding to the second database execution statement.
[0129] The apparatus further comprises a first node-in-list determination module configured to determine, for each first target node, a first called node list corresponding to the first target node; the called node list comprises a second target node calling the first target node.
[0130] The apparatus further comprises a second node-in-list determination module configured to, for each second target node, generate a second called node list corresponding to the second target node and a calling node list; the called node list comprises another second target node calling the second target node; and the calling node list comprises another second target node and / or first target node called by the second target node.
[0131] In the code call chain, different second target nodes correspond to different functions.
[0132] The target execution statement comprises a database execution statement; the parsing result further comprises a database operated by the database execution statement and a corresponding data processing operation; and the code call chain generation module is further configured to: determine whether the database operated by the database execution statement is a preset database; if yes, determine whether the data processing operation corresponding to the database execution statement is a data writing operation; and if yes, generate the first target node based on the parsing result.
[0133] The code call chain includes a plurality of nodes, each node having a corresponding function; the target program code includes a plurality of files; the code difference data determination module is further configured to: compare the files of the second version of the target program code with the files of the first version of the target program code; based on a comparison result, determine modified files in the files of the second version of the target program code; based on the functions corresponding to the nodes of the code call chain, determine a target file in the modified files; and based on the target file and a corresponding file in the first version of the target program code, determine the code difference data corresponding to the functions indicated by the code call chain.
[0134] The code difference data determination module is further configured to: for each function indicated by the code call chain, find a target file corresponding to the function from the target file; if found, based on the found target file and a corresponding file in the first version of the target program code, determine the code difference data corresponding to the function.
[0135] The apparatus further includes a first code call chain updating module configured to, if not found, delete the node corresponding to the function from the code call chain, and update the code call chain.
[0136] The nodes in the code call chain have a related node list; the related node list includes other nodes called by the node and other nodes calling the node; the apparatus further includes a node list updating module configured to determine related nodes of the deleted node; the deleted node is included in the related node list of the related nodes; and the deleted node is deleted from the related node list of the related nodes.
[0137] The running data includes a plurality of specified execution statements; the plurality of specified execution statements are stored in a preset cache queue in a production order; the code call chain has a corresponding time parameter; the time parameter indicates a production time of the running data used to generate the code call chain; the apparatus further includes a running data reading module configured to read second running data from the cache queue; the production time of the second running data is later than the time parameter; a second code call chain updating module configured to update the code call chain based on the second running data; and a production event determination module configured to update the time parameter of the updated code call chain to the production time of the second running data.
[0138] The second code call chain updating module is further configured to: based on the second running data, determine a plurality of second functions; the second functions are called before the target execution statement is executed; if a third function in the plurality of second functions is not included in the code call chain, generate a third target node based on the third function; and update the code call chain based on the third target node.
[0139] The embodiment also provides an electronic device, including a processor and a memory, the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the processing method of the program code data.
[0140] obtaining first running data generated by a server running a first version of target program code; obtaining a target execution statement from the first running data, determining a code call chain corresponding to the target execution statement based on the first running data; the code call chain is used to indicate a plurality of functions required to be called when executing the target execution statement, and a calling relationship of the plurality of functions; determining code difference data of the functions indicated by the code call chain based on the second version of target program code and the first version of target program code.
[0141] In the above manner, the user can clearly understand the code execution process of the preset requirement affected by the modified function by viewing the code call chain, thereby improving the efficiency of analyzing the business function affected by the code modification, and the code call chain is generated based on the running data of the server, so that the code call relationship is more accurate, thereby improving the analysis accuracy of the business impact effect.
[0142] Optionally, the step of determining the code call chain corresponding to the target execution statement based on the first running data includes: generating a first target node based on the target execution statement; determining a plurality of first functions based on the first running data; the first function is called before executing the target execution statement; generating a second target node based on the first function; and generating the code call chain corresponding to the target execution statement based on the first target node, the second target node, and the calling relationship of the plurality of first functions.
[0143] Optionally, the step of generating the first target node based on the target execution statement includes: performing parsing processing on the target execution statement to obtain a parsing result; the parsing result includes the syntax structure of the target execution statement; and generating the first target node based on the parsing result.
[0144] Optionally, the target execution statement includes a plurality of database execution statements; the parsing result further includes a database operated by the database execution statement and a corresponding data processing operation; and the step of generating the first target node based on the parsing result includes: generating the first target node based on the parsing result of a first database execution statement in the plurality of database execution statements; and if a syntax structure of a second database execution statement in the plurality of database execution statements is the same as the syntax structure of the first target execution statement, and a database operated by the second database execution statement is the same as a database operated by the first target execution statement, determining the first target node corresponding to the first database execution statement as a first target node corresponding to the second database execution statement.
[0145] Optionally, the method further comprises: for each first target node, determining a first called node list corresponding to the first target node; the called node list comprises a second target node that calls the first target node.
[0146] Optionally, the method further comprises: for each second target node, generating a second called node list corresponding to the second target node, and a calling node list; the called node list comprises other second target nodes that call the second target node; the calling node list comprises other second target nodes and / or first target nodes called by the second target node.
[0147] Optionally, in the code call chain, different second target nodes correspond to different functions.
[0148] Optionally, the target execution statement comprises a database execution statement; the parsing result further comprises a database on which the database execution statement operates and a corresponding data processing operation; based on the parsing result, the step of generating the first target node comprises: determining whether the database on which the database execution statement operates is a preset database; if so, determining whether the data processing operation corresponding to the database execution statement is a data write operation; if so, generating the first target node based on the parsing result.
[0149] Optionally, the code call chain comprises a plurality of nodes, each node having a corresponding function; the target program code comprises a plurality of files; based on the second version of the target program code and the first version of the target program code, the step of determining the code difference data corresponding to the function indicated by the code call chain comprises: comparing the files of the second version of the target program code with the files of the first version of the target program code; based on the comparison result, determining a modified file in the files of the second version of the target program code; based on the functions corresponding to the nodes of the code call chain, determining a target file in the modified file; based on the target file and the corresponding file in the first version of the target program code, determining the code difference data corresponding to the function indicated by the code call chain.
[0150] Optionally, the step of determining the code difference data corresponding to the function indicated by the code call chain based on the target file and the corresponding file in the first version of the target program code comprises: for each function indicated by the code call chain, searching for a target file corresponding to the function from the target file; if found, determining the code difference data corresponding to the function based on the found target file and the corresponding file of the function in the first version of the target program code.
[0151] Optionally, the method further comprises: if not found, deleting the node corresponding to the function from the code call chain, and updating the code call chain.
[0152] Optionally, the node in the code call chain has a related node list; the related node list includes other nodes called by the node and other nodes calling the node; the method further includes: determining related nodes of the deleted node; the deleted node is included in the related node list of the related nodes; and deleting the deleted node from the related node list of the related nodes.
[0153] Optionally, the running data includes a plurality of specified execution statements; the plurality of specified execution statements are sequentially stored in a preset cache queue according to generation order; the code call chain has a corresponding time parameter; the time parameter indicates a generation time of the running data used to generate the code call chain; the method further includes: reading second running data from the cache queue; the generation time of the second running data is later than the time parameter; updating the code call chain based on the second running data; and updating the time parameter of the updated code call chain to the generation time of the second running data.
[0154] Optionally, the step of updating the code call chain based on the second running data includes: determining a plurality of second functions based on the second running data; the second functions are called before the target execution statement is executed; if a third function in the plurality of second functions is not included in the code call chain, generating a third target node based on the third function; and updating the code call chain based on the third target node.
[0155] Referring to Figure 9 As shown in the figure, the electronic device includes a processor 100 and a memory 101, the memory 101 stores machine executable instructions capable of being executed by the processor 100, and the processor 100 executes the machine executable instructions to implement the above-mentioned program code data processing method.
[0156] Further, Figure 9 As shown in the figure, the electronic device further includes a bus 102 and a communication interface 103, and the processor 100, the communication interface 103 and the memory 101 are connected through the bus 102.
[0157] Wherein, the memory 101 can contain a high-speed random access memory (RAM, Random Access Memory), and can also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which can be wired or wireless), and the Internet, a wide area network, a local area network, a metropolitan area network, etc. can be used. The bus 102 can be an ISA bus, a PCI bus or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, Figure 9 Only one bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0158] The processor 100 can be an integrated circuit chip with processing capability of signals. In implementation process, each step of the above method can be completed by integrated logic circuit of hardware in the processor 100 or instruction in the form of software. The processor 100 described above can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. Each method, step and logic block diagram disclosed in the embodiments of the present disclosure can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the embodiments of the present disclosure can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random access memory, a flash memory, a read only memory, a programmable read only memory or an electrically erasable programmable memory, a register, etc. The storage medium in the art. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101, and combines the hardware to complete the steps of the method of the above embodiment.
[0159] The embodiment also provides a machine readable storage medium, which stores machine executable instructions. When the machine executable instructions are called and executed by a processor, the machine executable instructions cause the processor to implement the processing method of the program code data.
[0160] The processing method, device and electronic equipment provided by the embodiment of the present disclosure include a computer readable storage medium storing program code, and the instructions included in the program code can be used to execute the method described in the foregoing method embodiment, for example:
[0161] Obtain first running data generated by running a target program code of a first version on a server; obtain a target execution statement from the first running data, determine a code call chain corresponding to the target execution statement based on the first running data; the code call chain is used to indicate a plurality of functions required to be called for executing the target execution statement, and a calling relationship of the plurality of functions; determine code difference data of the functions indicated by the code call chain based on the target program code of the second version and the target program code of the first version.
[0162] In the above manner, the user can clearly understand the code execution process of the preset requirement affected by the modified function by viewing the code call chain, improving the efficiency of analyzing the business function affected by the code modification, and the code call chain is generated based on the running data of the server, so that the code call relationship is more accurate, thereby improving the analysis accuracy of the business impact effect.
[0163] Optionally, the step of determining the code call chain corresponding to the target execution statement based on the first running data comprises: generating a first target node based on the target execution statement; determining a plurality of first functions based on the first running data; the first function is called before the target execution statement is executed; generating a second target node based on the first function; and generating the code call chain corresponding to the target execution statement based on the first target node, the second target node, and the calling relationship of the plurality of first functions.
[0164] Optionally, the step of generating the first target node based on the target execution statement comprises: performing parsing processing on the target execution statement to obtain a parsing result; the parsing result comprises the syntax structure of the target execution statement; and generating the first target node based on the parsing result.
[0165] Optionally, the target execution statement comprises a plurality of database execution statements; the parsing result further comprises a database operated by the database execution statement and a corresponding data processing operation; and the step of generating the first target node based on the parsing result comprises: generating the first target node based on the parsing result of a first database execution statement in the plurality of database execution statements; and if a second database execution statement in the plurality of database execution statements has the same syntax structure as the first target execution statement and operates on the same database as the first target execution statement, determining the first target node corresponding to the first database execution statement as the first target node corresponding to the second database execution statement.
[0166] Optionally, the method further comprises: for each first target node, determining a first called node list corresponding to the first target node; and the called node list comprises a second target node calling the first target node.
[0167] Optionally, the method further comprises: for each second target node, generating a second called node list corresponding to the second target node, and a calling node list; the called node list comprises other second target nodes calling the second target node; and the calling node list comprises other second target nodes and / or first target nodes called by the second target node.
[0168] Optionally, in the code call chain, different second target nodes correspond to different functions.
[0169] Optionally, the target execution statement includes a database execution statement; the parsed result further includes a database operated by the database execution statement and a corresponding data processing operation; and the step of generating the first target node based on the parsed result includes: determining whether the database operated by the database execution statement is a preset database; if yes, determining whether the data processing operation corresponding to the database execution statement is a data writing operation; if yes, generating the first target node based on the parsed result.
[0170] Optionally, the code call chain includes a plurality of nodes, each node having a corresponding function; the target program code includes a plurality of files; and the step of determining the code difference data corresponding to the function indicated by the code call chain based on the second version of the target program code and the first version of the target program code includes: comparing the files of the second version of the target program code with the files of the first version of the target program code; determining modified files in the files of the second version of the target program code based on the comparison result; determining a target file in the modified files based on the function corresponding to the node of the code call chain; and determining the code difference data corresponding to the function indicated by the code call chain based on the target file and the corresponding file in the first version of the target program code.
[0171] Optionally, the step of determining the code difference data corresponding to the function indicated by the code call chain based on the target file and the corresponding file in the first version of the target program code includes: for each function indicated by the code call chain, searching for a target file corresponding to the function from the target file; if the target file is found, determining the code difference data corresponding to the function based on the found target file and the corresponding file of the function in the first version of the target program code.
[0172] Optionally, the method further includes: if the target file is not found, deleting the node corresponding to the function from the code call chain and updating the code call chain.
[0173] Optionally, each node in the code call chain has a related node list; the related node list includes other nodes called by the node and other nodes calling the node; and the method further includes: determining related nodes of the deleted node; the related node list of the related nodes including the deleted node; and deleting the deleted node from the related node list of the related nodes.
[0174] Optionally, the running data comprises a plurality of specified execution statements; the plurality of specified execution statements are stored in a preset cache queue in sequence according to generation order; the code call chain has a corresponding time parameter; the time parameter indicates a generation time of the running data used to generate the code call chain; the method further comprises: reading second running data from the cache queue; the generation time of the second running data is later than the time parameter; updating the code call chain based on the second running data; and updating the time parameter of the updated code call chain to the generation time of the second running data.
[0175] Optionally, the step of updating the code call chain based on the second running data comprises: determining a plurality of second functions based on the second running data; the second functions are called before executing the target execution statement; if a third function in the plurality of second functions is not included in the code call chain, generating a third target node based on the third function; and updating the code call chain based on the third target node.
[0176] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the foregoing method embodiments, which will not be described here.
[0177] In addition, in the description of the embodiments of the present disclosure, unless explicitly defined and limited, the terms "mounting", "connecting", "connecting" should be understood broadly, for example, it can be fixedly connected, or it can be detachably connected, or integrally connected; it can be mechanically connected, or it can be electrically connected; it can be directly connected, or it can be indirectly connected through an intermediate medium, or it can be the communication inside two elements. For those skilled in the art, the specific meaning of the above terms in the present disclosure can be understood according to the specific circumstances.
[0178] The functions, if realized in the form of software function units and sold or used as independent products, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present disclosure essentially or the parts that make contributions to the prior art or parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.
[0179] In the description of the present disclosure, it should be explained that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present disclosure and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation on the present disclosure. In addition, the terms "first", "second", "third" are only for the purpose of description, and cannot be understood as indicating or implying relative importance.
[0180] Finally, it should be noted that the above embodiments are only specific embodiments of the present disclosure, used to illustrate the technical solutions of the present disclosure, and are not limiting, and the protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can make modifications or easily think of changes to the technical solutions recorded in the foregoing embodiments within the technical range disclosed by the present disclosure, or make equivalent replacements to some technical features; and these modifications, changes or replacements do not cause the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. A method for processing program code data, characterized in that, The method includes: Obtain the first runtime data generated by the server running the first version of the target program code; The target execution statement is obtained from the first execution data, and the code call chain corresponding to the target execution statement is determined based on the first execution data; the code call chain is used to indicate multiple functions that need to be called to execute the target execution statement, and the call relationship of the multiple functions; Based on the second version of the target program code and the first version of the target program code, determine the code difference data of the function indicated by the code call chain; The runtime data includes multiple specified execution statements; the multiple specified execution statements are stored sequentially in a preset cache queue according to their generation order; the code call chain has a corresponding time parameter; the time parameter indicates the generation time of the runtime data used to generate the code call chain; The method further includes: Read the second running data from the cache queue; the second running data was generated later than the time parameter. Based on the second runtime data, a plurality of second functions are determined; the second functions are called before the target execution statement is executed. If the code call chain does not include the third function among the plurality of second functions, a third target node is generated based on the third function; Update the code call chain based on the third target node; Update the time parameter of the updated code call chain to the generation time of the second runtime data.
2. The method according to claim 1, characterized in that, The step of determining the code call chain corresponding to the target execution statement based on the first running data includes: Based on the target execution statement, a first target node is generated; Based on the first running data, a plurality of first functions are determined; the first functions are called before the target execution statement is executed; Based on the first function, generate the second target node; Based on the calling relationships of the first target node, the second target node, and the plurality of first functions, a code call chain corresponding to the target execution statement is generated.
3. The method according to claim 2, characterized in that, The step of generating the first target node based on the target execution statement includes: The target execution statement is parsed to obtain a parsing result; the parsing result includes the syntax structure of the target execution statement. Based on the analysis results, the first target node is generated.
4. The method according to claim 3, characterized in that, The target execution statement includes multiple database execution statements; the parsing result also includes the database operated on by the database execution statements; The steps for generating the first target node based on the parsing results include: Based on the parsing result of the first database execution statement among the multiple database execution statements, a first target node is generated; If the syntax structure of the second database execution statement among the multiple database execution statements is the same as that of the first database execution statement, and the database operated on by the second database execution statement is the same as that operated on by the first database execution statement, then the first target node corresponding to the first database execution statement is determined as the first target node corresponding to the second database execution statement.
5. The method according to claim 2, characterized in that, The method further includes: For each first target node, a first list of called nodes corresponding to the first target node is determined; the list of called nodes includes the second target node that calls the first target node.
6. The method according to claim 2, characterized in that, The method further includes: For each second target node, a list of second called nodes corresponding to the second target node and a list of calling nodes are determined; the list of called nodes includes other second target nodes that call the second target node; the list of calling nodes includes other second target nodes called by the second target node and / or the first target node.
7. The method according to claim 2, characterized in that, In the code call chain, different second target nodes correspond to different functions.
8. The method according to claim 3, characterized in that, The target execution statement includes a database execution statement; the parsing result also includes the database operated on by the database execution statement and the corresponding data processing operation; The steps for generating the first target node based on the parsing results include: Determine whether the database in which the statement operation is executed is a preset database; If so, determine whether the data processing operation corresponding to the database execution statement is a data write operation; If so, generate the first target node based on the parsing result.
9. The method according to claim 1, characterized in that, The code call chain includes multiple nodes, each node having a corresponding function; the target program code includes multiple files. The step of determining the code difference data corresponding to the function indicated by the code call chain based on the second version of the target program code and the first version of the target program code includes: Compare the target program code file of the second version with the target program code file of the first version; Based on the comparison results, the modified files in the target program code of the second version were identified; Based on the function corresponding to the node in the code call chain, the target file in the modified file is determined; Based on the target file and the corresponding file in the target program code of the first version, determine the code difference data corresponding to the function indicated by the code call chain.
10. The method according to claim 9, characterized in that, The step of determining the code difference data corresponding to the function indicated by the code call chain based on the target file and the corresponding file in the target program code of the first version includes: For each function indicated by the code call chain, locate the corresponding object file from the object file; If found, based on the found target file and the corresponding file of the function in the target program code of the first version, the code difference data corresponding to the function is determined.
11. The method according to claim 10, characterized in that, The method further includes: If not found, delete the node corresponding to the function from the code call chain and update the code call chain.
12. The method according to claim 11, characterized in that, The nodes in the code call chain have a list of related nodes; the list of related nodes includes other nodes called by the node, as well as other nodes that called the node. The method further includes: Identify and delete the related nodes of the node; the list of related nodes includes the deleted node; The node to be deleted will be removed from the list of related nodes of the related nodes.
13. A device for processing program code data, characterized in that, The device includes: The runtime data acquisition module is used to acquire the first runtime data generated by the server running the first version of the target program code; The code call chain generation module is used to obtain the target execution statement from the first execution data, and determine the code call chain corresponding to the target execution statement based on the first execution data; the code call chain is used to indicate multiple functions that need to be called to execute the target execution statement, and the calling relationship of the multiple functions; The code difference data determination module is used to determine the code difference data of the function indicated by the code call chain based on the second version of the target program code and the first version of the target program code; The runtime data includes multiple specified execution statements; the multiple specified execution statements are stored sequentially in a preset cache queue according to their generation order; the code call chain has a corresponding time parameter; the time parameter indicates the generation time of the runtime data used to generate the code call chain; The device further includes: A data reading module is used to read second running data from the cache queue; the generation time of the second running data is later than the time parameter. The second code calls the chain update module, used for: Based on the second running data, a plurality of second functions are determined; the second functions are called before the target execution statement is executed; if the code call chain does not include a third function among the plurality of second functions, a third target node is generated based on the third function; the code call chain is updated based on the third target node; The generation time determination module is used to update the time parameter of the updated code call chain to the generation time of the second running data.
14. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the method for processing program code data according to any one of claims 1-12.
15. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores machine-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the method for processing program code data as described in any one of claims 1-12.
Citation Information
Patent Citations
Source code analysis method and device, electronic equipment and storage medium
CN116303013A
Regression testing method and device and storage medium
CN116467210A