CN101477491A - Method and apparatus for function running state statistics - Google Patents

Method and apparatus for function running state statistics Download PDF

Info

Publication number
CN101477491A
CN101477491A CNA2009100767489A CN200910076748A CN101477491A CN 101477491 A CN101477491 A CN 101477491A CN A2009100767489 A CNA2009100767489 A CN A2009100767489A CN 200910076748 A CN200910076748 A CN 200910076748A CN 101477491 A CN101477491 A CN 101477491A
Authority
CN
China
Prior art keywords
function
statistical
hook
proxy
hook function
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
CNA2009100767489A
Other languages
Chinese (zh)
Other versions
CN101477491B (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.)
New H3C Technologies Co Ltd
Original Assignee
Hangzhou H3C Technologies 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 Hangzhou H3C Technologies Co Ltd filed Critical Hangzhou H3C Technologies Co Ltd
Priority to CN2009100767489A priority Critical patent/CN101477491B/en
Publication of CN101477491A publication Critical patent/CN101477491A/en
Application granted granted Critical
Publication of CN101477491B publication Critical patent/CN101477491B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a device for recording function operation states. In the invention, a proxy function, a first hook function and a second hook function are preset. When the function states are recorded, the function states for recording are dynamically replaced by proxy function under the triggering of a guest replacement command, and the order of the proxy function change into the first hook function, the function for recording and the second hook function. Two hook functions have recording function, so that the state record to the function for recording can be conveniently realized through dynamic replacement.

Description

