A method and apparatus for program hot spot path determination
By constructing a program control flow graph and optimizing path analysis, and utilizing spanning trees and auxiliary edge techniques, the problem of low efficiency in determining program hotspot paths in existing technologies is solved, and efficient determination of program hotspot paths is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV
- Filing Date
- 2022-04-24
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies require a large number of test cases and repeated executions when determining hotspot paths in a program, resulting in high time costs and low efficiency.
By constructing a program control flow graph, removing closed subgraphs, inserting instructions with execution frequency records, and optimizing path analysis using spanning trees and auxiliary edges, hotspot paths of the program can be determined with only a small number of test cases.
It significantly improves the efficiency of identifying program hotspot paths, reduces the number of test cases, and shortens software development time.
Smart Images

Figure CN114817029B_ABST
Abstract
Description
A method and apparatus for determining program hotspot paths Technical Field
[0001] This invention relates to program code path analysis in software engineering. Background Technology
[0002] Program hotspot path analysis is a crucial aspect of software engineering. Knowing the hotspot paths in the program code beforehand allows software testing engineers to perform targeted testing on these paths, thereby improving and ensuring the robustness of core software modules. For non-hotspot paths, the amount of testing can be reduced, significantly improving overall testing efficiency and accelerating the overall software development process. Current techniques typically determine program hotspot paths using the following method: first, all paths are traversed, and an index is created for each path; then, a large number of test cases are executed, and the execution frequency of each path is counted based on the path index; finally, the paths with the highest frequency are identified as program hotspot paths. This method requires a sufficient number of test cases and needs to be repeated multiple times, thus consuming a significant amount of time. Summary of the Invention
[0003] The problem this invention aims to solve is to improve the efficiency of determining hotspot paths in a program.
[0004] To solve the above problems, the present invention adopts the following solution:
[0005] According to a method for determining program hotspot paths according to the present invention, the method includes the following steps:
[0006] Step S1 is used to: obtain program source code and test case set; the test case set is a collection of test cases for the program source code; the test cases contain parameter data required for testing the program source code;
[0007] Step S2 is used to: construct a program control flow graph based on the program source code; the program control flow graph is a directed graph composed of nodes representing basic program blocks and edges representing jump relationships between basic program blocks;
[0008] Step S3 is used to: construct an initial closed subgraph set based on the program control flow graph, and obtain an atomic closed subgraph set by removing closed subgraphs in the initial closed subgraph set that contain other closed subgraphs; the initial closed subgraph set and the atomic closed subgraph set are sets of closed subgraphs; the closed subgraph is labeled as G(v(i),v(j)); the closed subgraph G(v(i),v(j)) represents a subgraph in the program control flow graph with a unique entry point of node v(i), a unique exit point of node v(j), and a number of edges of not less than 3; where v(i) and v(j) are two nodes in the program control flow graph;
[0009] Step S4 is used to: insert execution frequency recording instructions for edges into the program source code according to the program control flow graph to obtain the instrumented program code, and then use each test case in the test case set as test input to execute the instrumented program code respectively, thereby obtaining the execution frequency of each edge of the program control flow graph through the execution of the execution frequency recording instructions for edges, and then calculate the discreteness value of each closed subgraph in the atomic closed subgraph set according to the execution frequency of each edge of the program control flow graph, and select several closed subgraphs with the smallest discreteness value to form an preferred closed subgraph set; wherein, the discreteness value of the closed subgraph is calculated using the following formula: DG(G(m)=(DL(p(G(m,a(1)),G(m,b(1))),1)+ DL(p(G(m,a(2)), G(m,b(2))),2)+...+ DL(p(G(m,a(K)), G(m,b(K))),K)) / K;
[0010] Where DG(G(m)) represents the discreteness value of the closed subgraph G(m), and G(m) represents the m-th closed subgraph in the atomic closed subgraph set; DL(p(G(m,a(k)), G(m,b(k))),k),k∈[1..K] represents the variance of the execution frequency distribution of the edge between the k-th node pair p(G(m,a(k)), G(m,b(k))); p(G(m,a(k)), G(m,b(k))) represents the node pair consisting of node G(m,a(k)) and node G(m,b(k)); node G(m,a(k)) and node G(m,b(k)) are the a(k)-th node and the b(k)-th node in the closed subgraph G(m), respectively; [1..K] represents the set of integers from 1 to K; K is the number of node pairs in the closed subgraph G(m);
[0011] Step S5 is used to: process the closed subgraphs in the preferred closed subgraph set to remove loops to obtain a de-looped graph of the closed subgraphs, then traverse the paths of the de-looped graph, and use these paths as edges between the entry and exit nodes of the closed subgraphs to simplify the program control flow graph to obtain a simplified control flow graph. At the same time, based on these paths, insert execution frequency recording instructions for the paths into the program source code, and combine this with the second instrumentation code obtained by inserting execution frequency recording instructions for the edges corresponding to the edges in the program control flow graph that are not in the preferred closed subgraph set.
[0012] The closed subgraph de-looping process involves replacing the loop body back edges with two loop auxiliary directed edges to obtain the de-looped graph.
[0013] The two cycle auxiliary directed edges replaced by the loop body back edge are the cycle auxiliary directed edge from the start node of the back edge to the subsequent node of the loop body, and the cycle auxiliary directed edge from the previous node of the loop body to the end node of the back edge.
[0014] The path to the decyclic graph starts at the entrance node of the closed subgraph and ends at the end node of the loop back edge, and ends at the exit node of the closed subgraph and ends at the beginning node of the loop back edge, without considering cyclic auxiliary directed edges.
[0015] Step S6 is used to: use each test case in the test case set as test input, execute the second instrumentation code respectively, and obtain the execution frequency of each edge of the simplified control flow graph;
[0016] Step S7 is used to: construct a definite flow set Fv(v) for each node and a definite flow set Fe(e(v,u(v,t))) for each edge based on the simplified control flow graph and the execution frequency of each edge in the simplified control flow graph; then select several subsequent paths with the highest determination frequency in the definite flow set of the entry node as program hotspot paths; wherein,
[0017] Fv(v) represents the set of deterministic flows of node v; the deterministic flows of a node include the subsequent path Rv(v,c) and the deterministic frequency fv(Rv(v,c)); Rv(v,c) represents the c-th subsequent path in the set of deterministic flows of node v Fv(v), which is the node sequence of nodes on the path from node v to the exit node in order; fv(Rv(v,c)) represents the deterministic frequency corresponding to the subsequent path Rv(v,c);
[0018] The set of deterministic flows Fv(v) of node v is formed by merging the set of deterministic flows Fe(e(v,u(v,t))) of all out-degree edges of node v;
[0019] Fe(e(v,u(v,t))) represents the set of deterministic flows of the out-degree edges e(v,u(v,t)) of node v; e(v,u(v,t)) represents the out-degree edge from node v to node u(v,t); node u(v,t) represents the terminal node of the t-th out-degree edge of node v; the edge deterministic flow includes the post-order path Re(e(v,u(v,t)),h) and the deterministic frequency fe(Re(e(v,u(v,t)),h)). Re(e(v,u(v,t)),h) represents the h-th post-order path of edge e(v,u(v,t)), which is the sequential sequence of nodes on the path from node v to the exit node, consisting of the post-order paths in the flow set determined by nodes v and u(v,t); fe(Re(e(v,u(v,t)),h)) represents the frequency corresponding to the post-order path Re(e(v,u(v,t)),h); where,
[0020] fe(Re(e(v,u(v,t)),h))= f(e(v,u(v,t)))-(ft(u(v,t))-fv(Rv(u(v,t),c))), and fe(Re(e(v,u(v,t)),h)) is greater than 0; where f(e(v,u(v,t))) represents the execution frequency of edge e(v,u(v,t)); ft(u(v,t)) represents the total number of times node u(v,t) is executed;
[0021] fv(Rv(u(v,t),c)) represents the definite frequency corresponding to the subsequent path Rv(u(v,t),c); Rv(u(v,t),c) is the c-th subsequent path in the definite flow set Fv(u(v,t)) of node u(v,t).
[0022] Furthermore, according to the method for determining hotspot paths of the present invention, step S4, "inserting an execution frequency recording instruction for the edge in the program source code," includes the following steps:
[0023] Step S411 is used to: find the loop body back edge in the program control flow graph, replace the loop body back edge with two loop auxiliary virtual edges, and add entry and exit auxiliary virtual edges to obtain a first auxiliary graph; the two loop auxiliary virtual edges replaced by the loop body back edge are the loop auxiliary virtual edge between the back edge starting node and the loop body subsequent node and the loop auxiliary virtual edge between the back edge ending node and the loop body preceding node; the entry and exit auxiliary virtual edges are the edges between the program control flow graph entry node and exit node;
[0024] Step S412 is used to: construct a first minimum spanning tree including the in and out auxiliary virtual edges based on the first auxiliary graph;
[0025] Step S413 is used to: insert execution frequency recording instructions for all edges in the program control flow graph that are not on the first minimum spanning tree at the corresponding positions in the program source code;
[0026] The step S4, "obtaining the execution frequency of each edge in the program control flow graph", includes calculating the execution frequency of all edges in the program control flow graph that are on the first minimum spanning tree.
[0027] Furthermore, according to the method for determining program hotspot paths of the present invention, step S5, "inserting an execution frequency recording instruction for the path into the program source code," includes the following steps:
[0028] Step S51 is used to: sort the nodes of the decyclic graph in reverse order, traverse the nodes according to the reverse-ordered decyclic graph nodes, and process each traversed node according to the following steps to calculate the edge value of each edge of the decyclic graph:
[0029] Step S511 is used to: if the out-degree of the node is 0, then initialize the numpath value of the node to 1; otherwise, initialize the numpath value of the node to 0.
[0030] Step S512 is used to: traverse the out-degree edges of the node, and process each traversed out-degree edge according to the following steps:
[0031] Step S5121 is used to: set the edge value of the out-degree edge to be equal to the numpath value of the node;
[0032] Step S5122 is used to: increase the numpath value of the node by the numpath value of the end node of the out-degree edge;
[0033] Step S52 is used to: add entry and exit auxiliary back edges to the decyclic graph to obtain a second auxiliary graph; and then construct a second minimum spanning tree including entry and exit auxiliary back edges based on the second auxiliary graph; the entry and exit auxiliary back edges are directed edges from the exit node to the entry node of the closed subgraph;
[0034] Step S53 is used to: initialize the instrumentation values of all cyclic auxiliary directed edges to 0, and then calculate the instrumentation values of all edges in the second auxiliary graph that are not on the second minimum spanning tree; the instrumentation values are calculated using the following formula: Inc(eo)=Val(eo)+sigma(Val(et)*Dir(eo, et, C(eo, et)) |et∈C(eo, et)); where Inc(eo) represents the instrumentation value of edge eo; Val(eo) represents the edge value of edge eo; sigma represents the accumulation function; Val(et) represents the edge value of edge et; Dir(eo,et, C(eo,et) represents the direction values of edges eo and et. If edges eo and et are in the same direction within the cycle C(eo,et), the value is 1; otherwise, the value is -1. C(eo,et) represents the cycle formed by edges eo and et. et∈C(eo,et) means that when edge eo is added to the second minimum spanning tree, it can form a cycle with et. Edge eo represents an edge that is not in the second minimum spanning tree, and edge et represents an edge that is in the second minimum spanning tree.
[0035] Step S54 is used to: insert an execution frequency recording instruction for the closed subgraph path into the program source code, including:
[0036] Step S541 is used to: insert a path index initialization instruction at the location of the program source code where the entry node of the closed subgraph is located;
[0037] Step S542 is used to: insert path index processing instructions for all edges in the closed subgraph that are not on the second minimum spanning tree.
[0038] If the edge is not a loop body return edge, then insert a path index increment instruction at the corresponding location in the program source code.
[0039] If the edge is a loop body back edge, then the path index reset instruction will be located at the corresponding position in the program source code;
[0040] Step S543 is used to: insert an execution frequency record instruction for the path corresponding to the path index at the location of the program source code where the exit node of the closed subgraph is located;
[0041] The path index initialization instruction is an instruction that initializes the path index value to 0;
[0042] The path index increment instruction is an instruction to add the edge instrumentation value to the path index value. If the edge is a loop body back edge, the instrumentation value of the edge is the instrumentation value of the loop auxiliary directed edge from the starting node of the loop body back edge to the subsequent node of the loop body.
[0043] The path index reset instruction is an instruction that assigns the path index value to the instrumentation value of the cyclic auxiliary directed edge from the preceding node of the loop body to the terminal node of the loop body's back edge.
[0044] Furthermore, according to the method for determining program hotspot paths of the present invention, in step S542, if the edge is a loop body back edge, then three instructions are inserted at the position of the program source code corresponding to the edge, in the following order: path index increment instruction, execution frequency recording instruction of the path corresponding to the path index, and path index reset instruction.
[0045] Furthermore, according to the method for determining program hotspot paths of the present invention, step S7 includes a step of sorting the control flow simplified graph nodes in reverse order to obtain a reverse-order node sequence and a step of traversing the reverse-order node sequence; the step of traversing the reverse-order node sequence includes the following steps:
[0046] Step S71 is used to: if the current node is an exit node, construct an initial node determination flow set; the initial node determination flow set contains a unique subsequent path, which contains a unique exit node, and the determination frequency corresponding to the path is the total number of times the second instrumentation code is executed; the current node is the node currently being traversed.
[0047] Step S72 is used to: traverse the out-degree edges of the current node and construct an edge determination flow set for each out-degree edge;
[0048] Step S73 is used to: merge the definite flow sets of all out-degree edges of the current node to obtain the definite flow set of the current node;
[0049] Step S74 is used to: repeat steps S71 to S73 until all nodes in the reversed node sequence have been traversed.
[0050] According to an apparatus for determining program hotspot paths based on the present invention, the apparatus includes the following modules:
[0051] Module M1 is used to: obtain program source code and test case set; the test case set is a collection of test cases for the program source code; the test cases contain parameter data required for testing the program source code;
[0052] Module M2 is used to: construct a program control flow graph based on the program source code; the program control flow graph is a directed graph composed of nodes representing basic program blocks and edges representing jump relationships between basic program blocks;
[0053] Module M3 is used for: constructing an initial closed subgraph set based on the program control flow graph, and obtaining an atomic closed subgraph set by removing closed subgraphs in the initial closed subgraph set that contain other closed subgraphs; the initial closed subgraph set and the atomic closed subgraph set are sets of closed subgraphs; the closed subgraph is labeled as G(v(i),v(j)); the closed subgraph G(v(i),v(j)) represents a subgraph in the program control flow graph with a unique entry point of node v(i), a unique exit point of node v(j), and at least 3 edges; where v(i) and v(j) are two nodes in the program control flow graph;
[0054] Module M4 is used to: insert execution frequency recording instructions for edges into the program source code according to the program control flow graph to obtain the instrumented program code, and then use each test case in the test case set as test input to execute the instrumented program code respectively, thereby obtaining the execution frequency of each edge of the program control flow graph through the execution of the execution frequency recording instructions for edges, and then calculate the discreteness value of each closed subgraph in the atomic closed subgraph set according to the execution frequency of each edge of the program control flow graph, and select several closed subgraphs with the smallest discreteness value to form an optimal closed subgraph set; wherein, the discreteness value of the closed subgraph is calculated by the following formula: DG(G(m)=(DL(p(G(m,a(1)),G(m,b(1))),1)+ DL(p(G(m,a(2)), G(m,b(2))),2)+...+ DL(p(G(m,a(K)), G(m,b(K))),K)) / K;
[0055] Where DG(G(m)) represents the discreteness value of the closed subgraph G(m), and G(m) represents the m-th closed subgraph in the atomic closed subgraph set; DL(p(G(m,a(k)), G(m,b(k))),k),k∈[1..K] represents the variance of the execution frequency distribution of the edge between the k-th node pair p(G(m,a(k)), G(m,b(k))); p(G(m,a(k)), G(m,b(k))) represents the node pair consisting of node G(m,a(k)) and node G(m,b(k)); node G(m,a(k)) and node G(m,b(k)) are the a(k)-th node and the b(k)-th node in the closed subgraph G(m), respectively; [1..K] represents the set of integers from 1 to K; K is the number of node pairs in the closed subgraph G(m);
[0056] Module M5 is used to: process the closed subgraphs in the preferred closed subgraph set to obtain a de-looped graph of the closed subgraphs, then traverse the paths of the de-looped graph, and use these paths as edges between the entry and exit nodes of the closed subgraphs to simplify the program control flow graph to obtain a simplified control flow graph. At the same time, based on these paths, execution frequency recording instructions for the paths are inserted into the program source code, and second instrumentation code is obtained by combining the execution frequency recording instructions for the edges inserted into the program source code positions corresponding to the edges in the program control flow graph that are not in the preferred closed subgraph set.
[0057] The closed subgraph de-looping process involves replacing the loop body back edges with two loop auxiliary directed edges to obtain the de-looped graph.
[0058] The two cycle auxiliary directed edges replaced by the loop body back edge are the cycle auxiliary directed edge from the start node of the back edge to the subsequent node of the loop body, and the cycle auxiliary directed edge from the previous node of the loop body to the end node of the back edge.
[0059] The path to the decyclic graph starts at the entrance node of the closed subgraph and ends at the end node of the loop back edge, and ends at the exit node of the closed subgraph and ends at the beginning node of the loop back edge, without considering cyclic auxiliary directed edges.
[0060] Module M6 is used to: take each test case in the test case set as test input, execute the second instrumentation code respectively, and obtain the execution frequency of each edge of the simplified control flow graph;
[0061] Module M7 is used to: construct a definite flow set Fv(v) for each node and a definite flow set Fe(e(v,u(v,t))) for each edge based on the simplified control flow graph and the execution frequency of each edge in the simplified control flow graph; and then select several subsequent paths with the highest determination frequency in the definite flow set of the entry node as program hotspot paths; wherein,
[0062] Fv(v) represents the set of deterministic flows of node v; the deterministic flows of a node include the subsequent path Rv(v,c) and the deterministic frequency fv(Rv(v,c)); Rv(v,c) represents the c-th subsequent path in the set of deterministic flows of node v Fv(v), which is the node sequence of nodes on the path from node v to the exit node in order; fv(Rv(v,c)) represents the deterministic frequency corresponding to the subsequent path Rv(v,c);
[0063] The set of deterministic flows Fv(v) of node v is formed by merging the set of deterministic flows Fe(e(v,u(v,t))) of all out-degree edges of node v;
[0064] Fe(e(v,u(v,t))) represents the set of deterministic flows of the out-degree edges e(v,u(v,t)) of node v; e(v,u(v,t)) represents the out-degree edge from node v to node u(v,t); node u(v,t) represents the terminal node of the t-th out-degree edge of node v; the edge deterministic flow includes the post-order path Re(e(v,u(v,t)),h) and the deterministic frequency fe(Re(e(v,u(v,t)),h)). Re(e(v,u(v,t)),h) represents the h-th post-order path of edge e(v,u(v,t)), which is the sequential sequence of nodes on the path from node v to the exit node, consisting of the post-order paths in the flow set determined by nodes v and u(v,t); fe(Re(e(v,u(v,t)),h)) represents the frequency corresponding to the post-order path Re(e(v,u(v,t)),h); where,
[0065] fe(Re(e(v,u(v,t)),h))= f(e(v,u(v,t)))-(ft(u(v,t))-fv(Rv(u(v,t),c))), and fe(Re(e(v,u(v,t)),h)) is greater than 0; where f(e(v,u(v,t))) represents the execution frequency of edge e(v,u(v,t)); ft(u(v,t)) represents the total number of times node u(v,t) is executed;
[0066] fv(Rv(u(v,t),c)) represents the definite frequency corresponding to the subsequent path Rv(u(v,t),c); Rv(u(v,t),c) is the c-th subsequent path in the definite flow set Fv(u(v,t)) of node u(v,t).
[0067] Furthermore, according to the apparatus for determining program hotspot paths according to the present invention, the "insertion of an execution frequency recording instruction for an edge in the program source code" in module M4 includes the following modules:
[0068] Module M411 is used to: find the loop body back edge in the program control flow graph, replace the loop body back edge with two loop auxiliary virtual edges, and add entry and exit auxiliary virtual edges to obtain a first auxiliary graph; the two loop auxiliary virtual edges replaced by the loop body back edge are the loop auxiliary virtual edge between the back edge starting node and the loop body subsequent node and the loop auxiliary virtual edge between the back edge ending node and the loop body preceding node; the entry and exit auxiliary virtual edges are the edges between the program control flow graph entry node and exit node;
[0069] Module M412 is configured to: construct a first minimum spanning tree including the in and out auxiliary virtual edges based on the first auxiliary graph;
[0070] Module M413 is used to: insert execution frequency recording instructions for all edges in the program control flow graph that are not on the first minimum spanning tree at the corresponding positions in the program source code;
[0071] The "obtaining the execution frequency of each edge of the program control flow graph" mentioned in module M4 includes calculating the execution frequency of all edges in the program control flow graph that are on the first minimum spanning tree.
[0072] Furthermore, according to the apparatus for determining program hotspot paths of the present invention, the "insertion of execution frequency recording instructions for the path in the program source code" in module M5 includes the following modules:
[0073] Module M51 is used for: sorting the nodes of the decyclic graph in reverse order, traversing the nodes according to the reverse-ordered decyclic graph nodes, and processing each traversed node according to the following module to calculate the edge value of each edge of the decyclic graph:
[0074] Module M511 is used to: initialize the numpath value of a node to 1 if the out-degree of the node is 0, otherwise initialize the numpath value of the node to 0.
[0075] Module M512 is used to: traverse the out-degree edges of the node, and process each traversed out-degree edge as follows:
[0076] Module M5121 is used to: set the edge value of the out-degree edge to be equal to the numpath value of the node;
[0077] Module M5122 is used to: increase the numpath value of the node by the numpath value of the end node of the out-degree edge;
[0078] Module M52 is used to: add inbound and outbound auxiliary back edges to the decyclic graph to obtain a second auxiliary graph; and then construct a second minimum spanning tree including inbound and outbound auxiliary back edges based on the second auxiliary graph; wherein the inbound and outbound auxiliary back edges are directed edges from the exit node to the entry node of the closed subgraph;
[0079] Module M53 is used to: initialize the instrumentation values of all cyclic auxiliary directed edges to 0, and then calculate the instrumentation values of all edges in the second auxiliary graph that are not on the second minimum spanning tree; the instrumentation values are calculated using the following formula: Inc(eo) = Val(eo) + sigma(Val(et) * Dir(eo, et, C(eo, et)) |et∈C(eo, et)); where Inc(eo) represents the instrumentation value of edge eo; Val(eo) represents the edge value of edge eo; sigma represents the accumulation function; Val(et) represents the edge value of edge et; Dir(eo,et, C(eo,et) represents the direction values of edges eo and et. If edges eo and et are in the same direction within the cycle C(eo,et), the value is 1; otherwise, the value is -1. C(eo,et) represents the cycle formed by edges eo and et. et∈C(eo,et) means that when edge eo is added to the second minimum spanning tree, it can form a cycle with et. Edge eo represents an edge that is not in the second minimum spanning tree, and edge et represents an edge that is in the second minimum spanning tree.
[0080] Module M54 is used to: insert execution frequency recording instructions for closed subgraph paths into the program source code, including:
[0081] Module M541 is used to insert path index initialization instructions at the location of the program source code where the entry node of the closed subgraph is located;
[0082] Module M542 is used for: inserting path index processing instructions for all edges in a closed subgraph that are not on the second minimum spanning tree.
[0083] If the edge is not a loop body return edge, then insert a path index increment instruction at the corresponding location in the program source code.
[0084] If the edge is a loop body back edge, then the path index reset instruction will be located at the corresponding position in the program source code;
[0085] Module M543 is used to: insert an execution frequency record instruction for the path corresponding to the path index at the location of the program source code where the exit node of the closed subgraph is located;
[0086] The path index initialization instruction is an instruction that initializes the path index value to 0;
[0087] The path index increment instruction is an instruction to add the edge instrumentation value to the path index value. If the edge is a loop body back edge, the instrumentation value of the edge is the instrumentation value of the loop auxiliary directed edge from the starting node of the loop body back edge to the subsequent node of the loop body.
[0088] The path index reset instruction is an instruction that assigns the path index value to the instrumentation value of the cyclic auxiliary directed edge from the preceding node of the loop body to the terminal node of the loop body's back edge.
[0089] Furthermore, in the device for determining program hotspot paths according to the present invention, if the edge is a loop body back edge in module M542, then three instructions are inserted at the position of the program source code corresponding to the edge, which are in the following order: path index increment instruction, execution frequency recording instruction of the path corresponding to the path index, and path index reset instruction.
[0090] Furthermore, according to the apparatus for determining program hotspot paths according to the present invention, module M7 includes a module for sorting the control flow simplified graph nodes in reverse order to obtain a reverse-order node sequence and a module for traversing the reverse-order node sequence; the module for traversing the reverse-order node sequence includes the following modules:
[0091] Module M71 is used to: construct an initial node determination flow set if the current node is an exit node; the initial node determination flow set contains a unique subsequent path, which contains a unique exit node, and the determination frequency corresponding to the path is the total number of times the second instrumentation code is executed; the current node is the node currently being traversed.
[0092] Module M72 is used to: traverse the out-degree edges of the current node and construct an edge-determining flow set for each out-degree edge;
[0093] Module M73 is used to: merge the deterministic flow sets of all out-degree edges of the current node to obtain the deterministic flow set of the current node;
[0094] Module M74 is used to: repeatedly execute modules M71 to M73 until all nodes in the reverse node sequence have been traversed.
[0095] The technical effects of this invention are as follows: The method of this invention requires only a small number of test cases, which greatly improves the efficiency of determining program hotspot paths. Attached Figure Description
[0096] Figure 1 is an overall flowchart of the present invention.
[0097] Figures 2 to 11 are examples of embodiments of the present invention.
[0098] Figure 2 is the program control flow graph corresponding to the program source code;
[0099] Figure 3 is the first auxiliary graph obtained after removing the loop from the program control flow graph in Figure 2 and adding inlet and outlet auxiliary virtual edges;
[0100] Figure 4 is the first minimum spanning tree constructed based on the first auxiliary graph in Figure 3;
[0101] Figure 5 shows all the edges in the program control flow graph of Figure 2 that are not on the first minimum spanning tree of Figure 4;
[0102] Figure 6 is the deloop graph obtained after delooping the preferred second closed subgraph in Figure 2;
[0103] Figure 7 is a simplified control flow graph obtained by simplifying the loop-free path in Figure 6.
[0104] Figure 8 is the second auxiliary graph obtained after removing the field entry and exit auxiliary back edge from the loop graph in Figure 6;
[0105] Figure 9 shows the second minimum spanning tree constructed based on the second auxiliary graph in Figure 8;
[0106] Figure 10 shows all the edges in the second auxiliary graph of Figure 8 that are not on the second minimum spanning tree of Figure 9.
[0107] Figure 11 shows the location of the staking for the second closed subgraph path in the second staking process and the frequency recording instruction for the inserted path. Detailed Implementation
[0108] The present invention will now be described in further detail with reference to the accompanying drawings.
[0109] The method for determining program hotspot paths in this invention is an automated method implemented by a machine executing machine instructions. The inputs are program source code and a test case set, and the output is the analyzed program hotspot paths. The "acquiring" in step S1 (acquiring program source code and test case set) indicates that the program source code and test case set are the inputs of this invention; how they are acquired and the form of the acquired data are not within the scope of this invention. Those skilled in the art will understand that, in a specific implementation, the program source code can be the program's original source code or intermediate code compiled from the program's original source code. The program's original source code can be C / C++, Java, or other programming languages. The test case set here is a collection of test cases for the program source code. Test cases contain parameter data required for testing the program source code. Those skilled in the art will understand that software testing is typically divided into unit testing, integration testing, and system testing processes. Unit testing, integration testing, and system testing usually employ different test cases. The test cases in this test case set can be unit test cases, integration test cases, or system test cases. Regardless of the type, the test cases in this invention's test case set are those that can be automated by machines using automation tools or scripts. Therefore, the parameter data required for the test referred to in these test cases is usually the test parameters used by automated testing tools, or it could be the test script itself.
[0110] Referring to Figure 1, the method for determining program hotspot paths according to the present invention includes a control flow graph construction step, a closed subgraph construction step, a closed subgraph optimization step, a flow graph simplification and instrumentation step, a second instrumentation execution step, and a flow analysis step.
[0111] The control flow graph construction step, also known as step S2 mentioned above, involves constructing the program control flow graph based on the program source code. As is well known, program control flow is a directed graph composed of nodes and edges. Nodes represent basic program blocks, while edges represent the jump relationships between these blocks. The construction of the program control flow graph is self-explanatory for those skilled in the art. It is important to emphasize that, since constructing the program control flow graph depends on the chosen tool platform, if the input required by the tool platform is intermediate code, the source code must first be converted into intermediate code before the tool platform can construct the program control flow graph. In this case, the input of the program source code in this invention can be considered as including a process of converting the source code into intermediate code. For this invention as a whole, the input is the intermediate code form of the program source code.
[0112] The closed subgraph construction step, also known as step S3, involves constructing an initial closed subgraph set based on the program control flow graph. After removing closed subgraphs from the initial set that contain other closed subgraphs, an atomic closed subgraph set is obtained. Here, both the initial and atomic closed subgraph sets are collections of closed subgraphs. Step S3 includes two steps: constructing the closed subgraph set based on the program control flow graph and removing subgraphs with containment relationships. Specifically, the step of constructing the closed subgraph set based on the program control flow graph involves traversing all node pairs (v(i), v(j)) in the program control flow graph, extracting the nodes and edges between node pairs (v(i), v(j)) to form a subgraph, and then determining whether the entry node v(i) and exit node v(j) of this subgraph are unique within the program control flow graph. In other words, the closed subgraph G(v(i), v(j)) between node pairs (v(i), v(j)) is a subgraph in the program control flow graph with a unique entry node v(i) and a unique exit node v(j). Here, nodes v(i) and v(j) are the i-th and j-th nodes in the program control flow graph, respectively.
[0113] We determine whether the entry node v(i) of the subgraph is unique in the program control flow graph, which means determining whether there are other nodes in the subgraph whose starting node of the in-degree edge is not in the subgraph. We also determine whether the exit node v(j) of the subgraph is unique in the program control flow graph, which means determining whether there are other nodes in the subgraph whose ending node of the out-degree edge is not in the subgraph. An in-degree edge of a node is an edge whose ending node is the node itself. An out-degree edge of a node is an edge whose starting node is the node itself. As we all know, edges in a directed graph have starting and ending nodes. Each edge in a directed graph is an edge between the starting and ending nodes. Therefore, an edge in a directed graph can be represented in the form e(a,b), where a and b represent the starting and ending nodes of edge e(a,b), respectively. Edge e(a,b) is the in-degree edge of node b and the out-degree edge of node a.
[0114] Furthermore, in this invention, a closed subgraph requires at least 3 edges, and there must be no inclusion relationship between closed subgraphs. Obviously, traversing all node pairs (v(i), v(j)) in the program control flow graph and extracting the nodes and edges between these pairs to form a subgraph results in a closed subgraph that may be a subgraph of another closed subgraph. To avoid closed subgraphs containing other closed subgraphs, the step of constructing a set of closed subgraphs based on the program control flow graph includes a step of removing subgraphs with inclusion relationships. This step removes subgraphs with inclusion relationships that contain other closed subgraphs. These two steps produce two sets of closed subgraphs. For distinction, the set of closed subgraphs output by the step of constructing the set of closed subgraphs based on the program control flow graph is the initial set of closed subgraphs, and the set of closed subgraphs output by the step of removing subgraphs with inclusion relationships is the atomic set of closed subgraphs. The initial set of closed subgraphs may contain closed subgraphs that are subgraphs of other closed subgraphs. In an atomic set of closed subgraphs, each closed subgraph is independent. More specifically, in an atomic set of closed subgraphs, there is no intersection between closed subgraphs. No intersection between closed subgraphs means that, as a set of edges, no two sets of edges from a closed subgraph intersect.
[0115] Taking the program control flow graph in Figure 2 as an example, this program control flow graph includes 8 nodes: A1, A2, A3, A4, A5, A6, A7, A8, A9, and A10. Among them, node A1 is the entry node of the program control flow graph, and node A8 is the exit node. The program control flow graph includes 14 edges: e(A1,A2), e(A1,A3), e(A2,A3), e(A3,A4), e(A3,A7), e(A4,A5), e(A4,A7), e(A5,A6), e(A5,A8), e(A6,A4), e(A7,A8), e(A8,A9), e(A8,A10), and e(A9,A10). The program's control flow graph contains a set of atomic closed subgraphs consisting of four closed subgraphs: the first closed subgraph consisting of nodes A1, A2, and A3; the second closed subgraph consisting of nodes A3, A4, A5, A6, A7, and A8; and the third closed subgraph consisting of nodes A8, A9, and A10. In the first closed subgraph, the entry node A1 is unique, the exit node A3 is unique, and it has three edges: e(A1,A2), e(A1,A3), and e(A2,A3). In the second closed subgraph, the entry node A3 is unique, the exit node A8 is unique, and it has eight edges: e(A3,A4), e(A3,A7), e(A4,A5), e(A4,A7), e(A5,A6), e(A5,A8), e(A6,A4), and e(A7,A8). In the third closed subgraph, the entry node A8 is unique, the exit node A10 is unique, and there are three edges: e(A8,A9), e(A8,A10), and e(A9,A10). There is no intersection of edges between the closed subgraphs, but there is an intersection of nodes. Node A3 is the exit node of the first closed subgraph and also the entry node of the second closed subgraph; node A8 is the exit node of the second closed subgraph and also the entry node of the third closed subgraph. In other words, intersection of nodes is allowed between closed subgraphs in the atomic closed subgraph set.
[0116] The closed subgraph optimization step, also known as step S4, involves inserting execution frequency recording instructions for edges into the program source code based on the program control flow graph to obtain the instrumented program code. Then, using each test case in the test case set as test input, the instrumented program code is executed respectively. This allows the execution frequency of each edge in the program control flow graph to be obtained through the execution of the edge execution frequency recording instructions. Then, based on the execution frequency of each edge in the program control flow graph, the dispersion value of each closed subgraph in the atomic closed subgraph set is calculated. The closed subgraphs with the smallest dispersion values are selected to form the preferred closed subgraph set. Step S4 can be divided into the following steps:
[0117] Step S41: Insert execution frequency recording instructions for edges into the program source code according to the program control flow graph to obtain the instrumented program code;
[0118] Step S42: Using each test case in the test case set as test input, execute the instrumented program code respectively;
[0119] Step S43: Obtain the execution frequency of each edge in the program control flow graph by recording the execution frequency of the edge instruction;
[0120] Step S44: Calculate the discreteness value of each closed subgraph in the atomic closed subgraph set based on the execution frequency of each edge of the program control flow graph;
[0121] Step S45: Select several closed subgraphs with the smallest dispersion values to form an optimal set of closed subgraphs.
[0122] That is, step S4 ultimately outputs the preferred closed sub-map set.
[0123] Step S43 relies on the instrumentation method of the edge execution frequency recording instruction in step S41. In the simplest way, the execution frequency recording instruction is inserted into the program source code corresponding to each edge of the program control flow graph. In this case, in step S43, the execution frequency of each edge of the program control flow graph can be directly obtained by executing the edge execution frequency recording instruction. Considering that when executing the instrumented program code in step S42, if the program source code is large in size, complex in structure, has many jumps, and a large number of test cases, the execution of the edge execution frequency recording instruction itself consumes a lot of overhead. To reduce the overhead consumed by the execution of the edge execution frequency recording instruction, in this embodiment, step S41 uses the following steps for instrumentation:
[0124] Step S411: Locate the loop body back edge in the program control flow graph, replace the loop body back edge with two loop auxiliary virtual edges, and add entry and exit auxiliary virtual edges to obtain the first auxiliary graph; the two loop auxiliary virtual edges replaced by the loop body back edge are the loop auxiliary virtual edge between the back edge start node and the loop body subsequent node and the loop auxiliary virtual edge between the back edge end node and the loop body preceding node; the entry and exit auxiliary virtual edges are the edges between the program control flow graph entry node and exit node;
[0125] Step S412: Construct a first minimum spanning tree including the in and out auxiliary virtual edges based on the first auxiliary graph;
[0126] Step S413: For all edges in the program control flow graph that are not on the first minimum spanning tree, insert execution frequency recording instructions for the corresponding edges at the locations in the program source code.
[0127] Continuing with the program control flow graph example in Figure 2, edge e(A6,A5) causes nodes A4, A5, and A6 to form a loop. Therefore, edge e(A6,A4) is a back edge of this loop. A preceding node of a loop is a node whose terminal node with an out-degree edge is located within the loop. The terminal node A4 of the out-degree edge e(A3,A4) of node A3 is located within the loop; therefore, node A3 is a preceding node of this loop. A following node of a loop is a node whose starting node with an in-degree edge is located within the loop. The starting node A4 of the in-degree edge e(A4,A7) of node A7 is located within the loop, and the starting node A5 of the in-degree edge e(A5,A8) of node A8 is located within the loop; therefore, nodes A7 and A8 are following nodes of this loop. After processing the program control flow graph in the example in Figure 2 through step S411, the first auxiliary graph shown in Figure 3 can be obtained.
[0128] In step S411, the loop body back edge is found in the program control flow graph, and replaced with two loop auxiliary virtual edges. The two loop auxiliary virtual edges replaced by the loop body back edge are the loop auxiliary virtual edge between the starting node of the back edge and the subsequent node of the loop body, and the loop auxiliary virtual edge between the ending node of the back edge and the preceding node of the loop body. This is a method of removing loop bodies from the program control flow graph. After the above processing, there are no loop bodies in the first auxiliary graph. Specifically, in the example of Figure 2, after the loop body back edge e(A6,A4) in Figure 2 is replaced by two loop auxiliary virtual edges, referring to Figure 3, the two loop auxiliary virtual edges are the edges (A3,A4) and (A6,A8) connected by the dashed lines in Figure 3. Among them, in the loop auxiliary virtual edge (A3,A4), node A4 is the ending node of the back edge e(A6,A4), and A3 is the preceding node of the loop body; in the loop auxiliary virtual edge (A6,A8), node A6 is the starting node of the back edge e(A6,A4), and A8 is the following node of the loop body. It should be noted that in actual processing, when constructing a loop auxiliary virtual edge about the starting node of the loop back edge, any node can be selected from the subsequent nodes of the loop body. Similarly, when constructing a loop auxiliary virtual edge about the ending node of the loop back edge, any node can be selected from the preceding nodes of the loop body. For example, in the example in Figure 2, a loop auxiliary virtual edge can also be constructed between the starting node A6 of the loop back edge and the subsequent node A7 of the loop body.
[0129] In addition, it should be noted that if there is no preceding or following node outside the loop, an empty node can be added outside the loop. This empty node corresponds to an empty instruction in the program source code.
[0130] In step S411, the program controls the auxiliary virtual edges between the entry node and the exit node of the flow graph. Specifically, in the example of Figure 2, the auxiliary virtual edges between the entry node A1 and the exit node A8 are shown as the dashed line connection between node A1 and node A8 in Figure 3.
[0131] Furthermore, it should be noted that the directionality of the cyclic auxiliary virtual edges and the in-and-out auxiliary virtual edges does not need to be considered. Therefore, the first auxiliary graph can be regarded as an undirected graph.
[0132] In step S412, the minimum spanning tree, also known as the minimum weight spanning tree, is familiar to those skilled in the art and requires no further explanation. It should be noted that when generating the first minimum spanning tree, it is necessary to ensure that the incoming and outgoing auxiliary virtual edges are within this minimum spanning tree. To ensure that the minimum spanning tree generated from the graph includes the incoming and outgoing auxiliary virtual edges, the incoming and outgoing auxiliary virtual edges can be assigned a weight less than that of other edges; for example, the weight of the incoming and outgoing auxiliary virtual edges is 0, and the weight of other edges is 1. Figure 4 illustrates the first minimum spanning tree generated from the first auxiliary graph in Figure 3.
[0133] It should be noted that the minimum spanning tree generated in step S412 is not unique; different algorithms may produce different minimum spanning trees.
[0134] Furthermore, in step S412, when calculating the minimum spanning tree, the weights of all edges except the auxiliary virtual edges are considered the same. Therefore, step S412 can also be regarded as calculating the minimum connected tree or the minimum connected graph, and there is actually no need to calculate the weights of the minimum spanning tree. For example, the minimum spanning tree shown in Figure 4 is the minimum connected graph or the minimum connected tree formed by searching the connected nodes through the depth-first traversal algorithm with the auxiliary virtual edges as initial edges and the entry node A1 and the exit node A8 as initial nodes. In this process, the weights are not actually calculated.
[0135] In step S413, all edges in the program control flow graph that are not on the first minimum spanning tree can be represented as a set operation or a set subtraction operation, specifically, Es = E0 - Et. Here, Es is the set of all edges in the program control flow graph that are not on the first minimum spanning tree, which is the set of edges to be instrumented; E0 is the set of edges in the program control flow graph; and Et is the set of edges in the first minimum spanning tree. When subtracting sets, there is no need to consider inbound / outbound auxiliary virtual edges and cyclic auxiliary virtual edges; these can be removed from the set. Continuing the previous example, subtracting the edge set of the first minimum spanning tree in Figure 4 from the edge set of the program control flow graph example in Figure 2 yields the set of edges to be instrumented, as shown in Figure 5, including edges e(A1,A3), e(A3,A4), e(A3,A7), e(A5,A8), e(A6,A4), and e(A7,A8). The edges in the global staking edge set are the edges where staking is performed in step S414.
[0136] Furthermore, the purpose of replacing the loop body back edge with a loop auxiliary virtual edge in step S411 is to enable the loop body back edge to be inserted as an edge to be instrumented into the execution frequency recording instruction for that edge. When calculating the first minimum spanning tree, the loop auxiliary virtual edge is treated the same as other edges except for the ingress and egress virtual edges. The first minimum spanning tree may or may not include loop auxiliary virtual edges. For example, the first minimum spanning tree shown in Figure 4 contains only one loop auxiliary virtual edge, and the other loop auxiliary virtual edge is not included in the first minimum spanning tree.
[0137] It is obvious that, using the above method, not all edges in the program control flow graph have instrumented execution frequency recording instructions for those edges. For example, referring to the set of edges to be instrumented illustrated in Figure 5, edges e(A1,A2), e(A2,A3), e(A4,A7), e(A4,A5), and e(A5,A6) in the program control flow graph illustrated in Figure 2 do not have instrumented execution frequency recording instructions for those edges. Therefore, it is necessary to calculate the execution frequency for all edges in the first minimum spanning tree of the program control flow graph in step S43. Obviously, the program control flow graph does not include loop auxiliary virtual edges, nor does it include inbound and outbound auxiliary virtual edges. Specifically, in the first minimum spanning tree illustrated in Figure 4, the execution frequencies of edges e(A1,A2), e(A2,A3), e(A4,A7), e(A4,A5), and e(A5,A6) need to be calculated. During the calculation, the total execution frequency of the out-degree edges of a node can be calculated based on the fact that the total execution frequency of the in-degree edges is equal to that of the out-degree edges.
[0138] Edge e(A1,A2) is the only in-degree edge of node A2, and its execution frequency is equal to the execution frequency of the out-degree edge e(A2,A3) of node A2.
[0139] Edge e(A2,A3) is one of the two in-degree edges of node A3. The sum of its execution frequency and that of edge e(A1,A2) is equal to the sum of the execution frequencies of the out-degree edges e(A3,A4) and e(A3,A7) of node A3. The execution frequencies of edges e(A1,A2), e(A3,A4), and e(A3,A7) can be measured by the execution of instrumented code. Therefore, the execution frequency of edge e(A2,A3) can be calculated, and thus the execution frequency of edge e(A1,A2) can be obtained.
[0140] Edge e(A4,A7) is one of the two in-degree edges of node A7. The sum of its execution frequency and the execution frequency of edge e(A3,A7) is equal to the execution frequency of the unique out-degree edge e(A7,A8) of node A7. The execution frequencies of edges e(A3,A7) and e(A7,A8) can be measured by the execution of instrumented code. Therefore, the execution frequency of edge e(A4,A7) can be calculated.
[0141] Edge e(A4,A5) is the only in-degree edge of node A5. Its execution frequency is equal to the sum of the execution frequencies of the two out-degree edges e(A5,A6) and e(A5,A8) of node A5. The execution frequency of edge e(A5,A8) can be measured by the execution of instrumented code. Therefore, we only need to calculate the execution frequency of edge e(A5,A6) to calculate the execution frequency of edge e(A4,A5).
[0142] Edge e(A5,A6) is the only in-degree edge of node A6. Its execution frequency is the same as that of edge e(A6,A4), the only out-degree edge of node A6. Edge e(A6,A4) can be measured by the execution of instrumented code. Thus, the execution frequency of edge e(A5,A6) can be obtained, and the execution frequency of edge e(A4,A5) can be calculated.
[0143] In summary, the execution frequency of all edges in the first minimum spanning tree of the program control flow graph can be calculated from the execution frequency of instrumented edges. Here, instrumented edges are edges with instructions for recording the execution frequency of the corresponding edges.
[0144] In step S44, the discreteness value of the closed subgraph is calculated according to the following formula: DG(G(m)=(DL(p(G(m,a(1)), G(m,b(1))),1)+ DL(p(G(m,a(2)), G(m,b(2))),2)+...+ DL(p(G(m,a(K)), G(m,b(K))),K)) / K. Wherein, DG(G(m) represents the discreteness value of the closed subgraph G(m), and G(m) represents the m-th closed subgraph in the atomic closed subgraph set; DL(p(G(m,a(k)), G(m,b(k))),k),k∈[1..K] represents the variance of the execution frequency distribution of the edge between the k-th node and p(G(m,a(k)), G(m,b(k))); p(G(m,a(k)), G(m,b(k))) represents a node pair consisting of nodes G(m,a(k)) and G(m,b(k)); nodes G(m,a(k)) and G(m,b(k)) are the a(k)-th and b(k)-th nodes in the closed subgraph G(m), respectively; [1..K] represents the set of integers from 1 to K; K is the number of node pairs in the closed subgraph G(m). It should be noted that the two nodes G(m,a(k)) in the node pair p(G(m,a(k)), G(m,b(k))) are... G(m,b(k)) is not limited to adjacent nodes. Taking the program flow control graph in Figure 2 as an example, its second closed subgraph consists of nodes A3, A4, A5, A6, A7, and A8. In the second closed subgraph, nodes A4 and A8 form a node pair, and the edges between nodes A4 and A8 include edges e(A4,A5), e(A4,A7), e(A5,A6), e(A5,A8), e(A6,A4), and e(A7,A8). Therefore, the variance of the execution frequency distribution between node pairs p(A4,A8) is DL(p(A4,A8)) and f(e(A4,A5)), f(e(A4,A7)), f(e(A5,A6)), f(e(A5,A8)), f(e(A6,A4)). The variance of the distribution of f(e(A7,A8)). Where f(e(A4,A5)), f(e(A4,A7)), f(e(A5,A6)), f(e(A5,A8)), f(e(A6,A4)), and f(e(A7,A8)) represent the execution frequency of edges e(A4,A5), e(A4,A7), e(A5,A6), e(A5,A8), e(A6,A4), and e(A7,A8), respectively.Therefore, we have: DL(p(A4,A6)) = ((f(e(A4,A5))-avg)^2 + (f(e(A4,A7))-avg)^2 + (f(e(A5,A6))-avg)^2 + (f(e(A5,A8))-avg)^2 + (f(e(A6,A4))-avg)^2 + (f(e(A7,A8))-avg)^2) / 4. Where avg is the average value of f(e(A4,A5)), f(e(A4,A7)), f(e(A5,A6)), f(e(A5,A8)), f(e(A6,A4)), and f(e(A7,A8)).
[0145] The flow graph simplification instrumentation step, also known as step S5, involves removing loops from the closed subgraphs in the preferred closed subgraph set to obtain a de-looped graph of the closed subgraphs. Then, the paths in the de-looped graph are traversed, and these paths are used as edges between the entry and exit nodes of the closed subgraphs to simplify the program control flow graph, resulting in a simplified control flow graph. Simultaneously, based on these paths, execution frequency recording instructions for the paths are inserted into the program source code. Combined with the execution frequency recording instructions for the edges corresponding to edges not in the preferred closed subgraph set in the program control flow graph, the second instrumentation code is obtained. This step has two objectives: simplification of the program control flow graph and the second instrumentation. The second instrumentation consists of two parts:
[0146] The first part involves inserting execution frequency recording instructions for edges based on the program source code positions corresponding to edges that are not in the preferred closed subgraph set in the program control flow graph.
[0147] The second part involves inserting instructions into the program source code to record the execution frequency of the path.
[0148] For the first part of the execution frequency recording instruction for edges, this embodiment adopts the same method as the aforementioned step S41. The difference is that the edges in the preferred closed sub-graph set can be skipped, so it will not be described again.
[0149] For the second part, which records the execution frequency of instructions for paths, the path here refers to a path in the decyclic graph. The simplification of the program control flow graph is also based on paths in the decyclic graph.
[0150] The closed subgraph de-looping process involves identifying the loop back edges in the closed subgraph and replacing them with two auxiliary directed edges to obtain the de-looped graph. The two auxiliary directed edges replacing the loop back edges are the auxiliary directed edge between the starting node of the loop back edge and the subsequent node of the loop body, and the auxiliary directed edge between the preceding node of the loop body and the ending node of the loop back edge. This step is similar to replacing the loop back edges with two auxiliary virtual edges in step S411, except that the edges being replaced here are directed edges; therefore, the specific processing steps will not be elaborated further. Taking the aforementioned second closed subgraph as an example, refer to Figure 6, which shows the de-looped graph obtained after de-looping the second closed subgraph in the control flow graph of the example program in Figure 2. In this diagram, the dashed arrow edge (A6, A8) is a directed auxiliary edge connecting the starting node A6 of the loop body's back edge e(A6, A4) to the subsequent node A8 of the loop body. The dashed arrow edge (A3, A4) is a directed auxiliary edge connecting the preceding node A3 of the loop body to the ending node A4 of the loop body's back edge e(A6, A4). In other words, there are two directed auxiliary edges in Figure 6: the directed auxiliary edge (A6, A8) and the directed auxiliary edge (A3, A4).
[0151] In this invention, the path to the decyclic graph uses the entry node of the closed subgraph and the end node of the loop back edge as the starting node of the path, and the exit node of the closed subgraph and the starting node of the loop back edge as the ending node of the path, without considering loop auxiliary directed edges. Specifically, in the example of Figure 6, the following path exists:
[0152] Path R1: A3→A7→A8;
[0153] Path R2: A3→A4→A7→A8;
[0154] Path R3: A3→A4→A5→A8;
[0155] Path R4: A4→A7→A8;
[0156] Path R5: A4→A5→A8;
[0157] Path R6: A3→A4→A5→A6;
[0158] Path R7: A4→A5→A6;
[0159] In this diagram, paths R1, R2, and R3 start at the entry node A3 of the closed subgraph and end at the exit node A8. Paths R4 and R5 start at the end node A4 of the loop back edge e(A6,A4) and end at the exit node A8. Path R6 starts at the entry node A3 of the closed subgraph and ends at the start node A6 of the loop back edge e(A6,A4). Path R7 starts at the end node A4 of the loop back edge e(A6,A4) and ends at the start node A6. These paths, acting as edges between the entry and exit nodes A3 and A8 of the closed subgraph, yield the simplified control flow graph shown in Figure 7.
[0160] When using a path in a decyclic graph as an edge between a closed entry node and an exit node, only the path whose ending node is the exit node of the closed subgraph is considered. Specifically, in the above paths, paths R6 and R7 actually represent the loop paths within the loop body. Path R6 represents the path entering the loop body, and path R7 represents the path within the loop body. Therefore, paths R6 and R7 are not used as edges between the closed entry and exit nodes of the simplified control flow graph. The paths used as edges between the closed entry and exit nodes of the simplified control flow graph are R1, R2, R3, R4, and R5. Furthermore, paths R4 and R5 use the ending node A4 of the loop back edge e(A6,A4) as the starting node of the path, and the actual corresponding closed subgraph path is:
[0161] Path R4: A3→(A4→A5→A6→A4)n→A7→A8;
[0162] Path R5: A3→(A4→A5→A6→A4)n→A5→A8.
[0163] In (A4→A5→A6→A4)n, n represents the number of loops. Therefore, the five edges in the simplified control flow graph shown in Figure 7 actually correspond to the five actual paths of the second closed subgraph:
[0164] Path R1: A3→A7→A8;
[0165] Path R2: A3→A4→A7→A8;
[0166] Path R3: A3→A4→A5→A8;
[0167] Path R4: A3→(A4→A5→A6→A4)n→A7→A8;
[0168] Path R5: A3→(A4→A5→A6→A4)n→A5→A8.
[0169] In this embodiment, inserting execution frequency recording instructions for these paths into the program source code specifically includes the following steps:
[0170] Step S51: Calculate the edge value of each edge by traversing the decyclic graph;
[0171] Step S52: Add in-out auxiliary back edges to the decyclic graph to obtain a second auxiliary graph; then construct a second minimum spanning tree including in-out auxiliary back edges based on the second auxiliary graph;
[0172] Step S53: After initializing the instrumentation values of all cyclic auxiliary directed edges to 0, calculate the instrumentation values of all edges in the second auxiliary graph that are not on the second minimum spanning tree.
[0173] Step S54: Insert an execution frequency recording instruction for the closed subgraph path into the program source code.
[0174] Step S51 specifically involves: sorting the nodes of the decyclic graph in reverse order, traversing the nodes according to the reverse-ordered decyclic graph nodes, and processing each traversed node according to the following steps to calculate the edge value of each edge of the decyclic graph:
[0175] Step S511: If the out-degree of the node is 0, then initialize the numpath value of the node to 1; otherwise, initialize the numpath value of the node to 0.
[0176] Step S512: Traverse the out-degree edges of the node. For each traversed out-degree edge, process it according to the following steps:
[0177] Step S5121: Set the edge value of the out-degree edge to be equal to the numpath value of the node;
[0178] Step S5122: The numpath value of the node is increased by the numpath value of the end node of the out-degree edge.
[0179] The nodes of a decyclic graph are sorted in reverse order based on the relationships determined by the directions of the directed edges. For example, if a directed edge has a start node and an end node, the reverse order means that the end node of the directed edge is placed before the start node. For instance, in the decyclic graph of Figure 6, composed of nodes A3, A4, A5, A6, A7, and A8, the reverse order of the nodes is: A8, A7, A6, A5, A4, A3. Edge values cannot be described by simple formulas; taking the decyclic graph of Figure 7 as an example...
[0180] For node A8, the out-degree of node A8 is 0. According to step S511, initialize the numpath value of A8, numpath(A8)=1; since node A8 has no out-degree edge, there is no need to process step S512.
[0181] For node A7, the out-degree of node A7 is 1. According to step S511, initialize the numpath value of node A7, numpath(A7)=0; according to step S5121, set the edge value Val(e(A7,A8))=numpath(A7)=0 for the out-degree edge e(A7,A8) of node A7; according to step S5122, update the numpath value of node A7: numpath(A7)= numpath(A7)+ numpath(A8)=1.
[0182] For node A6, the out-degree of node A6 is 1. According to step S511, initialize the numpath value of node A6, numpath(A6)=0; according to step S5121, set the value Val(cyclic auxiliary directed edge (A6,A8)) = numpath(A6)=0; according to step S5122, update the numpath value of node A6: numpath(A6) = numpath(A6) + numpath(A8)=1.
[0183] For node A5, the out-degree of node A5 is 2. According to step S511, initialize the numpath value of node A5 as numpath(A5) = 0. According to step S5121, set the edge value Val(e(A5,A8)) = numpath(A5) = 0 for the out-degree edge e(A5,A8). According to step S5122, update the numpath value of node A5 as numpath(A5) = numpath(A5) + numpath(A8) = 1. According to step S5121, set the edge value Val(e(A5,A6)) = numpath(A5) = 1 for the out-degree edge e(A5,A6). According to step S5122, update the numpath value of node A5 as numpath(A5) = numpath(A5) + numpath(A6) = 2.
[0184] For node A4, the out-degree of node A4 is 2. According to step S511, initialize the numpath value of node A4: numpath(A5) = 0. According to step S5121, set the out-degree edge e(A4,A7) of node A4 to Val(e(A4,A7)) = numpath(A4) = 0. According to step S5122, update the numpath value of node A4: numpath(A4) = numpath(A4) + numpath(A7) = 1. According to step S5121, set the out-degree edge e(A4,A5) of node A4 to Val(e(A4,A5)) = numpath(A4) = 1. According to step S5122, update the numpath value of node A4: numpath(A4) = numpath(A4) + numpath(A5) = 3.
[0185] For node A3, its out-degree is 3. According to step S511, initialize the numpath value of node A3 as numpath(A3) = 0. For the out-degree edge e(A3,A4) of node A3, according to step S5121, set its edge value Val(e(A3,A4)) = numpath(A3) = 0. According to step S5122, update the numpath value of node A3 as numpath(A3) = numpath(A3) + numpath(A4) = 3. For the out-degree edge e(A3,A7) of node A3, according to step S5121, set its edge value Val(e(A3,A7)) = numpath(A3) = 3. According to step S5122, update the numpath value of node A3 as numpath(A3) = numpath(A3) + numpath(A4) = 3. numpath(A7)=4; The out-degree edge of node A3, the cyclic auxiliary directed edge (A3,A4), is set to Val(cyclic auxiliary directed edge (A3,A4))=numpath(A3)=4 according to step S5121; The numpath value of node A3 is updated according to step S5122: numpath(A3)=numpath(A3)+numpath(A4)=7.
[0186] Therefore, the edge values of each edge in the decyclic graph can be obtained as follows:
[0187] Val(cyclic auxiliary directed edge (A3,A4))=4;
[0188] Val(e(A3,A7))=3;
[0189] Val(e(A3,A4))=0;
[0190] Val(e(A4,A5))=1;
[0191] Val(e(A4,A7))=0;
[0192] Val(e(A5,A6))=0;
[0193] Val(e(A5,A8))=1;
[0194] Val(cyclic auxiliary directed edge (A6, A8)) = 0;
[0195] Val(e(A7,A8))= 0.
[0196] In step S52, the auxiliary back edges are directed edges from the exit node to the entry node of the closed subgraph. The processing of step S52 is similar to that of steps S411 and S412, except that the auxiliary edges added between the exit node and the entry node in step S52 are directed edges. Continuing with the example of decyclic graphs in Figure 6, after adding the auxiliary back edges, the second auxiliary graph shown in Figure 8 can be obtained. The second minimum spanning tree constructed based on the second auxiliary graph shown in Figure 8 is shown in Figure 9.
[0197] In step S53, the stake value is calculated using the following formula:
[0198] Inc(eo) = Val(eo) + sigma(Val(et) * Dir(eo, et, C(eo, et)) | et ∈ C(eo, et)); where Inc(eo) represents the instrumentation value of edge eo; Val(eo) represents the edge value of edge eo; sigma represents the accumulation function; Val(et) represents the edge value of edge et; Dir(eo,et, C(eo,et)) represents the direction values of edges eo and et, which are 1 if edges eo and et are in the same direction in the cycle C(eo,et), otherwise they are -1; C(eo,et) represents the cycle formed by edges eo and et; et ∈ C(eo,et) means that when edge eo is added to the second minimum spanning tree, it can form a cycle with et; edge eo represents an edge that is not in the second minimum spanning tree, and edge et represents an edge in the second minimum spanning tree.
[0199] Continuing with the examples in Figures 8 and 9, based on the second auxiliary graph in Figure 8 and the second minimum spanning tree in Figure 9, we can obtain the edges in the second auxiliary graph that are not in the second minimum spanning tree as shown in Figure 10, including the cyclic auxiliary directed edges (A3,A4), e(A4,A7), e(A5,A6), e(A5,A8) and e(A7,A8).
[0200] For the cyclic auxiliary directed edge (A3, A4), when it is added to the second minimum spanning tree, it forms a cycle with edge e(A3, A4) but not with any other edges. Furthermore, the cyclic auxiliary directed edge (A3, A4) and edge e(A3, A4) are not in the same direction, and their direction value Dir is -1. Therefore, we have: Inc(cyclic auxiliary directed edge (A3, A4)) = Val(cyclic auxiliary directed edge (A3, A4)) + Val(e(A3, A4)) * (-1) = 4 - 0 = 4.
[0201] For edge e(A4,A7), when edge e(A4,A7) is added to the second minimum spanning tree, edge e(A4,A7), e(A3,A4), and e(A3,A7) form a cycle, but not with any other edge. Furthermore, e(A4,A7) and e(A3,A4) are in the same direction, while e(A3,A7) is in the opposite direction. Therefore, Inc(e(A4,A7)) = Val(e(A4,A7)) + Val(e(A3,A4)) + Val(e(A3,A7)) * (-1) = -3.
[0202] For edge e(A5,A6), when edge e(A5,A6) is added to the second minimum spanning tree, edge e(A5,A6), the cyclic auxiliary directed edge (A6,A8), the in-out auxiliary back edge (A8,A3), e(A3,A4), and e(A4,A5) form a cycle, but not with other edges. Furthermore, e(A5,A6), the cyclic auxiliary directed edge (A6,A8), the in-out auxiliary back edge (A8,A3), e(A3,A4), and e(A4,A5) are all in the same direction within the cycle. Therefore, we have: Inc(e(A5,A6))=Val(e(A5,A6))+ Val(cyclic auxiliary directed edge(A6,A8))+Val(input / output auxiliary back edge(A8,A3))+Val(e(A3,A4))+Val(e(A4,A5))=0+0+0+0+1=1.
[0203] For edge e(A5,A8), when edge e(A5,A8) is added to the second minimum spanning tree, edge e(A5,A8) and the auxiliary back edges (A8,A3), e(A3,A4), and e(A4,A5) form a cycle, but not with other edges. Furthermore, edge e(A5,A8) and the auxiliary back edges (A8,A3), e(A3,A4), and e(A4,A5) are in the same direction within the cycle. Therefore, Inc(e(A5,A8)) = Val(A5,A8) + Val(auxiliary back edges (A8,A3)) + Val(e(A3,A4)) + Val(e(A4,A5)) = 1 + 0 + 0 + 1 = 2.
[0204] For edge e(A7,A8), when edge e(A7,A8) is added to the second minimum spanning tree, edge e(A7,A8) and the auxiliary back edges (A8,A3) and e(A3,A7) form a cycle. Furthermore, edge e(A7,A8) and the auxiliary back edges (A8,A3) and e(A3,A7) are in the same direction within the cycle. Therefore, Inc(e(A7,A8)) = Val(A7,A8) + Val(auxiliary back edge (A8,A3)) + Val(e(A3,A7)) = 0 + 0 + 3 = 3.
[0205] The staking values for each side can be obtained as follows:
[0206] Inc(cyclic auxiliary directed edge (A3,A4))=4;
[0207] Inc(e(A4,A7)) = -3;
[0208] Inc(e(A5,A6))=1;
[0209] Inc(e(A5,A8))=2;
[0210] Inc(e(A7,A8))=3;
[0211] Inc(cyclic auxiliary directed edge (A6,A8))=0.
[0212] In step S54, different instructions need to be inserted at different locations in the program source code, specifically including the following steps:
[0213] Step S541: Insert a path index initialization instruction at the location of the program source code where the entry node of the closed subgraph is located;
[0214] Step S542 is to insert path index processing instructions for all edges in the closed subgraph that are not on the second minimum spanning tree;
[0215] Step S543: Insert the execution frequency record instruction corresponding to the path index at the location of the program source code where the exit node of the closed subgraph is located.
[0216] In the above steps, the path index is an integer. The path index initialization instruction initializes the path index value to 0, represented by the program statement code: Ri = 0. The instruction for recording the execution frequency of the path corresponding to the path index is represented by the program statement code: RC (Ri) = RC (Ri) + 1. Here, Ri represents the path index or path index value, and RC (Ri) represents the execution frequency of the path corresponding to the path index.
[0217] In step S542, the path index processing instruction needs to process different edges separately. Clearly, edges in the closed subgraph that are not in the second minimum spanning tree are not equivalent to edges in the second auxiliary graph that are not in the second minimum spanning tree. As mentioned earlier, neither the second minimum spanning tree nor the second auxiliary graph includes loop-body back edges. However, edges in the closed subgraph that are not in the second minimum spanning tree include loop-body back edges. Therefore, except for loop-body back edges, all edges in the closed subgraph that are not in the second minimum spanning tree can be found in the edges in the second auxiliary graph that are not in the second minimum spanning tree. Edges in the second auxiliary graph that are not in the second minimum spanning tree and loop-body back edges need to be processed separately:
[0218] If the edge is not a loop body back edge, then the edge must be an edge in the second auxiliary graph that is not on the second minimum spanning tree. In this case, insert a path index increment instruction at the location in the program source code corresponding to the edge.
[0219] If the edge is a loop return edge, it must not be an edge in the second auxiliary graph. In this case, three instructions are inserted at the corresponding location in the program source code, in the following order: path index increment instruction, path index corresponding path execution frequency recording instruction, and path index reset instruction.
[0220] The path index increment instruction is an instruction to add the edge instrumentation value to the path index value, which can be expressed as the program code: Ri = Ri + Inc(e). Here, Ri represents the path index or path index value, and Inc(e) is the edge instrumentation value. Obviously, if the edge is not a loop back edge, through the calculation in step S53, the edge, as an edge not on the second minimum spanning tree in the second auxiliary graph, can obtain the corresponding instrumentation value. If the edge is a loop back edge, step S53 does not calculate the loop back edge instrumentation value. In this case, the loop back edge instrumentation value is the instrumentation value of the loop auxiliary directed edge from the starting node of the loop back edge to the subsequent node of the loop. Specifically, in the example of the second closed subgraph mentioned above, the loop back edge e(A6,A4) corresponds to the loop auxiliary directed edge (A6,A8) from the starting node A6 to the subsequent node A8 of the loop back edge. That is, the loop back edge e(A6,A4) is the instrumentation value of the loop auxiliary directed edge (A6,A8).
[0221] The path index reset instruction assigns the path index value to the instrumentation value of the directed auxiliary edge from the preceding node of the loop body to the last node of the loop body's back edge. Specifically, in the example of the loop body back edge e(A6,A4) mentioned above, the directed auxiliary edge from the preceding node of the loop body to the last node of the loop body's back edge corresponding to the loop body back edge e(A6,A4) is the directed auxiliary edge (A3,A4), which can be represented in program code as: Ri=Inc(directed auxiliary edge (A3,A4)).
[0222] In other words, for a loop body back edge like e(A6,A4), the insertion instruction can be represented in program code as follows:
[0223] Ri = Ri + Inc(cyclic auxiliary directed edge (A6, A8));
[0224] RC(Ri) = RC(Ri) + 1;
[0225] Ri = Inc(Cyclic auxiliary directed edge (A3, A4)).
[0226] Based on the instrumentation values of the cyclic auxiliary directed edges obtained in step S53 above: Inc(cyclic auxiliary directed edge (A3, A4)) = 4; and Inc(cyclic auxiliary directed edge (A6, A8)) = 0. The above three statements are:
[0227] Ri=Ri+0;
[0228] RC(Ri) = RC(Ri) + 1;
[0229] Ri=4.
[0230] Based on the instrumentation values calculated in step S54 above, the execution frequency recording instructions inserted for the path in the second closed subgraph of the aforementioned example are shown in Figure 11. Combined with the aforementioned path in the decyclic graph:
[0231] Path R1: A3→A7→A8;
[0232] Path R2: A3→A4→A7→A8;
[0233] Path R3: A3→A4→A5→A8;
[0234] Path R4: A4→A7→A8;
[0235] Path R5: A4→A5→A8;
[0236] Path R6: A3→A4→A5→A6;
[0237] Path R7: A4→A5→A6.
[0238] After path R1 is executed, the path reaches node A8, and the path index Ri = Ri(A3) + Inc(e(A7,A8)) = 3;
[0239] After path R2 is executed, it reaches node A8, and the path index Ri = Ri(A3) + Inc(e(A4,A7)) + Inc(e(A7,A8)) = 0;
[0240] After path R3 is executed, the path reaches node A8, and the path index Ri = Ri(A3) + Inc(e(A5,A8)) = 2;
[0241] After path R4 is executed, it reaches node A8, and the path index Ri = Ri(A4) + Inc(e(A4,A7)) + Inc(e(A7,A8)) = 4;
[0242] After path R5 is executed, the path index Ri = Ri(A4) + Inc(e(A5,A8)) = 6, leading to node A8.
[0243] After path R6 is executed, the path index Ri = Ri(A3) + Inc(e(A5,A6)) = 1, leading to node A6.
[0244] After path R7 is executed, the path reaches node A6, and the path index Ri = Ri(A4) + Inc(e(A5,A6)) = 5;
[0245] In the above calculations, Ri(A3) and Ri(A4) represent the values when the program reaches nodes A3 and A4, respectively. The path index initialization instruction Ri=0, Ri(A3)=0. When paths R5, R6, and R7 use the end node of the loop back edge as the starting node, they represent the state of the loop value node A4 within the loop body. At this time, according to the path index reset instruction Ri=4 inserted by the loop back edge, when the program reaches node A4, Ri(A4)=4.
[0246] The above calculation results show that when the program executes the instruction for recording the execution frequency of the path corresponding to the path index, the path index value corresponds exactly to each of the above paths, and Ri takes values from 0 to Rn-1. Rn is the number of paths.
[0247] Furthermore, in the above paths, path R4 represents the number of times the loop body is entered; path R7 represents the number of times the loop is executed after entering the loop body; and paths R5 and R6 represent the number of times the loop body is exited. Clearly, f(R4) = f(R5) + f(R6). Here, f(R4), f(R5), and f(R6) are the execution frequencies of paths R4, R5, and R6, respectively.
[0248] It should be noted that in this embodiment, the purpose of inserting three instructions for the loop back edge instrumentation is to count the number of loops. If there is no need to count the number of loops, then only one path index reset instruction needs to be inserted for the loop back edge.
[0249] The second instrumentation execution step, also known as step S6 above, uses each test case in the test case set as test input to execute the second instrumentation code, thereby obtaining the execution frequency of each edge in the simplified control flow graph. This step is the same as step S43 above and will not be described again.
[0250] The flow analysis step, namely step S7 mentioned above, involves constructing a definite flow set Fv(v) for each node and a definite flow set Fe(e(v,u(v,t))) for each edge based on the simplified control flow graph and the execution frequency of each edge in the simplified control flow graph. Then, several subsequent paths with the highest determination frequency in the definite flow set of the entry node are selected as program hotspot paths.
[0251] Where Fv(v) represents the set of deterministic flows of node v; the deterministic flows of a node include the post-order path Rv(v,c) and the deterministic frequency fv(Rv(v,c)); Rv(v,c) represents the c-th post-order path in the set of deterministic flows of node v Fv(v), which is the node sequence of nodes on the path from node v to the exit node in order; fv(Rv(v,c)) represents the deterministic frequency corresponding to the post-order path Rv(v,c); the set of deterministic flows of node v Fv(v) is formed by merging the set of deterministic flows Fe(e(v,u(v,t))) of all out-degree edges of node v. Fe(e(v,u(v,t))) represents the set of deterministic flows of out-degree edges e(v,u(v,t)) from node v; e(v,u(v,t)) represents the out-degree edges from node v to node u(v,t); node u(v,t) represents the terminal node of the t-th out-degree edge from node v; the deterministic flow of edges includes the post-order path Re(e(v,u(v,t)),h) and the deterministic frequency fe(Re(e(v,u(v,t)),h)); Re(e(v,u( Let e(v,u(v,t)),h) represent the h-th post-order path of edge e(v,u(v,t)), which is the sequential sequence of nodes on the path from node v to the exit node, consisting of the post-order paths in the flow set determined by nodes v and u(v,t); fe(Re(e(v,u(v,t)),h)) represents the frequency of the post-order path Re(e(v,u(v,t)),h); where fe(Re(e(v,u(v,t)),h))= f(e(v,u(v,t)))-(ft(u(v,t))-fv(Rv(u(v,t),c))) and fe(Re(e(v,u(v,t)),h)) is greater than 0; where f(e(v,u(v,t))) represents the execution frequency of edge e(v,u(v,t)); fv(Rv(u(v,t),c)) represents the definite frequency corresponding to the subsequent path Rv(u(v,t),c); Rv(u(v,t),c) is the c-th subsequent path in the definite flow set Fv(u(v,t)) of node u(v,t); ft(u(v,t)) represents the total number of times node u(v,t) is executed.
[0252] In simple terms, the definition of the deterministic flow set mentioned above refers to the fact that the deterministic flow set of a node is formed by merging the deterministic flow sets of its out-degree edges. The deterministic flow set of an edge is determined by calculating whether the deterministic frequency of its subsequent path is greater than 0. The subsequent path of an edge is composed of the subsequent paths in the deterministic flow sets of the starting node and the ending node of the edge. Therefore, this is a process that needs to be implemented iteratively. There are generally two ways to implement this iteratively: the first is through recursion, and the other is to arrange the nodes in reverse order and traverse the nodes one by one in reverse order. This embodiment preferably adopts the method of reversing the node order. Step S7 includes the step of sorting the nodes of the control flow simplified graph in reverse order to obtain the reversed node sequence and the step of traversing the reversed node sequence. The step of traversing the reversed node sequence includes the following steps:
[0253] Step S71: If the current node is the exit node, construct an initial node determination flow set; the initial node determination flow set contains a unique subsequent path, which contains a unique exit node, and the determination frequency corresponding to it is the total number of times the second instrumentation code is executed; the current node is the node currently being traversed.
[0254] Step S72: Traverse the out-degree edges of the current node and construct an edge determination flow set for each out-degree edge;
[0255] Step S73: Merge the definite flow sets of all out-degree edges of the current node to obtain the definite flow set of the current node;
[0256] Step S74: Repeat steps S71 to S73 until all nodes in the reverse node sequence have been traversed.
[0257] Specifically, in the simplified control flow diagram illustrated in Figure 7, after the instrumentation code in step S6 is executed, the execution frequencies of each edge are as follows:
[0258] f(e(A1,A3))=490, f(e(A1,A2))=10, f(e(A2,A3))=10, f(e(R1))=70, f(e(R2))=90, f(e(R3))= 100, f(e(R4))=115, f(e(R5))=125, f(e(A8,A10))=20, f(e(A8,A9))=480, f(e(A9,A10))=480.
[0259] The reverse order of the nodes is: A10, A9, A8, A3, A2, A1.
[0260] When traversing to node A10, node A10 serves as the exit node of the simplified control flow graph, and the initial set of deterministic flows is: {{{A10}, 500}}. Here, 500 is the deterministic frequency fv({A10}) of the subsequent path {A10}, which is equal to the total number of times the second instrumentation code is executed.
[0261] When traversing to node A9, we first traverse the outgoing edges of node A9. For the unique outgoing edge e(A9,A10) of node A9, according to the post-order path in the deterministic flow set of its terminal node A10, its corresponding post-order path is {A9,A10}. The deterministic frequency of the post-order path {A9,A10} is fe({A9,A10})=f(e(A9,A10))-(ft(A10)-fv({A10}))=480-(500-500))=480. Therefore, the deterministic flow set of the outgoing edge e(A9,A10) is: {{{A9,A10},480}}. After merging the deterministic flow set of the outgoing edge e(A9,A10) into node A9, we get the deterministic flow set of node A9 as {{{A9,A10},480}}.
[0262] When traversing to node A8, we first traverse the out-degree edges of node A8. Node A8 has two out-degree edges e(A8,10) and e(A8,A9). According to the post-order paths in the deterministic flow set of its terminal node A10, the post-order path corresponding to e(A8,10) is {A8,A10}. The deterministic frequency of the post-order path {A8,A10} is fe({A8,A10})=f(e(A8,A10))-(ft(A10)-fv({A10}))=20-(500-500))=20. Therefore, the deterministic flow set of the out-degree edge e(A8,A10) is {{{A8,A10},20}}. Based on the post-order paths in the deterministic flow set of its terminal node A9, the post-order paths of the out-degree edge e(A8,A9) are: {A8,A9,A10}. The deterministic frequency of the post-order path {A8,A9,A10} is fe({A8,A9,A10})=f(e(A8,A9))-(ft(A9)-fv({A9,A10}))=480-(480-480))=480. Therefore, the deterministic flow set of the out-degree edge e(A8,A9) is {{{A8,A9,A10},480}}. Merging the deterministic flow sets of out-degree edges e(A8,10) and e(A8,A9) yields the deterministic flow set of node A8: {{{A8,A10},20},{{A8,A9,A10},480}}.
[0263] When traversing to node A3, first traverse the out-degree edges of node A3. Node A3 has 5 out-degree edges R1, R2, R3, R4, and R5. Based on the post-order paths in the definite flow set of its terminal node A8, the post-order paths corresponding to out-degree edge R1 are: {A3,R1,A8,A10} and {A3,R1,A8,A9,A10}. The definite frequency of the post-order path {A3,R1,A8,A10} is fe({A3,R1,A8,A10})=f(e(R1))-(ft(A8)-fv({A8,A10}))=70-(500-20))=-410<0. The deterministic frequency of the post-order path {A3,R1,A8,A9,A10} is fe({A3,R1,A8,A9,A10}) = f(e(R1)) - (ft(A8) - fv({A8,A9,A10})) = 70 - (500 - 480)) = 50. Since the deterministic frequency of the post-order path {A3,R1,A8,A10} is less than 0, it cannot be considered a deterministic flow. Therefore, the deterministic flow set of out-degree edge R1 is {{{A3,R1,A8,A9,A10},50}}. Based on the post-order paths in the deterministic flow set of its terminal node A8, the post-order paths corresponding to out-degree edge R2 are: {A3,R2,A8,A10} and {A3,R2,A8,A9,A10}. The frequency of the subsequent path {A3,R2,A8,A10} is given by fe({A3,R2,A8,A10}) = f(e(R2)) - (ft(A8) - fv({A8,A10})) = 90 - (500 - 20)) = -390 < 0. The frequency of the subsequent path {A3,R2,A8,A9,A10} is given by fe({A3,R2,A8,A9,A10}) = f(e(R2)) - (ft(A8) - fv({A8,A9,A10})) = 90 - (500 - 480)) = 70. Since the frequency of determination for the subsequent path {A3,R2,A8,A10} is less than 0, it cannot be considered a definite flow. Therefore, the set of definite flows for out-degree edge R2 is {{{A3,R2,A8,A9,A10},70}}. Similarly, the set of definite flows for out-degree edge R3 is {{{A3,R3,A8,A9,A10},80}}, for out-degree edge R4 it is {{{A3,R4,A8,A9,A10},95}}, and for out-degree edge R5 it is {{{A3,R5,A8,A9,A10},105}}.After merging the definite flow sets of out-degree edges R1, R2, R3, R4, and R5, we obtain the definite flow set of node A3: {{{A3,R1,A8,A9,A10},50},{{A3,R2,A8,A9,A10},70},{{A3,R3,A8,A9,A10},80},{{A3,R4,A8,A9,A10},95},{{A3,R5,A8,A9,A10},105}}.
[0264] When traversing to node A2, first traverse the out-degree edges of node A2. Node A2 has a unique out-degree edge e(A2,A3). Based on the subsequent paths in the definite flow set of its terminal node A3, its corresponding subsequent paths are: {A2,A3,R1,A8,A9,A10}, {A2,A3,R2,A8,A9,A10}, {A2,A3,R3,A8,A9,A10}, {A2,A3,R4,A8,A9,A10}, and {A2,A3,R1,A8,A9,A10}. The frequencies of determination for each subsequent path are: fe({A2,A3,R1,A8,A9,A10})=f(e(A2,A3))-(ft(A3)-fv({A3,R1,A8,A9,A10}))=10-(500-50))= -440<0; fe({A2,A3,R2,A8,A9,A10})=f(e(A2,A3))-(ft(A3)-fv({A3,R2,A8,A9,A10}))=10-(500-70))= -420<0;fe({A2,A3,R3,A8,A9,A10})=f(e(A2,A3))-(ft(A3)-fv({A3,R3,A8,A9,A10}))=10-(500-80))= -410<0;fe ({A2,A4,R4,A8,A9,A10})=f(e(A2,A3))-(ft(A3)-fv({A3,R4,A8,A9,A10}))=10-(500-95))= -395<0; fe ({A2,A4,R5,A8,A9,A10})=f(e(A2,A3))-(ft(A3)-fv({A3,R5,A8,A9,A10}))=10-(500-105))= -385<0. The deterministic frequencies of all subsequent paths of the out-degree edge e(A2,A3) are less than 0, therefore they cannot be considered deterministic flows. Thus, the deterministic flow set of this out-degree edge e(A2,A3) is empty. Consequently, the deterministic flow set of node A2 is also empty.
[0265] When traversing to node A1, we first traverse the outgoing edges of node A1. Node A1 has two outgoing edges e(A1,A2) and e(A1,A3). The deterministic flow set of the terminal node of outgoing edge e(A1,A2) is empty, so the deterministic flow set of this outgoing edge is also empty. For outgoing edge e(A1,A3), according to the post-order path in the deterministic flow set of its terminal node A3, the corresponding post-order paths are: {A1,A3,R1,A8,A9,A10}, {A1,A3,R2,A8,A9,A10}, {A1,A3,R3,A8,A9,A10}, {A1,A3,R4,A8,A9,A10}, and {A1,A3,R1,A8,A9,A10}. The frequencies of determination for each subsequent path are: fe({A1,A3,R1,A8,A9,A10})=f(e(A1,A3))-(ft(A3)-fv({A3,R1,A8,A9,A10}))=490-(500-50))= 40; fe({A1,A3,R2,A8,A9,A10})=f(e(A1,A3))-(ft(A3)-fv({A3,R2,A8,A9,A10}))=490-(500-70))=60; fe ({A1,A3,R3,A8,A9,A10})=f(e(A1,A3))-(ft(A3)-fv({A3,R3,A8,A9,A10}))=490-(500-80))=70; fe ({A1,A4,R4,A8,A9,A10})=f(e(A1,A3))-(ft(A3)-fv({A3,R4,A8,A9,A10}))=490-(500-95))=85; fe ({A1,A4,R5,A8,A9,A10})=f(e(A1,A3))-(ft(A3)-fv({A3,R5,A8,A9,A10}))=490-(500-105))=95. Therefore, the definite flow set of edge e(A1,A2) is:
[0266] {{{A1,A3,R1,A8,A9,A10},40},{{A1,A3,R2,A8,A9,A10},60},{{A1,A3,R3,A8,A9,A10},70},{{A1,A3,R4,A8,A9,A10},85},{{A1,A3,R5,A8,A9,A10},95}}. The deterministic flow set of the above edge e(A1,A2) is also the deterministic flow set of node A1. If we take the two subsequent paths with the highest deterministic frequency as hotspot paths, we can obtain the hotspot paths:
[0267] {A1,A3,R4,A8,A9,A10} and {A1,A3,R5,A8,A9,A10}.
[0268] Then, substituting edges R4 and R5 into the path sequence, we obtain the final hotspot path as follows:
[0269] Hotspot path 1: A1→A3→(A4→A5→A6→A4)n→A7→A8→A9→A10;
[0270] Hotspot path 2: A1→A3→(A4→A5→A6→A4)n→A5→A8→A9→A10.
[0271] Furthermore, the device referred to in this invention is a virtual device corresponding to the aforementioned method, and its modules are the steps corresponding to the method, which will not be described again.
Claims
1. A method for determining program hotspot paths, characterized in that, The method includes the following steps: Step S1, used to: obtain program source code and test case set; the test case set is a collection of test cases for the program source code; the test cases contain parameter data required for testing the program source code; Step S2, used to: construct a program control flow graph based on the program source code; the program control flow graph is a directed graph composed of nodes representing basic program blocks and edges representing jump relationships between basic program blocks; Step S3, used to: construct an initial closed subgraph set based on the program control flow graph, and obtain an atomic closed subgraph set by removing closed subgraphs that contain other closed subgraphs from the initial closed subgraph set; the initial closed subgraph set and the atomic closed subgraph set are sets of closed subgraphs; the closed subgraph is labeled G(v(i),v(j)); the closed subgraph G(v(i),v(j)) indicates that the unique entry point in the program control flow graph is node v(i), and the unique The exit is a subgraph with node v(j) and the number of edges is not less than 3; where v(i) and v(j) are two nodes in the program control flow graph; Step S4 is used to: insert execution frequency recording instructions for edges into the program source code according to the program control flow graph to obtain the instrumented program code, and then use each test case in the test case set as test input to execute the instrumented program code respectively, so as to obtain the execution frequency of each edge of the program control flow graph through the execution of the execution frequency recording instructions for edges, and then calculate the discreteness value of each closed subgraph in the atomic closed subgraph set according to the execution frequency of each edge of the program control flow graph, and select several closed subgraphs with the smallest discreteness value to form a preferred closed subgraph set; where the discreteness value of the closed subgraph is calculated by the following formula: DG(G(m)=(DL(p(G(m,a(1)), G(m,b(1))),1)+ DL(p(G(m,a(2)), G(m,b(2))),2)+...+ DL(p(G(m,a(K)), G(m,b(K))),K)) / K; where DG(G(m) represents the discreteness value of the closed subgraph G(m), and G(m) represents the m-th closed subgraph in the atomic closed subgraph set; DL(p(G(m,a(k)), G(m,b(k))),k),k∈[1..K] represents the variance of the execution frequency distribution of the edge between the k-th node and p(G(m,a(k)),G(m,b(k))); p(G(m,a(k)), G(m,b(k))) represents a node pair consisting of nodes G(m,a(k)) and G(m,b(k)); nodes G(m,a(k)) and G(m,b(k)) are the a(k)th and b(k)th nodes in the closed subgraph G(m), respectively; [1..K] represents the set of integers from 1 to K; K is the number of node pairs in the closed subgraph G(m);Step S5 is used to: After removing loops from the closed subgraphs in the preferred closed subgraph set, obtain a de-looped graph of the closed subgraphs; then traverse the paths of the de-looped graph; and use these paths as edges between the entry and exit nodes of the closed subgraphs to simplify the program control flow graph to obtain a simplified control flow graph. Simultaneously, based on these paths, insert execution frequency recording instructions for the paths into the program source code; and combine this with the second instrumentation code obtained by inserting execution frequency recording instructions for the edges corresponding to edges in the program control flow graph that are not in the preferred closed subgraph set. The de-looping process of the closed subgraph involves replacing the loop body back edges with two loop auxiliary directed edges to obtain the de-looped graph. Cyclic graph; the two cycle auxiliary directed edges replaced by the loop body back edge are the cycle auxiliary directed edge from the back edge start node to the loop body subsequent node and the cycle auxiliary directed edge from the loop body preceding node to the back edge end node; the path to the cyclic graph uses the entry node of the closed subgraph and the end node of the cycle back edge as the path start node, and the exit node of the closed subgraph and the start node of the cycle back edge as the path end node, without considering cycle auxiliary directed edges; step S6 is used to: use each test case in the test case set as test input, execute the second instrumentation code respectively, and obtain the execution frequency of each edge of the control flow simplified graph; step S7 is used to: according to the The simplified control flow graph and the execution frequency of each edge in the simplified control flow graph are used to construct a definite flow set Fv(v) for each node and a definite flow set Fe(e(v,u(v,t))) for each edge. Then, the most frequent subsequent paths in the definite flow set of the entry node are selected as program hotspot paths. Here, Fv(v) represents the definite flow set of node v; the node definite flow includes the subsequent path Rv(v,c) and the determination frequency fv(Rv(v,c)); Rv(v,c) represents the c-th subsequent path in the definite flow set Fv(v) of node v, which is the node sequence of nodes on the path from node v to the exit node in order; fv(Rv(v,c)) The frequency corresponding to the subsequent path Rv(v,c) is represented; the set of deterministic flows Fv(v) of node v is formed by merging the set of deterministic flows Fe(e(v,u(v,t))) of all out-degree edges of node v; Fe(e(v,u(v,t))) represents the set of deterministic flows of the out-degree edges e(v,u(v,t)) of node v; e(v,u(v,t)) represents the out-degree edge from node v to node u(v,t); node u(v,t) represents the terminal node of the t-th out-degree edge of node v; the edge deterministic flows include the subsequent path Re(e(v,u(v,t)),h) and the deterministic frequency fe(Re(e(v,u(v,t)),h)).Re(e(v,u(v,t)),h) represents the h-th post-order path of edge e(v,u(v,t)), which is the sequential sequence of nodes on the path from node v to the exit node, consisting of the post-order paths in the flow set determined by nodes v and u(v,t); fe(Re(e(v,u(v,t)),h)) represents the frequency of the post-order path Re(e(v,u(v,t)),h); where fe(Re(e(v,u(v,t)),h))= f(e(v,u(v,t)))-(ft(u(v,t))-fv(Rv(u(v,t),c))) and fe(Re(e(v,u(v,t)),h))) is greater than 0; where f(e(v,u(v,t))) represents the execution frequency of edge e(v,u(v,t)); ft(u(v,t)) represents the total number of times node u(v,t) is executed; fv(Rv(u(v,t),c)) represents the definite frequency corresponding to the subsequent path Rv(u(v,t),c); Rv(u(v,t),c) is the c-th subsequent path in the definite flow set Fv(u(v,t)) of node u(v,t).
2. The method for determining program hotspot paths as described in claim 1, characterized in that, Step S4, "inserting an execution frequency recording instruction for an edge in the program source code," includes the following steps: Step S411, used to: find the loop body back edge in the program control flow graph, replace the loop body back edge with two loop auxiliary virtual edges, and add an inlet / outlet auxiliary virtual edge to obtain a first auxiliary graph; the two loop auxiliary virtual edges replaced by the loop body back edge are the loop auxiliary virtual edge between the back edge starting node and the loop body subsequent node, and the loop auxiliary virtual edge between the back edge ending node and the loop body preceding node; the inlet / outlet auxiliary virtual edge is the edge between the program control flow graph entry node and exit node; Step S412, used to: construct a first minimum spanning tree including the inlet / outlet auxiliary virtual edge according to the first auxiliary graph; Step S413, used to: insert an execution frequency recording instruction for an edge at the corresponding position in the program source code for all edges in the program control flow graph that are not on the first minimum spanning tree; Step S4, "obtaining the execution frequency of each edge in the program control flow graph," includes calculating the execution frequency of all edges in the program control flow graph that are on the first minimum spanning tree.
3. The method for determining program hotspot paths as described in claim 1, characterized in that, The step S5, "inserting an execution frequency record instruction for the path in the program source code," includes the following steps: Step S51, used to: sort the nodes of the decyclic graph in reverse order, traverse the nodes according to the reverse-ordered decyclic graph nodes, and process each traversed node according to the following steps to calculate the edge value of each edge of the decyclic graph: Step S511, used to: if the out-degree of the node is 0, initialize the numpath value of the node to 1; otherwise, initialize the numpath value of the node to 0; Step S512, used to: traverse the out-degree edges of the node, For each traversed out-degree edge, the following steps are performed: Step S5121, used to: set the edge value of the out-degree edge equal to the numpath value of the node; Step S5122, used to: increase the numpath value of the node by the numpath value of the terminal node of the out-degree edge; Step S52, used to: add in-out auxiliary back edges to the decyclic graph to obtain a second auxiliary graph; then construct a second minimum spanning tree including in-out auxiliary back edges based on the second auxiliary graph; the in-out auxiliary back edges are directed edges from the exit node to the entry node of the closed subgraph; Step S53 is used to: initialize the instrumentation values of all cyclic auxiliary directed edges to 0, and then calculate the instrumentation values of all edges in the second auxiliary graph that are not on the second minimum spanning tree; the instrumentation values are calculated using the following formula: Inc(eo)=Val(eo)+sigma(Val(et)*Dir(eo, et, C(eo, et)) |et∈C(eo, et)); where Inc(eo) represents the instrumentation value of edge eo; Val(eo) represents the edge value of edge eo; sigma represents the accumulation function; Val(et) represents the edge value of edge et; Dir(eo,et, C(eo,et) represents the direction values of edges eo and et. If edges eo and et are in the same direction within the cycle C(eo,et), the value is 1; otherwise, the value is -1. C(eo,et) represents the cycle formed by edges eo and et. et∈C(eo,et) means that when edge eo is added to the second minimum spanning tree, it can form a cycle with et. Edge eo represents an edge not in the second minimum spanning tree, and edge et represents an edge in the second minimum spanning tree. Step S54 is used to: insert an execution frequency recording instruction for the closed subgraph path into the program source code, including: Step S541, used to: insert a path index initialization instruction at the location of the program source code where the entry node of the closed subgraph is located; Step S542, used to: insert a path index processing instruction for all edges in the closed subgraph that are not in the second minimum spanning tree. Command: If the edge is not a loop return edge, then insert a path index increment instruction at the corresponding location in the program source code; if the edge is a loop return edge, then insert a path index reset instruction at the corresponding location in the program source code; Step S543 is used to: insert an execution frequency record instruction for the path corresponding to the path index at the location in the program source code of the exit node of the closed subgraph; the path index initialization instruction is an instruction to initialize the path index value to 0; the path index increment instruction is an instruction to add the instrumentation value of the edge to the path index value; if the edge is a loop return edge, then the instrumentation value of the edge is the instrumentation value of the cyclic auxiliary directed edge from the starting node of the loop return edge to the subsequent node of the loop; the path index reset instruction is an instruction to assign the path index value to the instrumentation value of the cyclic auxiliary directed edge from the preceding node of the loop to the ending node of the loop return edge.
4. The method for determining program hotspot paths as described in claim 3, characterized in that, In step S542, if the edge is a loop body back edge, then three instructions are inserted at the corresponding position in the program source code, in the following order: path index increment instruction, path index corresponding path execution frequency recording instruction, and path index reset instruction.
5. The method for determining program hotspot paths as described in claim 1, characterized in that, Step S7 includes the steps of sorting the nodes of the control flow simplified graph in reverse order to obtain a reverse node sequence and traversing the reverse node sequence; the step of traversing the reverse node sequence includes the following steps: Step S71, used to: if the current node is an exit node, construct an initial node determination flow set; the initial node determination flow set contains a unique subsequent path, which contains a unique exit node, and the determination frequency corresponding to the path is the total number of times the second instrumentation code is executed; the current node is the node currently being traversed; Step S72, used to: traverse the out-degree edges of the current node and construct an edge determination flow set for each out-degree edge; Step S73, used to: merge the determination flow sets of all out-degree edges of the current node to obtain the determination flow set of the current node; Step S74, used to: repeat steps S71 to S73 until all nodes in the reverse node sequence have been traversed.
6. A device for determining program hotspot paths, characterized in that, The device includes the following modules: Module M1, used for: acquiring program source code and a test case set; the test case set is a collection of test cases for the program source code; the test cases contain parameter data required for testing the program source code; Module M2, used for: constructing a program control flow graph based on the program source code; the program control flow graph is a directed graph composed of nodes representing basic program blocks and edges representing jump relationships between basic program blocks; Module M3, used for: constructing an initial closed subgraph set based on the program control flow graph, and obtaining an atomic closed subgraph set by removing closed subgraphs that contain other closed subgraphs from the initial closed subgraph set; the initial closed subgraph set and the atomic closed subgraph set are sets of closed subgraphs; the closed subgraph is labeled G(v(i),v(j)); the closed subgraph G(v(i),v(j)) indicates that the unique entry point in the program control flow graph is node v(i), and the unique... The exit is a subgraph with node v(j) and the number of edges is not less than 3; where v(i) and v(j) are two nodes in the program control flow graph; Module M4 is used to: insert execution frequency recording instructions for edges into the program source code according to the program control flow graph to obtain the instrumented program code, and then use each test case in the test case set as test input to execute the instrumented program code respectively, thereby obtaining the execution frequency of each edge of the program control flow graph through the execution of the execution frequency recording instructions for edges, and then calculate the discreteness value of each closed subgraph in the atomic closed subgraph set according to the execution frequency of each edge of the program control flow graph, and select several closed subgraphs with the smallest discreteness value to form a preferred closed subgraph set; where the discreteness value of the closed subgraph is calculated by the following formula: DG(G(m)=(DL(p(G(m,a(1)), G(m,b(1))),1)+ DL(p(G(m,a(2)), G(m,b(2))),2)+...+ DL(p(G(m,a(K)), G(m,b(K))),K)) / K; where DG(G(m) represents the discreteness value of the closed subgraph G(m), and G(m) represents the m-th closed subgraph in the atomic closed subgraph set; DL(p(G(m,a(k)), G(m,b(k))),k),k∈[1..K] represents the variance of the execution frequency distribution of the edge between the k-th node and p(G(m,a(k)),G(m,b(k))); p(G(m,a(k)), G(m,b(k))) represents a node pair consisting of nodes G(m,a(k)) and G(m,b(k)); nodes G(m,a(k)) and G(m,b(k)) are the a(k)th and b(k)th nodes in the closed subgraph G(m), respectively; [1..K] represents the set of integers from 1 to K; K is the number of node pairs in the closed subgraph G(m);Module M5 is used for: processing closed subgraphs in the preferred closed subgraph set to remove loops, obtaining a de-looped graph of the closed subgraphs; traversing the paths in the de-looped graph; using these paths as edges between the entry and exit nodes of the closed subgraphs to simplify the program control flow graph to obtain a simplified control flow graph; simultaneously, inserting execution frequency recording instructions for the paths into the program source code based on these paths; and combining this with the insertion of execution frequency recording instructions for the edges corresponding to edges in the program control flow graph that are not in the preferred closed subgraph set to obtain second instrumentation code; the closed subgraph de-looping process involves replacing the loop body back edges with two loop auxiliary directed edges to obtain the de-looped graph. The loop graph; the two loop auxiliary directed edges replaced by the loop body back edge are the loop auxiliary directed edge from the back edge start node to the loop body subsequent node and the loop auxiliary directed edge from the loop body preceding node to the back edge end node; the path to the loop graph uses the entry node of the closed subgraph and the end node of the loop back edge as the path start node, and the exit node of the closed subgraph and the start node of the loop back edge as the path end node, without considering loop auxiliary directed edges; module M6 is used to: use each test case in the test case set as test input, execute the second instrumentation code respectively, and obtain the execution frequency of each edge of the simplified control flow graph; module M7 is used to: according to the The simplified control flow graph and the execution frequency of each edge in the simplified control flow graph are used to construct a definite flow set Fv(v) for each node and a definite flow set Fe(e(v,u(v,t))) for each edge. Then, the most frequent subsequent paths in the definite flow set of the entry node are selected as program hotspot paths. Here, Fv(v) represents the definite flow set of node v; the node definite flow includes the subsequent path Rv(v,c) and the determination frequency fv(Rv(v,c)); Rv(v,c) represents the c-th subsequent path in the definite flow set Fv(v) of node v, which is the node sequence of nodes on the path from node v to the exit node in order; fv(Rv(v,c)) The frequency corresponding to the subsequent path Rv(v,c) is represented; the set of deterministic flows Fv(v) of node v is formed by merging the set of deterministic flows Fe(e(v,u(v,t))) of all out-degree edges of node v; Fe(e(v,u(v,t))) represents the set of deterministic flows of the out-degree edges e(v,u(v,t)) of node v; e(v,u(v,t)) represents the out-degree edge from node v to node u(v,t); node u(v,t) represents the terminal node of the t-th out-degree edge of node v; the edge deterministic flows include the subsequent path Re(e(v,u(v,t)),h) and the deterministic frequency fe(Re(e(v,u(v,t)),h)).Re(e(v,u(v,t)),h) represents the h-th post-order path of edge e(v,u(v,t)), which is the sequential sequence of nodes on the path from node v to the exit node, consisting of the post-order paths in the flow set determined by nodes v and u(v,t); fe(Re(e(v,u(v,t)),h)) represents the frequency of the post-order path Re(e(v,u(v,t)),h); where fe(Re(e(v,u(v,t)),h))= f(e(v,u(v,t)))-(ft(u(v,t))-fv(Rv(u(v,t),c))) and fe(Re(e(v,u(v,t)),h))) is greater than 0; where f(e(v,u(v,t))) represents the execution frequency of edge e(v,u(v,t)); ft(u(v,t)) represents the total number of times node u(v,t) is executed; fv(Rv(u(v,t),c)) represents the definite frequency corresponding to the subsequent path Rv(u(v,t),c); Rv(u(v,t),c) is the c-th subsequent path in the definite flow set Fv(u(v,t)) of node u(v,t).
7. The apparatus for determining program hotspot paths as described in claim 6, characterized in that, The "insertion of execution frequency recording instructions for edges in the program source code" mentioned in module M4 includes the following modules: Module M411, used to: find the loop body back edge in the program control flow graph, replace the loop body back edge with two loop auxiliary virtual edges, and add entry and exit auxiliary virtual edges to obtain a first auxiliary graph; the two loop auxiliary virtual edges replaced by the loop body back edge are the loop auxiliary virtual edge between the back edge start node and the loop body subsequent node and the loop auxiliary virtual edge between the back edge end node and the loop body preceding node; the entry and exit auxiliary virtual edges are the edges between the program control flow graph entry node and exit node; Module M412, used to: construct a first minimum spanning tree including the entry and exit auxiliary virtual edges according to the first auxiliary graph; Module M413, used to: insert execution frequency recording instructions for all edges in the program control flow graph that are not on the first minimum spanning tree at the corresponding positions in the program source code; the "obtaining the execution frequency of each edge in the program control flow graph" mentioned in module M4 includes calculating the execution frequency of all edges in the program control flow graph that are on the first minimum spanning tree.
8. The apparatus for determining program hotspot paths as described in claim 6, characterized in that, The "insertion of execution frequency recording instruction for the path in the program source code" in module M5 includes the following modules: Module M51, used for: sorting the nodes of the decyclic graph in reverse order, traversing the nodes according to the reverse-ordered decyclic graph nodes, and processing each traversed node according to the following module to calculate the edge value of each edge of the decyclic graph: Module M511, used for: if the out-degree of the node is 0, then initialize the numpath value of the node to 1, otherwise initialize the numpath value of the node to 0; Module M512, used for: traversing the out-degree edges of the node, and processing each traversed out-degree edge according to the following module: Module M5121, used for: setting the edge value of the out-degree edge to be equal to the numpath value of the node; Block M5122 is used to: add the numpath value of the node to the numpath value of the end node of the out-degree edge; Module M52 is used to: add in-out auxiliary back edges to the decyclic graph to obtain a second auxiliary graph; then construct a second minimum spanning tree including in-out auxiliary back edges based on the second auxiliary graph; the in-out auxiliary back edges are directed edges from the exit node to the entry node of the closed subgraph; Module M53 is used to: initialize the instrumentation values of all cyclic auxiliary directed edges to 0, and then calculate the instrumentation values of all edges in the second auxiliary graph that are not on the second minimum spanning tree; the instrumentation values are calculated using the following formula: Inc(eo)=Val(eo)+sigma(Val(et)*Dir(eo, et, C(eo, et)) |et∈C(eo, et)); where Inc(eo) represents the instrumentation value of edge eo; Val(eo) represents the edge value of edge eo; sigma represents the accumulation function; Val(et) represents the edge value of edge et; Dir(eo,et, C(eo,et) represents the direction values of edges eo and et. If edges eo and et are in the same direction in the cycle C(eo,et), the value is 1; otherwise, the value is -1. C(eo,et) represents the cycle formed by edges eo and et. et∈C(eo,et) means that when edge eo is added to the second minimum spanning tree, it can form a cycle with et. Edge eo represents an edge that is not in the second minimum spanning tree, and edge et represents an edge that is in the second minimum spanning tree. Module M54 is used to: insert execution frequency recording instructions for closed subgraph paths into the program source code, including: module M541, used to: insert path index initialization instructions at the location of the program source code where the entry node of the closed subgraph is located; module M542, used to: insert path index processing instructions for all edges in the closed subgraph that are not in the second minimum spanning tree: if the edge is not a loop body back edge, then insert a path index increment instruction at the location of the corresponding program source code; if the edge is a loop body back edge, then insert a path index reset instruction at the location of the corresponding program source code.Module M543 is used to: insert an execution frequency record instruction corresponding to the path index at the location of the program source code where the exit node of the closed subgraph is located; the path index initialization instruction is an instruction to initialize the path index value to 0; the path index increment instruction is an instruction to add the edge instrumentation value to the path index value, and if the edge is a loop body back edge, then the instrumentation value of the edge is the instrumentation value of the loop auxiliary directed edge from the starting node of the loop body back edge to the next node of the loop body; the path index reset instruction is an instruction to assign the path index value to the instrumentation value of the loop auxiliary directed edge from the previous node of the loop body to the end node of the loop body back edge.
9. The apparatus for determining program hotspot paths as described in claim 8, characterized in that, In module M542, if the edge is a loop body back edge, then three instructions are inserted at the corresponding position in the program source code, in the following order: path index increment instruction, path index corresponding path execution frequency recording instruction, and path index reset instruction.
10. The apparatus for determining program hotspot paths as described in claim 6, characterized in that, Module M7 includes a module for sorting the nodes of the control flow simplified graph in reverse order to obtain a reverse node sequence and a module for traversing the reverse node sequence. The module for traversing the reverse node sequence includes the following modules: Module M71, used to: if the current node is an exit node, construct an initial node determination flow set; the initial node determination flow set contains a unique subsequent path, which contains a unique exit node, and the determination frequency corresponding to the path is the total number of times the second instrumentation code is executed; the current node is the node currently being traversed; Module M72, used to: traverse the out-degree edges of the current node and construct an edge determination flow set for each out-degree edge; Module M73, used to: merge the determination flow sets of all out-degree edges of the current node to obtain the determination flow set of the current node; Module M74, used to: repeatedly execute modules M71 to M73 until all nodes in the reverse node sequence have been traversed.
Citation Information
Patent Citations
Smart contract testing method based on path coverage sufficiency criterion
CN110046089A
Unit testing method based on automatic generation of path coverage test use cases
WO2019223247A1