Summary of the invention
Present invention solves the technical problem that and be to provide in a kind of performance analysis tool quickly mapping function performance note
The method and device of record, for providing a kind of quick mapping function performance inventory internal memory in performance analysis tool
Method so that it is when sampling in the face of large-scale data and high-frequency performance, remain to keep outstanding performance.
For solving above-mentioned technical problem, the invention provides quick mapping function in a kind of performance analysis tool
The method of performance inventory,
At the generation phase of tested program, it is numbered for the tested function of each in described tested program,
Add up total number of tested function, and create Local Property according to total number of the described tested function of statistics
Record array;
In the operation phase of described tested program, according to the numbering of described tested function from described Local Property
Record array searches the performance inventory that described tested function is corresponding.
Further, described Local Property record array deposits the performance inventory that each tested function is corresponding
Unit, or the pointer of performance inventory unit corresponding to each tested function.
Further, at the generation phase of described tested program, compiler generates expresses tested function numbering
Code;Linker revises the code that compiler generates when reorientation, raw for each described tested function
Become function numbering.
Further, at the generation phase of described tested program, described compiler is tested function hooks
Can measure Hook Function, and using the numbering of tested function as the incoming parameter of performance measurement Hook Function;
In the operation phase of described tested program, during described tested function operation, enter described performance measurement hook
Subfunction, described performance measurement Hook Function obtains the numbering of described tested function from incoming parameter, and
Using the numbering of described tested function as array index, Local Property record array finds correspondence
Performance inventory.
Further, after described linker completes link, by described performance measurement Hook Function and performance
The initialization function of analytical tool, as a single file destination, is linked into described by ranging respectively
Sequence and tested dynamic base;
When described tested program starts or described tested dynamic base is loaded, described tested program or institute
The initialization function stating tested dynamic base creates described local according to total number of the described tested function of statistics
Performance inventory array.
Present invention also offers the device of quick mapping function performance inventory in a kind of performance analysis tool, bag
Include performance inventory relating module and performance inventory search module, wherein:
Described performance inventory relating module is used for, at the generation phase of tested program, for described tested program
In each tested function be numbered, add up total number of tested function, and according to described in statistics
Total number of tested function creates Local Property record array;
Described performance inventory is searched module and is used for, in the operation phase of described tested program, according to described quilt
The numbering surveying function searches the performance note that described tested function is corresponding from described Local Property record array
Record.
Further, described performance inventory relating module farther includes compiler code signal generating unit and chain
Connect device function numbering signal generating unit,
Described compiler code signal generating unit is used for, and generates the code expressing tested function numbering;
Described linker function numbering signal generating unit, revises described compiler code and generates single when reorientation
The code of the described expression tested function numbering that unit generates, numbers for each described tested function generating function.
Further, described performance inventory relating module further comprises compiler Hook Function and implants list
Unit,
Described compiler Hook Function is implanted unit and is used for, at the generation phase of described tested program, for quilt
Survey function hooks performance measurement Hook Function, and using the numbering of tested function as performance measurement Hook Function
Incoming parameter;
Described performance inventory is searched module and is used for, in the operation phase of described tested program, and described tested letter
Number enters described performance measurement Hook Function when running, and described performance measurement Hook Function is from incoming parameter
Obtain the numbering of described tested function, and using the numbering of described tested function as array index, in local
Performance inventory array finds the performance inventory of correspondence.
Further, described performance inventory relating module further comprises the link of linker initialization function
Unit,
Described linker initialization function link unit is used for, after described linker completes link, by described
The initialization function of performance measurement Hook Function and performance analysis tool as a single file destination,
It is linked into described tested program and tested dynamic base respectively.
Further, described performance inventory relating module further comprises performance inventory array creating unit,
Described performance inventory array creating unit is used for, described tested program start or described tested dynamically
When storehouse is loaded, the initialization function of described tested program or described tested dynamic base is according to the institute of statistics
The total number stating tested function creates described Local Property record array.
Compared with prior art, the present invention at least has the advantage that
The present invention is the lookup method that performance analysis tool provides that a kind of time complexity is O (1), it is possible to
It is rapidly completed and searches the performance inventory that function is corresponding, solve search performance note in existing performance analysis tool
Record is time-consuming long, on problems such as tested program impact are big.
Detailed description of the invention
Present embodiment provides a kind of method of quick mapping function performance inventory in performance analysis tool,
Use following scheme:
At the generation phase of tested program, need measured tested letter for each in this tested program
Number (the most if no special instructions, the most tested function) is numbered, and adds up tested function
Total number, and create Local Property record array according to total number of the tested function of statistics;
In the operation phase of tested program, look into from Local Property record array according to the numbering of tested function
Look for the performance inventory that this tested function is corresponding.
Wherein, described Local Property record array deposits the performance inventory list that each tested function is corresponding
Unit, or the pointer of performance inventory unit corresponding to each tested function.
In such scheme, it is quickly to have searched by having numbered for each tested function.And realize being somebody's turn to do
Function relies primarily on compiler and linker.Compiler generates the code expressing tested function numbering, link
The code that compiler generates revised by device when reorientation, generates real tested function numbering.Operationally,
According to total number of function tested in tested program, set up an array.Performance measurement Hook Function is from biography
Enter the numbering of the tested function of gain of parameter, this tested function is numbered the subscript as array, it is possible to be fast
Speed positions the performance inventory that this tested function is corresponding.
Wherein, present document relates to following concept: tested program is a concept being referred to as, and tested program is divided into:
The tested program of static linkage and the tested program of dynamic link.When static linkage, mastery routine is completely etc.
It is same as tested program;When dynamic link, tested program normally comprise tested mastery routine and tested dynamically
Storehouse.
Further, the quick mapping function performance inventory in performance analysis tool that present embodiment provides
Method, it is embodied as step and is described as follows:
Step one, when compiler generates the biography ginseng code of performance measurement Hook Function, has specific by one
The variable func_index_stub of prefix is incoming as a parameter of performance measurement Hook Function.Can be
Func_index_stub generates a kind of special reorientation type, it is also possible to for func_index_stub this
Name adds special prefix, uses as being marked for linker.Linker is set up a func_index and is become
Amount is numbered as tested function.Linker, when carrying out reorientation, can check the weight being presently processing
The type of location project be whether described special reorientation type or name be whether described specific before
The func_index_stub sewed, if it is, func_index is added 1 by linker, and at reorientation item
The value of func_index is write by the position amendment instruction that mesh is specified.After completing finally to link,
Func_index is exactly the sum of tested function in tested program.Linker is at reorientation special variable
Being write wherein by this sum during func_total, writing mode is identical with func_index above.Specifically,
When meeting with func_total reorientation project, the value of the func_index not write direct at that time, because
Now link may also be not fully complete, and the tested function of part may also not have statistics.At this moment, it is by weight
The location records of location gets off, and after whole link process completes, then writes in this position recorded
Final func_index value.
Step 2, by performance measurement Hook Function, and the initialization function of performance measurement tool is as one
Individually file destination, is linked into tested program and each tested dynamic base respectively.
Step 3, when tested program starts or tested dynamic base is loaded, its initialization each having
Function sets up local array record_array according to the value of func_total respectively, for storing performance
Record.
Wherein, each unit of array record_array both can be record unit, it is also possible to refer to
Pointer to record unit.
Step 4, during tested function operation, enters performance measurement Hook Function, performance measurement Hook Function
From passing the numbering obtaining tested function ginseng, then by this numbering as array index, in local
Can the read-write carrying out performance inventory safely and fast in record_array array.
According to such scheme, in the array of local, each numbering namely each tested function have it
Corresponding storage element.So, the storage of array unit found according to numbering when depositing, it is functionality
The position that can record.When each follow-up write and reading, according to same numbering in same office
In portion's array, find is same core position.Owing to the base address of local array is constant,
Therefore, if numbering identical, this record also it is equivalent to identical relative to the skew of array such that it is able to protect
The region of memory that card eventually points to also is identical.
For making the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing
Embodiments of the invention are described in detail.It should be noted that in the case of not conflicting, this Shen
Embodiment in please and the feature in embodiment can mutual combination in any.
In the present embodiment, as a example by x86 system pitching pile formula performance analysis tool, describe and realize the present invention's
Preferred version.The program is broadly divided into Program Generating when realizing and program runs two stages.Depend on below
Secondary it is introduced.
One, the Program Generating stage
There is following three main task in this stage: (11) are each tested function hooks performance measurement hook
Subfunction, and the numbering of incoming tested function is as its parameter;(12) tested letter in statistics tested program
The sum of number, and be placed in appointment variable;(13) be mastery routine and associated dynamic storehouse mounting special at the beginning of
Beginningization function, is used for initializing performance inventory array.As it is shown in figure 1, this Program Generating stage is concrete
Flow process is described as follows:
(11) compiler mounting performance measurement Hook Function, and generate code using tested function numbering as
The parameter of performance measurement Hook Function is incoming
Shown in Fig. 1, tested function is void test (int a, int b), entry and exit performance measurement hook
It is respectively hook_exit (int index), hook_enter (int index).In the compilation phase, compiler is at quilt
Porch insertion hook_enter (_ _ func_index) surveying function test is called, and exit is inserted
Hook_exit (_ _ func_index) calls.In the assembly phase, assembler is undefined _ func_index
Variable generates reorientation project.Linker one memory variable count of definition represents that tested function is numbered,
In the link stage, linker often processes a hook_enter reorientation project, just by enumerator count
Add 1, often run into one _ _ func_index reorientation project, just at its address specified, insert compilation and refer to
Make count as value incoming hook_enter or the hook_exit function of func_index.
(12) add up the sum of tested function, and put it in the special variable specified
The position that tested function is total is write owing to linker needs reorientation project to instruct, specifically,
The encapsulation function that one is input parameter with global variable func_total can be defined, will in encapsulation function
Value incoming for _ _ func_total is as return value.So, by calling this encapsulation function, can be from return value
In obtain the sum of tested function.Linker is revised in method and the task 11 of ginseng _ _ _ _ func_total
The way of incoming _ _ _ func index parameter is similar, is the most no longer described in detail, and it differs only in, by
Just can obtain when link completes in tested function sum, therefore, linker is running into _ _ func_total
Shi Buneng writes tested function numbering at that time immediately, but needs to record the position of reorientation, treats chain
After having connect, then write tested function sum at record position.
(13) it is that mastery routine and associated dynamic storehouse mount special initialization function and performance measurement hook letter
Number
Write initialization function _ _ init_fast_search, according to the tested function sum drawn in task 12
Create the memory array needed for performance inventory, and function property is set makes it can be automatic when file is loaded
Perform.Specifically, in same source file add performance measurement Hook Function hook_enter and
Hook_exit defines.These three function is compiled as a single file destination _ _ fast_search.o.Repair
Change link instruction (can directly revise the associated script of user, it is possible to adjusted in tools chain),
It is linked in mastery routine and each associated dynamic storehouse at terminal stage general _ _ fast_search.o.
Two, the program operation phase
Mainly there are two tasks in this stage: (21), at initial phase, according to the total number of tested function are
Performance inventory storage allocation space;(22) in program operation process, according to the numbering of tested function,
It is quickly found out the performance inventory of its correspondence.
(21) performance inventory array is initialized
When tested program or relevant tested dynamic base are loaded _ _ _ init_fast_search function obtain from
Dynamic execution, as shown in Figure 2.Mastery routine and dynamic base have each linked one _ _ fast_search.o, the most just
It is to say, mastery routine and each own one the _ _ init_fast_search function of dynamic base.Each
_ _ init_fast_search will create self place dynamic base or mastery routine according to tested function sum
Local Property record array.
(22) performance inventory of its correspondence is searched according to tested function numbering
Such as Fig. 2, can incoming self number during tested function call performance measurement Hook Function.Performance measurement
Hook Function by the numbering of tested function as subscript, at the Local Property that _ _ _ init_fast_search sets up
Record array can carry out the read-write of corresponding performance inventory.
Additionally, the embodiment of the present invention additionally provides quick mapping function performance in a kind of performance analysis tool
The device of record, this device mainly includes that performance inventory relating module and performance inventory search module, wherein:
Described performance inventory relating module is used for, at the generation phase of tested program, for described tested program
In each tested function be numbered, add up total number of tested function, and according to described in statistics
Total number of tested function creates Local Property record array;
Described performance inventory is searched module and is used for, in the operation phase of described tested program, according to described quilt
The numbering surveying function searches the performance note that described tested function is corresponding from described Local Property record array
Record.
Further, described performance inventory relating module farther includes compiler code signal generating unit and chain
Connect device function numbering signal generating unit,
Described compiler code signal generating unit is used for, and generates the code expressing tested function numbering;
Described linker function numbering signal generating unit, revises described compiler code and generates single when reorientation
The code of the described expression tested function numbering that unit generates, numbers for each described tested function generating function.
Further, described performance inventory relating module further comprises compiler Hook Function and implants list
Unit,
Described compiler Hook Function is implanted unit and is used for, at the generation phase of described tested program, for quilt
Survey function hooks performance measurement Hook Function, and using the numbering of tested function as performance measurement Hook Function
Incoming parameter;
Described performance inventory is searched module and is used for, in the operation phase of described tested program, and described tested letter
Number enters described performance measurement Hook Function when running, and described performance measurement Hook Function is from incoming parameter
Obtain the numbering of described tested function, and using the numbering of described tested function as array index, in local
Performance inventory array finds the performance inventory of correspondence.
Further, described performance inventory relating module further comprises the link of linker initialization function
Unit,
Described linker initialization function link unit is used for, after described linker completes link, by described
The initialization function of performance measurement Hook Function and performance analysis tool as a single file destination,
It is linked into described tested program and tested dynamic base respectively.
Further, described performance inventory relating module further comprises performance inventory array creating unit,
Described performance inventory array creating unit is used for, described tested program start or described tested dynamically
When storehouse is loaded, the initialization function of described tested program or described tested dynamic base is according to the institute of statistics
The total number stating tested function creates described Local Property record array.
These are only that the present invention's is preferable to carry out case, be not limited to the present invention, the present invention is also
Can there be other various embodiments, in the case of without departing substantially from present invention spirit and essence thereof, be familiar with this area
Technical staff can make various corresponding change and deformation according to the present invention, but these change accordingly and
Deformation all should belong to the protection domain of appended claims of the invention.
Obviously, those skilled in the art should be understood that each module of the above-mentioned present invention or each step can
To realize with general calculating device, they can concentrate on single calculating device, or distribution
On the network that multiple calculating devices are formed, alternatively, they can be with calculating the executable journey of device
Sequence code realizes, and performs it is thus possible to be stored in storing in device by calculating device, and
And in some cases, can be different from order herein perform shown or described by step, or
They are fabricated to respectively each integrated circuit modules, or the multiple modules in them or step are made
Single integrated circuit module is become to realize.So, the present invention is not restricted to any specific hardware and software
In conjunction with.