CN102193859A - Code analysis method and system - Google Patents

Code analysis method and system Download PDF

Info

Publication number
CN102193859A
CN102193859A CN2010101184019A CN201010118401A CN102193859A CN 102193859 A CN102193859 A CN 102193859A CN 2010101184019 A CN2010101184019 A CN 2010101184019A CN 201010118401 A CN201010118401 A CN 201010118401A CN 102193859 A CN102193859 A CN 102193859A
Authority
CN
China
Prior art keywords
code
analysis
search engine
code analysis
index database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2010101184019A
Other languages
Chinese (zh)
Other versions
CN102193859B (en
Inventor
白广元
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Shiji Guangsu Information Technology Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201010118401.9A priority Critical patent/CN102193859B/en
Publication of CN102193859A publication Critical patent/CN102193859A/en
Application granted granted Critical
Publication of CN102193859B publication Critical patent/CN102193859B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention is suitable for the field of computer software and provides a code analysis method and system. The method comprises the following steps of: collecting code information and establishing an index database; according to a configured checking rule, querying the index database, thereby acquiring a query result; and performing code analysis on the query result and outputting a code analysis result. According to the method, the code is collected, the index is established and the code query result is analyzed, so that code reading is separated from code analysis, the efficiency and flexibility of code analysis are greatly increased, the enterprise-level codes are analyzed and managed, and code collection and the index can be realized by utilizing a search engine.

Description

A kind of code analysis methods and system
Technical field
The invention belongs to computer software fields, relate in particular to a kind of code analysis methods and system.
Background technology
Code analysis claims code scans or code check again, mainly checks the aspects such as rationality of source program code to the degree of following of standard, readable height, code logic correctness of expression, code structure.Run counter to the problem of programming standard in can discovery procedure by code analysis, and dangerous, indeterminate and fuzzy part in the program, find out and repeat in the program or portable part not.Code analysis comprises contents such as variable inspection, name and type examination, programmed logic examination, program syntax inspection and program structure inspection.
At present, the instrument of code analysis has a lot, the technical method that adopts is similar, as shown in Figure 1, generally be divided into fetch program, analyzer and form and show three parts, most of instrument can self-defined inspections rule, and main difference concentrates on checks the different of regular formulation and analyzer algorithm.
There is following shortcoming in existing code analysis tool:
(1) low, the consuming time length of analysis efficiency, can't be competent at the code administration of enterprise-level;
(2) code reads and analysis is coupled, and after checking that rule changes, code reads with the code analysis need of work and does again;
(3) the code change as analyzing, can only be once more execution analyzer from the beginning, therefore be difficult to the analysis of code when frequently changing;
(4) statistical study of more suitable single or a small amount of code file in the face of huge code library, can't be done the comparative analysis between file and the file, for example function call situation, duplicated code rate, code reuse situation, Module Division situation etc.
Summary of the invention
The purpose of the embodiment of the invention is to provide a kind of code analysis methods, is intended to solve that existing code analysis efficient is low, flexibility ratio is poor, the problem of incompatibility enterprise-level code analysis.
The embodiment of the invention is achieved in that a kind of code analysis methods, and described method comprises the steps:
Collect code information, set up index database;
According to the inspection rule of configuration, inquire about described index database, obtain Query Result;
Described Query Result is carried out code analysis, the output code analysis result.
Another purpose of the embodiment of the invention is to provide a kind of code analysis system, and described system comprises:
Indexing units is used to collect code information, sets up index database, and query interface is provided;
Code profiler is used for the inspection rule according to configuration, inquires about described index database by described query interface, obtains Query Result, Query Result is carried out code analysis, the output code analysis result; And
The code analysis display unit is used to export the code analysis result who shows described code profiler output.
The embodiment of the invention is collected code, set up index, the result analyzes at symbol lookup, having realized that code reads with code analysis is separated, the efficient and the flexibility ratio of code analysis have greatly been promoted, can realize the analysis management of enterprise-level code, code is collected with index and can be realized by search engine.
Description of drawings
Fig. 1 is the realization schematic diagram of the code analysis that provides of prior art;
Fig. 2 is the realization flow figure of the code analysis methods that provides of the embodiment of the invention;
Fig. 3 is the structural drawing of the code analysis system that provides of the embodiment of the invention.
Embodiment
In order to make purpose of the present invention, technical scheme and advantage clearer,, the present invention is further elaborated below in conjunction with drawings and Examples.Should be appreciated that specific embodiment described herein only in order to explanation the present invention, and be not used in qualification the present invention.
The embodiment of the invention is collected processing to code, sets up index database, utilizes the high speed query interface to inquire about, and Query Result is carried out code analysis, can improve the efficient and the flexibility ratio of code analysis greatly, realizes the analysis management of enterprise-level code.
Fig. 2 shows the realization flow of the code analysis methods that the embodiment of the invention provides, and details are as follows:
In step S101, collect code information, set up index database;
As one embodiment of the present of invention, utilize search engine to collect code information, set up index database.Search engine can utilize existing search engine, also can develop voluntarily.Search engine can be collected code information according to certain strategy, and after code information was organized and handled, the code information after output is handled was for the rear end code analysis provides retrieval service.
Search engine in the embodiment of the invention is the full-text search engine, extracts the code information in each software program, sets up index data base, and can retrieve the record that is complementary with querying condition, returns Query Result by certain arrangement sequence, and detailed process is as follows:
1, the code information in the capture program
Search engine has corresponding code capture program (Web Crawler), can grasp the code information in each program from huge enterprise-level program code storehouse continuously.
2, handle the code that grasps, set up index database
After search engine is caught code information, do a large amount of pre-service work, most important is exactly the keyword that extracts in the code information, sets up index database.
As one embodiment of the present of invention, search engine is the code variations situation of monitored object program easily, even code changes, only need read and analyze the code section of variation again, therefore can adapt to the code analysis under the frequent change conditions of code.
In step S102, according to the inspection rule of configuration, the search index storehouse obtains Query Result;
In embodiments of the present invention, directly code is not analyzed during code analysis, and be based on the query interface that search engine provides, inspection rule input inquiry condition according to configuration, the search index storehouse, the Query Result that search engine is returned carries out statistical study, can greatly promote the efficient of statistics and comparative analysis.
In step S103, Query Result is analyzed the output analysis result.
In embodiments of the present invention, Query Result according to search engine, can realize the comparative analysis between the code in the huge source code library, for example find out in whole project or the enterprise certain function situation etc. that is called, can also make high-rise logic analysis, for example duplicated code rate, code reuse situation, Module Division situation etc. to code.
The embodiment of the invention is by carrying out combination with search engine and two kinds of proven technique of code profiler, the ability of utilizing search engine to collect text message is collected code information, preserve the necessary information in the code, according to keywords create index, so just possessed full-text search ability code library.Directly code is not analyzed during code analysis, and be based on the query interface that search engine provides, Query Result is carried out statistical study, can greatly promote the efficient of statistics and comparative analysis, for example can retrieve the code file that comprises certain function definition earlier, again these code files are analyzed, judge whether these function inside are also identical, to find out duplicated code quickly and easily.
Fig. 3 shows the structure of the code analysis system that the embodiment of the invention provides, and for convenience of explanation, only shows the part relevant with the embodiment of the invention.
Indexing units 1 is collected code information, sets up index database, and query interface is provided.
As one embodiment of the present of invention, as indexing units, search engine can utilize existing search engine with search engine, also can develop voluntarily.
Code information in searcher 11 discoveries and the acquisition program.
Index 12 is handled the code information that searcher 11 is searched, and therefrom extracts index entry, according to keywords creates index.
The index that index database 13 storage indexs 12 are created, for example concordance list.
Searcher 14 provides query interface to code profiler 2, according to the querying condition search index storehouse 13 that code profiler 2 provides, and the output Query Result.
Code profiler 2 is according to the inspection rule of configuration, and by the query interface that indexing units 1 provides, the search index storehouse obtains Query Result, and Query Result is carried out code analysis, the output code analysis result.
In embodiments of the present invention, directly code is not analyzed during code profiler 2 code analysis, and be based on the query interface that indexing units 1 provides, inspection rule input inquiry condition according to configuration, the search index storehouse, the Query Result that indexing units 1 is returned carries out statistical study, can greatly promote the efficient of statistics and comparative analysis.
As one embodiment of the present of invention, symbol lookup logic 21 is according to the inspection rule of configuration, and generation and the query interface input inquiry condition that provides to code search engine 1 receive the Query Result that code search engine 1 returns.
22 pairs of Query Results of code analysis logic carry out code analysis, the output code analysis result.
In embodiments of the present invention, code analysis logic 22 is according to the Query Result of search engine, can realize the comparative analysis between the code in the huge source code library, for example find out in whole project or the enterprise certain function situation etc. that is called, can also make high-rise logic analysis, for example duplicated code rate, code reuse situation, Module Division situation etc. to code.
The code analysis result of code analysis display unit 3 output reveal codes analyzers 2 outputs.
The embodiment of the invention is collected code, set up index, the result analyzes at symbol lookup, having realized that code reads with code analysis is separated, the efficient and the flexibility ratio of code analysis have greatly been promoted, can realize the analysis management of enterprise-level code, code is collected with index and can be realized by search engine.
Particularly, the embodiment of the invention has the following advantages:
(1) huge code library can be analyzed, the analysis management of enterprise-level code can be realized;
(2) code is read with code analysis separate,, only need do code analysis again if check the rule change.Simultaneously, based on search inquiry interface at a high speed, make code analysis efficient, rapid;
(3) can make things convenient for the change conditions of monitored object code,, only need read and analyze changing unit again, the analysis when can code frequently changing even code changes;
(4) enlarged the scope of application of code analysis, be particularly useful for the huge mega project of code quantity,, can also realize spanned item destination code compare of analysis perhaps to the analysis and the monitoring of the whole codes of whole enterprise.
The above only is preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of being done within the spirit and principles in the present invention, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.

Claims (8)

1. a code analysis methods is characterized in that, described method comprises the steps:
Collect code information, set up index database;
According to the inspection rule of configuration, inquire about described index database, obtain Query Result;
Described Query Result is carried out code analysis, the output code analysis result.
2. the method for claim 1 is characterized in that, described collection code information, and the step of setting up index database is specially:
Code information in the capture program;
The code that grasps is handled, set up index database.
3. method as claimed in claim 1 or 2 is characterized in that, described collection code information is set up index database and realized by search engine.
4. method as claimed in claim 3 is characterized in that, described search engine is the full-text search engine.
5. a code analysis system is characterized in that, described system comprises:
Indexing units is used to collect code information, sets up index database, and query interface is provided;
Code profiler is used for the inspection rule according to configuration, inquires about described index database by described query interface, obtains Query Result, Query Result is carried out code analysis, the output code analysis result; And
The code analysis display unit is used to export the code analysis result who shows described code profiler output.
6. system as claimed in claim 5 is characterized in that, described indexing units is a search engine.
7. system as claimed in claim 6 is characterized in that, described code search engine is the full-text search engine.
8. as claim 5,6 or 7 described systems, it is characterized in that described code profiler comprises:
The symbol lookup logic is used for the inspection rule according to configuration, generates and to the query interface input inquiry condition that described code search engine provides, receives the Query Result that described code search engine returns; And
The code analysis logic is used for described Query Result is carried out code analysis the output code analysis result.
CN201010118401.9A 2010-03-03 2010-03-03 Code analysis method and system Active CN102193859B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201010118401.9A CN102193859B (en) 2010-03-03 2010-03-03 Code analysis method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201010118401.9A CN102193859B (en) 2010-03-03 2010-03-03 Code analysis method and system

Publications (2)

Publication Number Publication Date
CN102193859A true CN102193859A (en) 2011-09-21
CN102193859B CN102193859B (en) 2014-09-10

Family

ID=44601957

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201010118401.9A Active CN102193859B (en) 2010-03-03 2010-03-03 Code analysis method and system

Country Status (1)

Country Link
CN (1) CN102193859B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103268354A (en) * 2013-06-04 2013-08-28 百度在线网络技术(北京)有限公司 Method and device for analyzing coupling degrees between correlation strategies in searching engine
CN104991909A (en) * 2015-06-19 2015-10-21 扬州大学 Automatic thesaurus construction method for specific software historical code library
CN106575225A (en) * 2014-12-11 2017-04-19 株式会社日立制作所 Module division assistance device, module division assistance method, and module division assistance program
CN108446213A (en) * 2017-02-15 2018-08-24 西门子公司 A kind of static code mass analysis method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050081106A1 (en) * 2003-10-08 2005-04-14 Henry Chang Software testing
CN101017458A (en) * 2007-03-02 2007-08-15 北京邮电大学 Software safety code analyzer based on static analysis of source code and testing method therefor
CN101336428A (en) * 2006-01-26 2008-12-31 微软公司 Analyzing binary code
CN101599047A (en) * 2008-06-05 2009-12-09 埃森哲环球服务有限公司 Software upgrade analysis system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050081106A1 (en) * 2003-10-08 2005-04-14 Henry Chang Software testing
CN101336428A (en) * 2006-01-26 2008-12-31 微软公司 Analyzing binary code
CN101017458A (en) * 2007-03-02 2007-08-15 北京邮电大学 Software safety code analyzer based on static analysis of source code and testing method therefor
CN101599047A (en) * 2008-06-05 2009-12-09 埃森哲环球服务有限公司 Software upgrade analysis system

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103268354A (en) * 2013-06-04 2013-08-28 百度在线网络技术(北京)有限公司 Method and device for analyzing coupling degrees between correlation strategies in searching engine
CN103268354B (en) * 2013-06-04 2019-04-02 百度在线网络技术(北京)有限公司 In search engine between correlation strategy the degree of coupling analysis method and device
CN106575225A (en) * 2014-12-11 2017-04-19 株式会社日立制作所 Module division assistance device, module division assistance method, and module division assistance program
CN104991909A (en) * 2015-06-19 2015-10-21 扬州大学 Automatic thesaurus construction method for specific software historical code library
CN104991909B (en) * 2015-06-19 2018-02-27 扬州大学 A kind of dictionary method for auto constructing for specific software history codes storehouse
CN108446213A (en) * 2017-02-15 2018-08-24 西门子公司 A kind of static code mass analysis method and device
CN108446213B (en) * 2017-02-15 2021-08-17 西门子公司 Static code quality analysis method and device

Also Published As

Publication number Publication date
CN102193859B (en) 2014-09-10

Similar Documents

Publication Publication Date Title
CN107886238B (en) Business process management system and method based on mass data analysis
Linares-Vásquez et al. Triaging incoming change requests: Bug or commit history, or code authorship?
US7958114B2 (en) Detecting estimation errors in dictinct page counts
Wang et al. Efficient recovery of missing events
CN112100149B (en) Automatic log analysis system
CN102542061B (en) Intelligent product classification method
CN108694221B (en) Data real-time analysis method, module, equipment and device
CN104216948A (en) Difference control method of data model
CN103077192B (en) A kind of data processing method and system thereof
CN104699735A (en) Data processing method and device for enterprise data center
CN102193859B (en) Code analysis method and system
CN105302730A (en) Calculation model detection method, testing server and service platform
CN101425070B (en) Deadlock positioning method, deadlock positioning device and data system
CN104462461B (en) The method and device of investigation processing empty value is carried out to list
CN105677723A (en) Method for establishing and searching data labels for industrial signal source
CN113506098A (en) Power plant metadata management system and method based on multi-source data
CN108376324B (en) System and method for managing metering assets of carrier collector
US10223529B2 (en) Indexing apparatus and method for search of security monitoring data
CN112347314B (en) Data resource management system based on graph database
CN108108441A (en) A kind of database table structure analysis method and system
CN110750582A (en) Data processing method, device and system
CN107729518A (en) The text searching method and device of a kind of relevant database
CN104426708A (en) Method and system for executing security detection service
CA2746724A1 (en) Automatic data store architecture detection
CN111861790A (en) Electric power full-service data management system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
ASS Succession or assignment of patent right

Owner name: SHENZHEN SHIJI LIGHT SPEED INFORMATION TECHNOLOGY

Free format text: FORMER OWNER: TENGXUN SCI-TECH (SHENZHEN) CO., LTD.

Effective date: 20131101

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 518044 SHENZHEN, GUANGDONG PROVINCE TO: 518057 SHENZHEN, GUANGDONG PROVINCE

TA01 Transfer of patent application right

Effective date of registration: 20131101

Address after: A Tencent Building in Shenzhen Nanshan District City, Guangdong streets in Guangdong province science and technology 518057 16

Applicant after: Shenzhen Shiji Guangsu Information Technology Co., Ltd.

Address before: Shenzhen Futian District City, Guangdong province 518044 Zhenxing Road, SEG Science Park 2 East Room 403

Applicant before: Tencent Technology (Shenzhen) Co., Ltd.

C14 Grant of patent or utility model
GR01 Patent grant