A kind of method and apparatus of function running state statistics
Technical field
The present invention relates to the function statistical technique of computer realm, be specifically related to the method and apparatus of function running state statistics.
Background technology
Communication products generally all are based on the embedded system of task scheduling.Task is the minimum operation unit that the various system resources of set realize specific function in the embedded system.A task comprises a plurality of functions, and the minimum that the function in the task can be considered to task constitutes the unit.
Embedded system depends on task usually and initiatively discharges between cpu resource realization task and dispatch.If certain or some task holding times is long, can cause other task to can not get scheduling, produce endless loop.Clock interrupts providing the statistical function to each task holding time.When certain task holding time is long in detecting system, can on screen, print call stack.Call stack comprises the title and the order of the task institute call function that holding time is long.The user analyzes according to the call stack that prints, and finds out and suspects the long function of holding time, then function under a cloud is carried out the running status test, with the position of location endless loop appearance.
The test of the running status of function comprises that mainly the working time of adding up function under a cloud, its mode are to increase respectively at each function under a cloud to be used for the statistical function statistics codes of working time in source code, thereby obtains the working time of function under a cloud.
But the statistics codes of increase is retained in the source code, and the statistics codes that each source code is performed these increases also can be performed one time, has taken extra system resource, influences the operational efficiency of source code.Therefore, preferably after statistics finishes, the statistics codes that increases is deleted.But, run into the situation that needs function running state statistics next time, need in source code, to add again statistics codes again.As seen, because the statistical project of existing function operation state need increase statistics codes in source code, therefore implement comparatively complicated.
Summary of the invention
In view of this, the invention provides a kind of method of function running state statistics, all in source code, increase statistics codes at every turn when not needing to add up, greatly reduce the complexity of function running state statistics.
This method comprises:
First Hook Function, second Hook Function are set and are used for the system that obtains by the proxy function of function running state statistics;
When function running state statistics, replacing under the triggering of order the user will be described proxy function by the statistical function dynamic replacement; Described proxy function sequence call first Hook Function, by the statistical function and second Hook Function;
The current operation information of register system when described first Hook Function is called;
The current operation information of register system when described second Hook Function is called is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down.
Wherein, described proxy function is used for obtaining by the working time of statistical function and/or is performed process by statistical function whether go out the current task switching.
Wherein, when acting on behalf of function and be used to obtain by the working time of statistical function, register system current time when described first Hook Function is called; Register system current time when described second Hook Function is called, and the current time of current time of self record and first Hook Function record subtracted each other, obtain by the working time of statistical function.
Preferably, this method further comprises: default described proxy function is carried out except that calling by the time span that instruction consumed the statistical function;
Second Hook Function further deducts default described time span after the current time of current time of self record and first Hook Function record is subtracted each other from subtract each other the result, obtain by the working time of statistical function.
Wherein, be used for obtaining when being performed process and whether going out current task and switch when acting on behalf of function by statistical function, the special character that task switch flag position was set to preset when described first Hook Function was called, described task switch flag position is changed when each task is switched; Confirm when described second Hook Function is called whether the special character that is provided with in first Hook Function is changed,, determine that then current task switches if do not change, otherwise, determine to have occurred the task switching.
Preferably, described proxy function is further used for adding up the execution number of times by statistical function;
This method further comprises: be provided for representing to be carried out by statistical function the number of times statistical variable of number of times, carry out proxy function described number of times statistical variable in season at every turn and increase progressively.
Preferably, described will be described proxy function by the statistical function dynamic replacement; Described proxy function sequence call first Hook Function, comprised by the statistical function and second Hook Function:
When being called, preserve, adopt the function address of proxy function to substitute, make program code jump to proxy function by the function address of statistical function by the function address of statistical function, parameter and return address by statistical function;
Described proxy function is called first Hook Function, the current operation information of register system in first Hook Function; Described first Hook Function is finished, and returns described proxy function;
Described proxy function recover to preserve by the parameter of statistical function and function address, call by statistical function; Be finished by statistical function and return described proxy function; Described proxy function is preserved by the rreturn value of statistical function;
Described proxy function is called second Hook Function, and the current operation information of register system in second Hook Function is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down; Described second Hook Function is finished, and returns described proxy function;
The described rreturn value by statistical function that described proxy function will be preserved deposits register in, call preservation by the return address of statistical function.
Preferably, this method further comprises: the write-protect of closing code segment before described replacing it; The write-protect of after being finished, opening code segment by the running status of statistical function statistics.
The present invention also provides a kind of device of function running state statistics, all increases statistics codes when not needing to add up in source code at every turn, greatly reduces the complexity of function running state statistics.
This device comprises:
The unit is set, is used for being provided with first Hook Function, second Hook Function and is used to the system that obtains by the proxy function of function running state statistics; The current operation information of register system when described first Hook Function is called; The current operation information of register system when described second Hook Function is called is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down;
Replace the unit, be used for when function running state statistics, replacing under the triggering of order the user will be described proxy function by the statistical function dynamic replacement; Described proxy function sequence call is described to be provided with first Hook Function of unit setting, by statistical function with described second Hook Function that the unit is provided with is set.
Wherein, the described unit that is provided with is provided with described proxy function and is used for obtaining by the working time of statistical function and/or is performed process by statistical function whether going out current task and switching;
When acting on behalf of function and be used to obtain by the working time of statistical function, the described register system current time when described first Hook Function in unit being set being set to be called; Register system current time when described second Hook Function is set to be called, the current time of self record and the current time of first Hook Function record are subtracted each other, obtain by the working time of statistical function;
Be used for obtaining when being performed process and whether going out current task and switch when acting on behalf of function by statistical function, the described setting is provided with the special character of task switch flag position for presetting when described first Hook Function in unit is set to be called, described task switch flag position is changed when each task is switched; Confirm when described second Hook Function is set to be called whether the special character that is provided with in first Hook Function is changed,, determine that then current task switches if do not change, otherwise, determine to have occurred the task switching.
Preferably, the described setting after the current time of the current time of second Hook Function record and first Hook Function being write down the unit subtracts each other further deducts default time span from subtract each other the result, obtain by the working time of statistical function; Described default time span is that proxy function is carried out except that calling by the time span that instruction consumed the statistical function.
Preferably, the described unit that is provided with is further used for being provided with expression by the number of times statistical variable of statistical function execution number of times, carries out proxy function described number of times statistical variable in season at every turn and increases progressively.
Preferably, described replacement unit comprise proxy function execution module, the first Hook Function execution module, the second Hook Function execution module, by statistical function execution module and modifying of order module;
Described modifying of order module when being called by statistical function, is preserved by the function address of statistical function, parameter and return address, adopts the function address of proxy function to substitute by the function address of statistical function, makes code jump to proxy function;
Described proxy function execution module is carried out proxy function, when beginning to carry out proxy function, controls the first Hook Function execution module and calls first Hook Function; From obtain that described modifying of order module preserves after first Hook Function returns by the parameter of statistical function and function address, control is called by statistical function by the statistical function execution module; Preserve by the rreturn value of statistical function from returned the back by statistical function; Control the second Hook Function execution module and call second Hook Function; Deposit register in from the described rreturn value that will preserve after second Hook Function returns by statistical function, call that described modifying of order module preserves by the return address of statistical function;
The described first Hook Function execution module is used to carry out first Hook Function, the current operation information of register system in first Hook Function;
The described second Hook Function execution module is used to carry out second Hook Function, and the current operation information of register system in second Hook Function is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down;
Described by the statistical function execution module, be used for carrying out by statistical function.
According to above technical scheme as seen, using the present invention can function running state statistics, and need not increased statistics codes by statistical function in source code at each.Specifically, have following beneficial effect:
1, the present invention sets in advance proxy function, first Hook Function and second Hook Function.Proxy function calls first Hook Function according to the order of sequence when carrying out, by the statistical function and second Hook Function.Because two Hook Functions possess statistical function, thus proxy function be equivalent to statistical function by statistical function.When finding that certain or some functions need be added up running status, adopt proxy function to replace by statistical function, just can realize easily by the statistic of statistical function.
Only need when 2, adding up to trigger replacement operation by order line, function is equivalent to dynamically add statistics codes in by statistical function after replacing at every turn, need not the picture prior art at being increased statistics codes by statistical function, realizes simply.
3, the proxy function that sets in advance, first Hook Function and second Hook Function are shared by all functions, therefore be applicable to various by statistical function, highly versatile and do not waste limited code space.
4, simultaneously, proxy function, first Hook Function and second Hook Function can not be performed after being set up and finishing, and only carry out after function address replaces, and the agent relation is just come into force; After statistics was finished, replaced the cancellation address, and the agent relation was lost efficacy, thereby the statistics codes that will dynamically add is easily rejected from source code.As seen, the setting of proxy function and Hook Function can not carried out efficient by influence function.
Description of drawings
Fig. 1 is the synoptic diagram of function running state statistics scheme of the present invention.
Fig. 2 is the synoptic diagram of related each function in the embodiment of the invention.
Fig. 3 is the method flow diagram of function running state statistics in the embodiment of the invention.
Fig. 4 is the apparatus structure synoptic diagram of function running state statistics in the embodiment of the invention.
Embodiment
The embodiment of the invention provides a kind of scheme of function running state statistics, and its basic thought is:
Be provided for obtaining proxy function by function running state statistics, and first Hook Function and second Hook Function.
Wherein, first Hook Function was called before by statistical function, the current operation information of register system when being called; Second Hook Function is called after by statistical function, the current operation information of register system when being called, and according to the current operation information statistics of the system of self and first Hook Function record by the running status of statistical function.Hook Function refers to a class function, and this class function can be dynamically embedded into source code when needed, is equivalent on " being hooked to " source code, can at any time Hook Function " won " from source code when not required.
When to a function statistics running status, replacing under the triggering of order the user will be proxy function by the statistical function dynamic replacement.When being called by statistical function, because replacement operation, code jumps to the proxy function place, this proxy function sequence call first Hook Function, by the statistical function and second Hook Function, to realize the statistics of function operation state.Second Hook Function is finished, and calls by the return address of statistical function, returns the position of calling by statistical function.
Give an example, as shown in Figure 1, function B should call function A, in order to obtain the running status statistical information of function A, proxy function replacement function A is adopted in the capable configuration of user input commands, under the triggering of user command, the function address of record function A to be informing that proxy function is that function A is acted on behalf of, and the function address of function A replaced with the function address of proxy function.When function B call function A, program jumps to the proxy function run time version, proxy function is according to the function address of the function A that sets in advance and note at this moment, and order is carried out first Hook Function, function A and second Hook Function, thereby obtains the running status statistical information of function A.
As seen, the present invention sets in advance proxy function, first Hook Function and second Hook Function.Proxy function calls first Hook Function according to the order of sequence when carrying out, by the statistical function and second Hook Function.Because two Hook Functions possess statistical function, thus proxy function be equivalent to statistical function by statistical function.When finding that certain or some functions need be added up running status, adopt proxy function to replace by statistical function, just can realize easily by the statistic of statistical function.
Only need to trigger replacement operation during each statistics, after function is replaced, be equivalent in by statistical function, dynamically add statistics codes, need not the picture prior art, realize simply at being increased statistics codes by statistical function by order line.
Secondly, the proxy function that sets in advance, first Hook Function and second Hook Function are not at certain function setup, but are shared by all functions, so highly versatile, are applicable to various by statistical function.
Simultaneously, proxy function, first Hook Function and second Hook Function can not be performed after being set up and finishing, and only carry out after function address replaces, and the agent relation is just come into force; After statistics was finished, replaced the cancellation address, and the agent relation was lost efficacy, thereby the statistics codes that will dynamically add is easily rejected from source code.As seen, the setting of proxy function and Hook Function can not carried out efficient by influence function.
Adopt technical scheme of the present invention to make proxy function possess the statistical function of one or more function operation status informations by the particular content of design first Hook Function and second Hook Function.For example can statistical function working time, function be performed that the task that whether occurs in the process is switched, function is carried out information such as number of times.Different information can be provided with different proxy function respectively and add up, and also can utilize same proxy function to add up multiple information.
Below in conjunction with the accompanying drawing embodiment that develops simultaneously, describe the present invention.Be that example is described with the statistical function execution time in following examples.
Before statistics, proxy function and two Hook Functions are set at first.Below in conjunction with Fig. 2 the process of function B call function A and the proxy function and the Hook Function of setting are introduced one by one:
Function A: being the function that is called, also is by statistical function.When function B call function A, under to the function A statistics situation of working time, as shown in Figure 2, at first preserve the return address behind the call function A, carry out function A then.The implementation of function A is: the stack space of preparing function A, to the parameter of function A and the local variable pop down of using, carry out the instruction in the function A function body, discharge the stack space that function A takies, at last function A rreturn value being put into the register SCMD counts B and takes, and the call function link order turns back to the code position of return address indication, return function B here.
The first Hook Function PreF: be the Hook Function of carrying out before the call function A, register system current time when this Hook Function is called.
The second Hook Function PostF: the Hook Function of carrying out behind the call function A, register system current time when this Hook Function is called, the current time of self record and the time of first Hook Function PreF record are compared, obtain the mistiming, this mistiming is exactly the working time of function A.
Proxy function ProxyF: when the user is provided with proxy function and replaces being called function by order line, the function that is called of appointment is taken over.
The user by input command capable the setting before proxy function replaces function A, do not substitute or carry out relation between function A, PreF, PostF and the ProxyF; When the user is provided with proxy function replacement function A by order line after, produces between function A, PreF, PostF and the ProxyF and substitute and carry out relation.Below, show the process flow diagram of function running state statistics in the embodiment of the invention in conjunction with Fig. 3, to being set, proxy function replaces after the function A, and the flow process of function B call function A is described.As shown in Figure 3, this flow process may further comprise the steps:
Step 0: during function B call function A, by revising several instructions in front of function A, return address, the parameter of function A and the function address of function A behind the preservation call function A.
The function address of step 1, employing ProxyF function replaces the function address of function A, thereby makes program code directly jump to the ProxyF function.
Wherein, when instruct several of the fronts of modification function A, realize by revising the function address internal memory.Have metadata cache (data cache) and Instructions Cache (instructioncache) between system CPU and the internal memory.Wherein, metadata cache is used for temporary transient storage and sends the computing desired data to CPU; Instructions Cache is used for temporary transient storage and sends all kinds of operational orders to CPU.Amended instruction at first is kept in the metadata cache, is delivered in the internal memory then.Owing to when revising the instruction of function A, do not have the instruction of function A in the update instruction buffer memory, if therefore direct instruction with function A in the Instructions Cache is delivered to CPU, what then CPU carried out is to revise preceding function A instruction, and realization is replaced.Therefore present embodiment is after the instruction of revising function A, the flush instructions cache contents, and when the instruction of CPU function reading A, Instructions Cache can obtain the instruction of amended function A from internal memory, thereby realizes replacing.
Step 2:ProxyF function call PreF function.
The step 3:PreF function register system current time.
Step 4: return the ProxyF function, the ProxyF function recovers parameter and the function address of the function A of preservation.
Step 5: according to parameter and the function address call function A of the function A that recovers.It is identical with implementation among Fig. 2 to carry out the implementation of function A, comprises that stack space from preparation function A is to function A rreturn value is put into register and call function link order.What herein, the call function link order was returned is the ProxyF function.
Step 6: function A is finished, and returns the ProxyF function.
Step 7:ProxyF function is preserved the rreturn value of function A, and calls the PostF function.
The step 8:PostF function register system current time, the current time of self record and the current time of PreF function record to be subtracted each other, the mistiming that obtains is the time of function A operation.
Because the embodiment of the invention has increased the processing command of ProxyF, general tens tick consuming time (tick is the clock-unit of CPU) of the processing command of increase, these tens tick can exert an influence to the time statistics.Wherein the processing command of Zeng Jiaing is the instruction except that call function A in the ProxyF function.In order to make the time statistics more accurate, preferably, default ProxyF function is carried out the time span X that instruction consumed except that call function A.The PostF function further deducts default time span X after the current time of current time of self record and PreF function record is subtracted each other from subtract each other the result, obtain by the working time of statistical function.
Step 9: return the ProxyF function, the rreturn value of the function A that the ProxyF function is preserved step 7 deposits the register SCMD in and counts B and take, and the code place of call function A is returned in the return address of call function A.
So far, finished the process of statistical function A working time.
Flow process shown in Fig. 3 is the statistical function A flow process of working time, in practice, whether goes out current task switching, the then special character that task switch flag position is set to preset in the PreF function if wish monitoring when carrying out function A; When each task is switched, all this special character is changed; Confirm in the PostF function whether the special character that is provided with in the PreF function is changed,, determine that then current task switches, and switches otherwise determine current task if do not change.
If wish the execution number of times of monitoring function A, the number of times statistical variable of the overall situation then is set, carry out proxy function number of times statistical variable in season at every turn and increase progressively, for example add 1, the invoked number of times of value representation function A of number of times statistical variable.Wherein, the increment operation of carrying out when at every turn carrying out proxy function can be each PreF function when being called, or each PostF function is carried out when being called.Certainly, when the number of times statistical variable is added up a new function, need at first be initialized to initial value, for example be initialized as 0.
In practice, the code segment of generic function has all carried out write-protect.For such situation, the present invention need carry out replacement operation to function, before the dynamic replacement function, more particularly is to revise to be needed dynamically to close write-protect before several leading the instruction of statistical function therefore, opens write-protect again after finishing statistics.
In order to realize above-mentioned function operation statistic method, the embodiment of the invention also provides a kind of function operation statistic device.Fig. 4 is the structural representation of function operation statistic device in the embodiment of the invention.As shown in Figure 4, this device comprises:
Unit 41 is set, is used for being provided with PreF function, PostF function and is used to the system that obtains by the ProxyF function of function running state statistics.PreF function, PostF function and ProxyF function are shared by all functions, and its function has had detailed description in aforementioned statistical method.
Replace unit 42, when being used for function statistics running status, replacing under the triggering of order the user will be the ProxyF function by the statistical function dynamic replacement.The ProxyF function is when carrying out, and sequence call is provided with PreF function that unit 41 is provided with, by statistical function with the PostF function that unit 41 is provided with is set.
Wherein, unit 41 being set is provided with the ProxyF function and is used for obtaining by the working time of statistical function and/or is performed process by statistical function whether going out current task and switching:
When the ProxyF function is used to obtain by the working time of statistical function, unit 41 is set with PreF function setup register system current time when being called; With PostF function setup register system current time when being called, and the current time of self record and the current time of PreF function record subtracted each other, obtain by the working time of statistical function.Preferably,, further from subtract each other the result, deduct default time span X, obtain by the working time of statistical function when being provided with after the current time of current time of PostF function record and PreF function being write down unit 41 subtracts each other.This time span X carries out except that calling by the time span that instruction consumed the statistical function for the ProxyF function.
When the ProxyF function is used for obtaining when being performed process and whether going out current task and switch by statistical function, it is the special character that task switch flag position is set to preset when being called with the PreF function setup that unit 41 is set, and this task switch flag position is changed when each task is switched; With the PostF function setup is to confirm whether the special character that is provided with in first Hook Function is changed when being called, if do not change, determines that then current task switches, otherwise, determine to have occurred the task switching.Wherein, each task changes the operation of task switch flag position when switching can be carried out by the module of other responsible task switching monitoring, not shown.
Unit 41 is set also carries out the number of times statistical function for ProxyF function setup function.In this case, unit 41 is set expression is set, carry out proxy function this number of times statistical variable in season at every turn and increase progressively, for example add 1 by the number of times statistical variable of statistical function execution number of times.
Replace unit 42 comprise specifically comprise proxy function execution module 422, the first Hook Function execution module 423, the second Hook Function execution module 424, by statistical function execution module 425 and modifying of order module 421.Wherein,
Modifying of order module 421, when being called by statistical function, by revising by several leading instruction of statistical function, preservation is by the function address of statistical function, by the parameter of statistical function with by the return address of statistical function, adopt the function address of ProxyF function to substitute, make code jump to the ProxyF function by the function address of statistical function.
This modifying of order module 421 was further used for before the dynamic replacement function, was specifically to revise the write-protect of being closed code segment before several leading the instruction of statistical function; The write-protect of after being finished, opening code segment by the running status of statistical function statistics.
Proxy function execution module 422 is carried out the ProxyF function, when beginning to carry out the ProxyF function, controls the first Hook Function execution module 423 and calls the PreF function; From obtain that modifying of order module 421 preserves after the PreF function returns by the parameter of statistical function and function address, control by statistical function execution module 524 according to being called by statistical function by the parameter of statistical function and function address; Preserve by the rreturn value of statistical function from returned the back by statistical function; Control the second Hook Function execution module 424 and call the PostF function; Deposit register in from the rreturn value that will preserve after the PostF function returns by statistical function, call instruction modified module 421 preserve by the return address of statistical function.
The first Hook Function execution module 423 is used to carry out the PreF function, the current operation information of register system in the PreF function.
The second Hook Function execution module 424 is used to carry out the PostF function, and the current operation information of register system in the PostF function is added up by the running status of statistical function according to the current operation information of system that self and PreF function write down.
By statistical function execution module 425, be used for carrying out by statistical function.
In sum, more than be preferred embodiment of the present invention only, be not to be used to limit protection scope of the present invention.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (13)

