Method for quickly positioning and displaying Java logic operation source code

CN118585441APending Publication Date: 2024-09-03SHENZHEN MICRON INFORMATION SERVICE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410698328.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

类似Apache SkyWalking目前仍无法实现直接展示Api逻辑结果代码的源码, 因此也就无法实现显示其逻辑代码修改人和修改时间的功能, 仍然需要一步一步从源头去排查问题直到定位到具体的代码与代码编写人员

Benefits of technology

[0011] The invention has the beneficial effects of mapping the current running code line through Java to the GIt warehouse source code, coder and coding time, and presenting the information to the Web browser. The invention can improve the efficiency of locating codes and confirming the person in charge, thereby improving the timeliness of overall problem solving.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585441A
    Figure CN118585441A
Patent Text Reader

Abstract

The invention discloses a method for quickly positioning and displaying a Java logic operation source code, which comprises the following steps of: adding a field in a JSON response body of Api, and displaying a value of the field at a corresponding position when debugging is needed. According to the invention, the efficiency of code positioning and principal confirmation can be improved, so that the time efficiency of integrally solving problems is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a method for quickly locating and displaying Java logic running source code. Background Art

[0002] In Internet companies, back-end developers use Java as the back-end development language for Web services. It provides APIs and uses the Json format for front-end developers to interact through Html / Javascript languages, and finally presents it to end users through Web browsers. This mode is very common. In this mode, if the terminal Web browser does not return the expected results, the developer needs to find out the reason. This is what developers often call debugging. The process of problem occurrence and debugging is described with a scene. A customer failed to place an order: 1) Front-end developer A received this situation and needed to assist in finding out why the order failed, and found the API address. 2) It was found that the back-end Java program prompted "order failed", so the problem was fed back to the person in charge of back-end development B. 3) Back-end development person B learned about the order failure problem based on previous information and transferred the problem to the back-end staff C who developed the order system. 4) Back-end staff C debugged and checked the API parameter address step by step and found that it was a user account status problem, and then transferred the account status problem to the back-end staff D who was responsible for account development. 5) Backend staff D developer took over the problem and debugged step by step from the account function code. Finally, the problem was located and the corresponding payment problem was solved. When problems occur in this type of service, the simplified routine steps are to find the API address suspected to have problems, and then find the corresponding developer based on the API address. However, in order to achieve the purpose of "agile development" in current Internet companies, front-end developers and back-end developers are usually separated. This model is called "front-end and back-end separation". Often, the back-end part of Internet services is usually divided into different developers according to different modules (such as user module, order module, payment module). In this multi-person assisted development model, it is often necessary to intervene in locating and solving problems. When the business model of an enterprise becomes more and more complex, the number of development iterations increases, and the number of personnel increases, once the back-end Java developer is required to locate and solve the problem, the efficiency will be reduced due to the different modules and personnel areas.

[0003] Currently, tools that help quickly locate problems technically include link tracking tools such as Apache SkyWalking. Apache SkyWalking uses a request link ID to track the calling process of a request. For example, you can know which Java methods are passed in an "order request" and how long it takes to call these Java methods. Tools like Apache SkyWalking are currently unable to directly display the source code of the API logic result code, so they are also unable to display the function of displaying the person who modified the logic code and the modification time. You still need to troubleshoot the problem step by step from the source until you locate the specific code and the code writer. Summary of the invention

[0004] A technical problem solved by the present invention is that it is impossible to display the person who modified the logic code and the modification time in the prior art.

[0005] The technical solution adopted by the present invention is: a method for quickly locating and displaying Java logic running source code, including adding a field in the JSON response body of the API, and displaying the value of the field at a corresponding position when debugging is required.

[0006] As a further improvement of the present invention, it also includes code version management software for acquiring and managing code source code, code submitter and submission time information.

[0007] As a further improvement of the present invention, a domain name address for displaying field values ​​is also included.

[0008] As a further improvement of the present invention, the field records at least the following information: a Hash value corresponding to each file is generated based on each Java file of each project, and a Hash value corresponding to each line of file code is generated based on each line of each file.

[0009] As a further improvement of the present invention, the Hash value corresponding to each file generated based on each Java file of each project includes at least 2 elements: the unique name of the project, and the full path name of each Java file (including the file name itself), which intercepts and retains the part that can be converted into Java ClassName; the Hash value corresponding to each line of file code generated based on each line of each file includes at least 5 elements: the name of the code submitter, the email address of the code submitter, the code submission time, the Commit Hash of the code submission, and all the characters of the source code of the entire current line.

[0010] As a further improvement of the present invention, the elements of the Hash value are all in string format.