1, a kind of method of function running state statistics is characterized in that, this method comprises:
First Hook Function, second Hook Function are set and are used for the system that obtains by the proxy function of function running state statistics;
When function running state statistics, replacing under the triggering of order the user will be described proxy function by the statistical function dynamic replacement; Described proxy function sequence call first Hook Function, by the statistical function and second Hook Function;
The current operation information of register system when described first Hook Function is called;
The current operation information of register system when described second Hook Function is called is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down.
2, the method for claim 1 is characterized in that, described proxy function is used for obtaining by the working time of statistical function and/or is performed process by statistical function whether go out the current task switching.
3, method as claimed in claim 2 is characterized in that, when acting on behalf of function and be used to obtain by the working time of statistical function, and register system current time when described first Hook Function is called; Register system current time when described second Hook Function is called, and the current time of current time of self record and first Hook Function record subtracted each other, obtain by the working time of statistical function.
4, method as claimed in claim 3 is characterized in that, this method further comprises: default described proxy function is carried out except that calling by the time span that instruction consumed the statistical function;
Second Hook Function further deducts default described time span after the current time of current time of self record and first Hook Function record is subtracted each other from subtract each other the result, obtain by the working time of statistical function.
5, method as claimed in claim 2, it is characterized in that, be used for obtaining when being performed process and whether going out current task and switch when acting on behalf of function by statistical function, the special character that task switch flag position was set to preset when described first Hook Function was called, described task switch flag position is changed when each task is switched; Confirm when described second Hook Function is called whether the special character that is provided with in first Hook Function is changed,, determine that then current task switches if do not change, otherwise, determine to have occurred the task switching.
6, the method for claim 1 is characterized in that, described proxy function is further used for adding up the execution number of times by statistical function;
This method further comprises: be provided for representing to be carried out by statistical function the number of times statistical variable of number of times, carry out proxy function described number of times statistical variable in season at every turn and increase progressively.
7, the method for claim 1 is characterized in that, described will be described proxy function by the statistical function dynamic replacement; Described proxy function sequence call first Hook Function, comprised by the statistical function and second Hook Function:
When being called, preserve, adopt the function address of proxy function to substitute, make program code jump to proxy function by the function address of statistical function by the function address of statistical function, parameter and return address by statistical function;
Described proxy function is called first Hook Function, the current operation information of register system in first Hook Function; Described first Hook Function is finished, and returns described proxy function;
Described proxy function recover to preserve by the parameter of statistical function and function address, call by statistical function; Be finished by statistical function and return described proxy function; Described proxy function is preserved by the rreturn value of statistical function;
Described proxy function is called second Hook Function, and the current operation information of register system in second Hook Function is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down; Described second Hook Function is finished, and returns described proxy function;
The described rreturn value by statistical function that described proxy function will be preserved deposits register in, call preservation by the return address of statistical function.
8, the method for claim 1 is characterized in that, this method further comprises: the write-protect of closing code segment before described replacing it; The write-protect of after being finished, opening code segment by the running status of statistical function statistics.
9, a kind of device of function running state statistics is characterized in that, this device comprises:
The unit is set, is used for being provided with first Hook Function, second Hook Function and is used to the system that obtains by the proxy function of function running state statistics; The current operation information of register system when described first Hook Function is called; The current operation information of register system when described second Hook Function is called is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down;
Replace the unit, be used for when function running state statistics, replacing under the triggering of order the user will be described proxy function by the statistical function dynamic replacement; Described proxy function sequence call is described to be provided with first Hook Function of unit setting, by statistical function with described second Hook Function that the unit is provided with is set.
10, device as claimed in claim 9 is characterized in that, the described unit that is provided with is provided with described proxy function and is used for obtaining by the working time of statistical function and/or is performed process by statistical function whether going out current task and switching;
When acting on behalf of function and be used to obtain by the working time of statistical function, the described register system current time when described first Hook Function in unit being set being set to be called; Register system current time when described second Hook Function is set to be called, the current time of self record and the current time of first Hook Function record are subtracted each other, obtain by the working time of statistical function;
Be used for obtaining when being performed process and whether going out current task and switch when acting on behalf of function by statistical function, the described setting is provided with the special character of task switch flag position for presetting when described first Hook Function in unit is set to be called, described task switch flag position is changed when each task is switched; Confirm when described second Hook Function is set to be called whether the special character that is provided with in first Hook Function is changed,, determine that then current task switches if do not change, otherwise, determine to have occurred the task switching.
11, device as claimed in claim 10, it is characterized in that, the described setting after the current time of the current time of second Hook Function record and first Hook Function being write down the unit subtracts each other further deducts default time span from subtract each other the result, obtain by the working time of statistical function; Described default time span is that proxy function is carried out except that calling by the time span that instruction consumed the statistical function.
12, device as claimed in claim 10 is characterized in that, the described unit that is provided with is further used for being provided with expression by the number of times statistical variable of statistical function execution number of times, carries out proxy function described number of times statistical variable in season at every turn and increases progressively.
13, device as claimed in claim 9 is characterized in that, described replacement unit comprises proxy function execution module, the first Hook Function execution module, the second Hook Function execution module, by statistical function execution module and modifying of order module;
Described modifying of order module when being called by statistical function, is preserved by the function address of statistical function, parameter and return address, adopts the function address of proxy function to substitute by the function address of statistical function, makes code jump to proxy function;
Described proxy function execution module is carried out proxy function, when beginning to carry out proxy function, controls the first Hook Function execution module and calls first Hook Function; From obtain that described modifying of order module preserves after first Hook Function returns by the parameter of statistical function and function address, control is called by statistical function by the statistical function execution module; Preserve by the rreturn value of statistical function from returned the back by statistical function; Control the second Hook Function execution module and call second Hook Function; Deposit register in from the described rreturn value that will preserve after second Hook Function returns by statistical function, call that described modifying of order module preserves by the return address of statistical function;
The described first Hook Function execution module is used to carry out first Hook Function, the current operation information of register system in first Hook Function;
The described second Hook Function execution module is used to carry out second Hook Function, and the current operation information of register system in second Hook Function is added up by the running status of statistical function according to the current operation information of system that self and described first Hook Function write down;
Described by the statistical function execution module, be used for carrying out by statistical function.
CN2009100767489A 2009-01-16 2009-01-16 Method and apparatus for function running state statistics Expired - Fee Related CN101477491B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2009100767489A CN101477491B (en) 2009-01-16 2009-01-16 Method and apparatus for function running state statistics

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2009100767489A CN101477491B (en) 2009-01-16 2009-01-16 Method and apparatus for function running state statistics

Publications (2)

Publication Number Publication Date
CN101477491A true CN101477491A (en) 2009-07-08
CN101477491B CN101477491B (en) 2011-06-08

Family

ID=40838212

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2009100767489A Expired - Fee Related CN101477491B (en) 2009-01-16 2009-01-16 Method and apparatus for function running state statistics

Country Status (1)

Country Link
CN (1) CN101477491B (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103345440A (en) * 2013-06-05 2013-10-09 深圳天珑无线科技有限公司 Statistical method and device of accumulated running time of electronic equipment and electronic equipment
CN105630651A (en) * 2015-12-28 2016-06-01 北京像素软件科技股份有限公司 Method and device for monitoring performance
CN105701004A (en) * 2014-11-28 2016-06-22 深圳市腾讯计算机系统有限公司 Application test method and apparatus
CN106055462A (en) * 2016-05-20 2016-10-26 腾讯科技(深圳)有限公司 Method and device for duration acquisition
CN106547883A (en) * 2016-11-03 2017-03-29 北京集奥聚合科技有限公司 A kind of processing method and system of user-defined function UDF ruuning situations
CN107038108A (en) * 2015-08-20 2017-08-11 腾讯科技(深圳)有限公司 The method of testing and device of software
CN107168857A (en) * 2017-03-31 2017-09-15 武汉斗鱼网络科技有限公司 The method and component of a kind of function call in statistics application program
WO2019071535A1 (en) * 2017-10-12 2019-04-18 深圳市汇顶科技股份有限公司 Computer storage medium, and program running monitoring method and device
CN109857628A (en) * 2017-11-30 2019-06-07 北京高德云图科技有限公司 Dynamic UI business end code method for testing performance and device
CN109947414A (en) * 2019-01-31 2019-06-28 苏州德铂思电子科技有限公司 A kind of dynamic Hook Function implementation method based on Vxworks system
CN110580219A (en) * 2019-07-16 2019-12-17 许昌许继软件技术有限公司 Embedded device function performance online test method and device and storage medium
CN110806968A (en) * 2018-08-06 2020-02-18 阿里巴巴集团控股有限公司 Application program running information acquisition method and device
CN111736817A (en) * 2020-07-21 2020-10-02 平安国际智慧城市科技股份有限公司 Method and device for determining function execution time consumption, terminal equipment and storage medium
WO2023036076A1 (en) * 2021-09-13 2023-03-16 华为技术有限公司 Software monitoring method and related apparatus

Cited By (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103345440B (en) * 2013-06-05 2017-05-03 深圳天珑无线科技有限公司 Statistical method and device of accumulated running time of electronic equipment and electronic equipment
CN103345440A (en) * 2013-06-05 2013-10-09 深圳天珑无线科技有限公司 Statistical method and device of accumulated running time of electronic equipment and electronic equipment
CN105701004A (en) * 2014-11-28 2016-06-22 深圳市腾讯计算机系统有限公司 Application test method and apparatus
CN107038108B (en) * 2015-08-20 2020-11-03 腾讯科技(深圳)有限公司 Software testing method and device
CN107038108A (en) * 2015-08-20 2017-08-11 腾讯科技(深圳)有限公司 The method of testing and device of software
CN105630651A (en) * 2015-12-28 2016-06-01 北京像素软件科技股份有限公司 Method and device for monitoring performance
CN106055462A (en) * 2016-05-20 2016-10-26 腾讯科技(深圳)有限公司 Method and device for duration acquisition
CN106547883A (en) * 2016-11-03 2017-03-29 北京集奥聚合科技有限公司 A kind of processing method and system of user-defined function UDF ruuning situations
CN106547883B (en) * 2016-11-03 2021-02-19 北京集奥聚合科技有限公司 Method and system for processing User Defined Function (UDF) running condition
CN107168857A (en) * 2017-03-31 2017-09-15 武汉斗鱼网络科技有限公司 The method and component of a kind of function call in statistics application program
CN107168857B (en) * 2017-03-31 2021-01-01 武汉斗鱼网络科技有限公司 Method and assembly for counting function calls in application program
WO2019071535A1 (en) * 2017-10-12 2019-04-18 深圳市汇顶科技股份有限公司 Computer storage medium, and program running monitoring method and device
CN109923526A (en) * 2017-10-12 2019-06-21 深圳市汇顶科技股份有限公司 Computer storage medium, program operational monitoring method and device
CN109857628A (en) * 2017-11-30 2019-06-07 北京高德云图科技有限公司 Dynamic UI business end code method for testing performance and device
CN110806968A (en) * 2018-08-06 2020-02-18 阿里巴巴集团控股有限公司 Application program running information acquisition method and device
CN110806968B (en) * 2018-08-06 2024-04-09 阿里巴巴集团控股有限公司 Application program running information acquisition method and device
CN109947414A (en) * 2019-01-31 2019-06-28 苏州德铂思电子科技有限公司 A kind of dynamic Hook Function implementation method based on Vxworks system
CN110580219A (en) * 2019-07-16 2019-12-17 许昌许继软件技术有限公司 Embedded device function performance online test method and device and storage medium
CN111736817A (en) * 2020-07-21 2020-10-02 平安国际智慧城市科技股份有限公司 Method and device for determining function execution time consumption, terminal equipment and storage medium
WO2023036076A1 (en) * 2021-09-13 2023-03-16 华为技术有限公司 Software monitoring method and related apparatus

Also Published As

Publication number Publication date
CN101477491B (en) 2011-06-08

Similar Documents

Publication Publication Date Title
CN101477491B (en) Method and apparatus for function running state statistics
CN103927198B (en) A kind of software method for cleaning and device
CN101226487B (en) Method for implementing inner core level thread library based on built-in Linux operating system
KR20010030592A (en) Data processing unit with hardware assisted context switching capability
Brown et al. An introduction to the Kent C++ CSP Library
US8271768B2 (en) Concurrent handling of exceptions in received aggregate exception structure with supplied exception handlers and marking handled exceptions
CN101819539B (en) Interrupt nesting method for transplanting muCOS-II to ARM7
CN104657258B (en) A kind of method and device from Java bytecode to target process that injecting
CN110147281A (en) Optimize method, apparatus, the electronic equipment that snowflake algorithm is applied in financial business
CN104965708B (en) A kind of EMS memory management process and device of application program operational process
CN106331065A (en) Proxy application for host system with service container and system
CN107122216B (en) Dynamic loading method for embedded real-time operating system
CN103793249A (en) Multithreading preloading method for class library in Java virtual machine
CN110291508A (en) Garbage collector
CN103197962B (en) Multi-process state switching method and device
US8146085B2 (en) Concurrent exception handling using an aggregated exception structure
CN107820605A (en) System and method for the optimization of dynamic low latency
CN104778049A (en) Implementation method used for human-computer interaction APP (application) on the basis of Android system and interaction system
CN109582382B (en) Loading method and device of configuration information, storage medium and terminal equipment
CN107506293B (en) Software performance data acquisition method and device
CN107391274A (en) The processing method and processing device of deferred information
CN101950272A (en) Memory management method and device in embedded system
CN101882091A (en) Implementation method for thread local storage and device
CN115185576A (en) Process customization method and system based on process application system
CN111090627B (en) Log storage method and device based on pooling, computer equipment and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 310052 Binjiang District Changhe Road, Zhejiang, China, No. 466, No.

Patentee after: Xinhua three Technology Co., Ltd.

Address before: 310053 Hangzhou hi tech Industrial Development Zone, Zhejiang province science and Technology Industrial Park, No. 310 and No. six road, HUAWEI, Hangzhou production base

Patentee before: Huasan Communication Technology Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20110608

Termination date: 20200116