[0011] The invention has the beneficial effect of mapping the currently running Java code line to the GIt repository source code, the coder and the coding time, and presenting the information to the Web browser. The invention can improve the efficiency of locating the code and confirming the person in charge, thereby improving the overall timeliness of problem solving. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 It is a schematic diagram of the present invention.

[0013] Figure 2 The figure is a field diagram of an embodiment disclosed in the present invention. DETAILED DESCRIPTION

[0014] The present invention will be further described below in conjunction with the accompanying drawings.

[0015] In order to better understand the present application, the following names are first explained.

[0016] Web service: is a service provided through the Internet that enables different programs to interact. It is based on standard protocols such as HTTP, etc. In a certain embodiment of the present invention, JSON format is used to exchange data.

[0017] Example 1, by adding a field "trace" in the JSON response body of the Api, when debugging is needed, the value of "trace" is pasted into the address bar of the Web browser to display the source code, coder (code submitter), modification time and other information of the Api business logic result.

[0018] This embodiment will use the code version management software: Git code repository, which is used to obtain information such as code source code, coder (code submitter), modification time, etc.

[0019] This embodiment will prepare a domain name, which can be any domain name address that complies with the domain name specification. For the purpose of demonstration and explanation, this embodiment will use "example.com" commonly used in technical documents as an example.

[0020] This embodiment involves two types of program services in software engineering. They are both Web software engineering services written in the programming language Java and run through Jvm. They both provide APIs to provide services to the outside in the format of Json and are divided into two categories according to the different functions they implement.

[0021] The first category: "Source code management service", there is only one in this invention, its main functions are: 1) Use the Git code repository tool to clone the code of the "Business Function Service" to the server hard disk, then read all the Java code files of these projects line by line and perform the following operations: a) Generate a hash value corresponding to each file based on each Java file in each project. The two elements involved in the hash are: i. The unique name of the "Business Function Service" project; ii. The full path name of each Java file (including the file name itself) is intercepted and the part that can be converted into JavaClassName is retained; The above two elements are both in string format, and the hash value generated after concatenation is such as: "IyWr".

[0022] b) Generate a hash value corresponding to each line of the file code based on each line of each file. The five elements involved in the hash are: i. Name of the code submitter ii. Email of the code submitter iii. Code submission time iv. Commit Hash of code submission v. All characters of the source code of the current line The above five elements are all provided by the Git Blame function. All five elements are in string format, and the hash value generated after concatenation is like: "EMFTo".

[0023] It should be noted that the elements of the two hashes do not contain the "line number" of the code (that is, the "line number" is not included in the hash calculation), because the "line number" of each line of code will change due to the addition or deletion of file content. Once the change occurs, the pre-generated hash value will also change. Once this happens, it is very easy to cause the "trace" source code positioning function generated during operation to fail. Therefore, the "line number" element is not included in the hash.

[0024] The five elements of the second hash are all "as long as the current line is not modified, they will not change". In other words, as long as this line of code is not modified, the hash value it generates will always be the same. These two hashes will be saved in the database and used for query.

[0025] 2) Provide a Web service to present the effect of tracing source code of the present invention; when debugging is required, the "trace" value mentioned in this embodiment will be pasted into the address bar of the browser, and the current service will parse and query the data record corresponding to the above-mentioned Hash saved in the database according to the value in "trace", and use Git to read the source code source file pointed to by the record, and combine the Git Blame command to obtain the required modifier and modification time information, assemble the required information and present it into a browser Web interface.

[0026] The second category: "Business function service", in the present invention it can be one or more.

[0027] "Business Function Service" is a Java code project used to implement business logic functions in common software engineering.

[0028] In order to realize the functions of the present invention, the following three specifications are required for the "business function service": 1. Each "business function service" has its own unique program engineering name; 2. The return value of the method provided by the functional module to other modules outside its own module needs to be unified into a Java class named "Result". The original return value is a "data" field of the Result class, and the status of the returned result is abstracted into the "success" field for success and failure. The "trace" field is used to save the string of the tracking chain when the API outputs the Json result after completing the logic. The generation and assignment of the "trace" field value need to be focused on in this invention. 3. When the function module methods return, they are all returned through a unified Java tool class. For example, returnResultUtil.success(data); or return ResultUtil.error(data). This tool method will create a unified Result object inside, and when called, it will manage the trace chain value of "trace", such as writing the value of "trace" to the ThreadLocal of the current Java thread, or comparing the trace value in the ThreadLocal of the current Java thread to see whether it should be replaced or kept with the last value (for example, if the success field is "failed", it will be replaced with a new trace value. Different algorithms here will result in different locations of the final traced code stack).

[0029] When the "Business Function Service" is deployed and started, it will go to the above-mentioned "Source Code Management Service" to request its own project "Tracking Value Table" according to its unique program project name. And cache the "Tracking Value Table" in the program memory. When an Api request occurs, it will be called uniformly through the ResultUtil tool. Internally, the Java call stack mechanism will be used to obtain the class name and code line number of the tool class being called. Combined with its own "Business Function Service" name, class name and code line number, the tracking chain value can be exchanged from the "Tracking Value Table" cached in the memory. Write the value to the ThreadLocal of the current Java thread. When the Api request is executed or a Java exception occurs, the tracking chain value is obtained from the ThreadLocal, and a domain name (such as example.com) is concatenated in front of the value and assigned to the "trace" field in the Result, and then the entire Result object is responded to the front-end Web browser in Json format.

[0030] Figure 2 As a demonstration of this embodiment, the field trace is: example.com / IyWr.EMFTo, where "example.com" is the domain name, pointing to the source code management service; " / " is a separator, "IyWr" is the first segment of the Hash value, the class file path; "." is a separator; "EMFTo" is the second segment of the Hash value, pointing to the line where the source code is located.

[0031] The API will be displayed to the front-end and browser Web terminal in Json format. When the API needs to be debugged, copy the string trace to the browser, and the following behavior will occur: 1. The "example.com" segment will be resolved to the service where the "source code management service" is located (because example.com is a domain name, and the resolved IP points to the "source code management service").

[0032] 2. The "IyWr.EMFTo" segment will be used as a parameter in the "Source Code Management Service" to query the database for the project / file name (Java class) / code line mapped to the value. Once the project / file name (Java class) / code line is obtained, the source code accurate to the project, file and line can be obtained from the Git repository. At the same time, Git's Blame function can obtain the source code's modifier (coder) and modification time.

[0033] 3. Based on the Git code information obtained above, you can interact with the front-end Html / Javascript page code to render the output in the form of a browser Web page.

[0034] If "IyWr.EMFTo" locates line 100 of file A, there is a configuration in the "Source Code Management Service" to determine the range of source code lines to be displayed. If the configuration is "20", the 20 lines above and below the current code will be displayed; at this time, the Web browser will display the source code content of lines 80 to 120 and the modifier and modification time of each line from 80 to 120 according to the above configuration.

[0035] The method of the present invention has the following significant features: 1) quickly locates and displays the Java code that is the cause of the problem; 2) directly displays the person who wrote the Java code; 3) directly displays the time when the Java code was written.

[0036] Those skilled in the art should be aware that the protection scheme of the present invention is not limited to the above-mentioned embodiments, and various arrangements, combinations and transformations can be performed on the basis of the above-mentioned embodiments. Without violating the spirit of the present invention, various transformations of the present invention fall within the protection scope of the present invention.

Claims

1. A method for quickly locating and displaying Java logic running source code, characterized by: include, Add a field to the JSON response body of the API, and display the value of the field in the corresponding position when debugging is required.

2. The method for quickly locating and displaying Java logic running source code according to claim 1, characterized in that It also includes code version management software, which is used to obtain and manage code source, code submitter and submission time information.

3. A method for quickly locating and displaying Java logic running source code according to claim 1 or 2, characterized in that It also includes the domain name address used to display the field value.

4. The method for quickly locating and displaying Java logic running source code according to claim 1, characterized in that The field records at least the following information: generating a Hash value corresponding to each file based on each Java file of each project, and generating a Hash value corresponding to each line of file code based on each line of each file.

5. According to claim 4, a method for quickly locating and displaying Java logic running source code is characterized in that the Hash value corresponding to each file generated based on each Java file of each project includes at least 2 elements: the unique name of the project, the full path name of each Java file (including the file name itself), and the part that can be converted into JavaClassName is intercepted and retained; the Hash value corresponding to each line of file code generated based on each line of each file includes at least 5 elements: the name of the code submitter, the email address of the code submitter, the code submission time, the CommitHash of the code submission, and all the characters of the source code of the entire current line.

6. The method for quickly locating and displaying Java logic running source code according to claim 5, characterized in that The elements of the Hash value are all in string format.

Citation Information

Patent Citations

  • Software error processing method and device, storage medium and equipment

    CN110188044A

  • Visual defect positioning method

    CN113157592A

  • Method for locating program abnormity

    CN1704908A

  • Systems, methods and computer program products for debugging java server page files using compiled java class file modifications

    US6463578B1