Summary of the invention
Embodiments provide a kind of adjustment method and device of JS program, cause debugging inconvenient technical matters due to amendment at least to solve Node.js program.
According to an aspect of the embodiment of the present invention, provide a kind of adjustment method of JS program, comprising: the script file analysis result obtaining the JS program to be debugged loaded; Remove the above-mentioned script file analysis result obtained; When needs debugged program, again load above-mentioned JS program to be debugged; According to the above-mentioned JS program to be debugged of the debugging of loading result again.
Further, before the script file analysis result obtaining the JS program to be debugged loaded, said method also comprises: whether the part or all of code detected in above-mentioned JS program to be debugged is modified, if be modified, then perform the step of the script file analysis result obtaining the JS program to be debugged loaded.
Further, whether the part or all of code detected in above-mentioned JS program to be debugged has been modified and has comprised: whether the JS file monitoring the renewal of needs heat is changed; And/or detect whether editing machine has triggered removing script file analysis result trigger mechanism when preserving file.
Further, the means of editing machine trigger mechanism of triggering removing script file analysis result when preserving file comprise: editing machine sends trigger pip when preserving file to the process that above-mentioned JS program to be debugged is corresponding; And/or the URL specified accessed by editing machine when preserving file.
Further, while removing the above-mentioned script file analysis result obtained, said method also comprises: the adduction relationship of the above-mentioned script file that release obtains.
Further, before the adduction relationship of the above-mentioned script file of release acquisition, said method comprises: detect above-mentioned adduction relationship and whether comprise adduction relationship except the adduction relationship of the process corresponding with above-mentioned JS program to be debugged, wherein, if do not comprise, then perform the step of the adduction relationship of the above-mentioned script file that release obtains.
Further, after whether the above-mentioned adduction relationship of detection comprises the adduction relationship except the adduction relationship of the process corresponding with above-mentioned JS program to be debugged, said method comprises: if comprise, then do not perform the step of the adduction relationship of the above-mentioned script file that release obtains; If or comprise, whether the dormancy time of the process then further having detected above-mentioned adduction relationship except the adduction relationship of the process corresponding with above-mentioned JS program to be debugged identified exceeds threshold value, if exceed threshold value, then perform the step of the adduction relationship of the above-mentioned script file that release obtains, if do not exceed threshold value, then do not perform the step of the adduction relationship of the above-mentioned script file that release obtains.
According to the another aspect of the embodiment of the present invention, additionally provide a kind of debugging apparatus of JS program, comprising: acquiring unit, for obtaining the script file analysis result of the JS program to be debugged loaded; Clearing cell, for removing the above-mentioned script file analysis result of acquisition; Loading unit, for when needs debugged program, loads above-mentioned JS program to be debugged again; Debugging unit, for the basis above-mentioned JS program to be debugged of loading result debugging again.
Further, said apparatus also comprises: the first detecting unit, for before the script file analysis result obtaining the JS program to be debugged loaded, whether the part or all of code detected in above-mentioned JS program to be debugged is modified, when being modified, perform the function that above-mentioned acquiring unit obtains the script file analysis result of the JS program to be debugged loaded.
Whether further, above-mentioned first detecting unit comprises: monitor module, change for monitoring the JS file needing heat to upgrade; And/or detection module, whether trigger for detecting editing machine the trigger mechanism removing script file analysis result when preserving file.
Further, said apparatus also comprises trigger element, above-mentioned trigger element triggers the object of the trigger mechanism removing script file analysis result when preserving file for realizing editing machine, wherein, above-mentioned trigger element comprises: send signal trigger module, sends trigger pip for editing machine when preserving file to the process that above-mentioned JS program to be debugged is corresponding; And/or access URL trigger module, access the URL specified when preserving file for editing machine.
Further, said apparatus comprises: releasing unit, for while removing the above-mentioned script file analysis result obtained, and the adduction relationship of the above-mentioned script file that release obtains.
Further, said apparatus also comprises: the second detecting unit, for before the adduction relationship of the above-mentioned script file of release acquisition, detect above-mentioned adduction relationship and whether comprise adduction relationship except the adduction relationship of the process corresponding with above-mentioned JS program to be debugged, wherein, when not comprising, perform the function of the adduction relationship of the above-mentioned script file that the release of above-mentioned releasing unit obtains.
Further, said apparatus comprises: after whether the above-mentioned adduction relationship of detection comprises the adduction relationship except the adduction relationship of the process corresponding with above-mentioned JS program to be debugged, when comprising, do not perform the function of the adduction relationship of the above-mentioned script file that the release of above-mentioned releasing unit obtains; Or when comprising, second detecting unit, whether the dormancy time for the process having detected above-mentioned adduction relationship except the adduction relationship of the process corresponding with above-mentioned JS program to be debugged further identified exceeds threshold value, when exceeding threshold value, perform the step of the adduction relationship of the above-mentioned script file that the release of above-mentioned releasing unit obtains, when not exceeding threshold value, do not perform the step of the adduction relationship of the above-mentioned script file that the release of above-mentioned releasing unit obtains.
In embodiments of the present invention, adopt the mode of the script file analysis result removing the buffer memory when loading Node.js program in time, by obtaining the script file analysis result of the JS program to be debugged loaded; Remove the script file analysis result obtained; When needs debugged program, again load JS program to be debugged; JS program to be debugged is debugged according to loading result again, reach after update routine without the need to restarting the object that process can carry out debugging, thus achieve the technique effect being convenient to system debug JS program, and then solve Node.js program cause due to amendment debug inconvenience technical matters.
Embodiment
The present invention program is understood better in order to make those skilled in the art person, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the embodiment of a part of the present invention, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, should belong to the scope of protection of the invention.
It should be noted that, term " first ", " second " etc. in instructions of the present invention and claims and above-mentioned accompanying drawing are for distinguishing similar object, and need not be used for describing specific order or precedence.Should be appreciated that the data used like this can be exchanged in the appropriate case, so as embodiments of the invention described herein can with except here diagram or describe those except order implement.In addition, term " comprises " and " having " and their any distortion, intention is to cover not exclusive comprising, such as, contain those steps or unit that the process of series of steps or unit, method, system, product or equipment is not necessarily limited to clearly list, but can comprise clearly do not list or for intrinsic other step of these processes, method, product or equipment or unit.
Embodiment 1
According to the embodiment of the present invention, provide a kind of embodiment of the method for adjustment method of JS program, it should be noted that, can perform in the computer system of such as one group of computer executable instructions in the step shown in the process flow diagram of accompanying drawing, and, although show logical order in flow charts, in some cases, can be different from the step shown or described by order execution herein.
Fig. 1 is the process flow diagram of the adjustment method of a kind of optional JS program according to the embodiment of the present invention, and as shown in Figure 1, the method comprises the steps:
Step S102, obtains the script file analysis result of the JS program to be debugged loaded;
Step S104, removes the script file analysis result obtained;
Step S106, when needs debugged program, loads JS program to be debugged again;
Step S108, debugs JS program to be debugged according to loading result again.
Wherein, JS program can be node.js program, and it can be server end, also can be browser section.The module loader code heat that node.js heat can be utilized to dispose upgrades, and also, the module loader utilizing node.js heat to dispose realizes when needs debugged program, again loads the operation of JS program to be debugged when current process is not restarted.The core that realizes of Node.js module management is Module._cache, as long as remove the buffer memory of this module, when upper once require, Node.js module management will reload up-to-date code.
Due to Node.js program be loaded quote time, system can program code read analyzing script file, simultaneously storing and resolving result.And use the present invention, Node.js program is quoted and after buffer memory script file analysis result in loading, by obtaining and removing the script file analysis result of the JS program to be debugged loaded, and when needs debugged program, again load the JS program that this is to be debugged, now, the meeting corresponding script file analysis result of buffer memory again, debugs JS program to be debugged according to the analysis result of buffer memory when again loading.Like this, can avoid restarting process, direct execution debugging operations, especially for the JS program be modified, invention achieves after update routine without the need to restarting the object that process can carry out debugging, thus achieve the technique effect being convenient to system debug JS program, and then solve Node.js program cause due to amendment debug inconvenience technical matters.
Alternatively, before the script file analysis result obtaining the JS program to be debugged loaded, said method can also comprise:
S2, whether the part or all of code detected in JS program to be debugged is modified;
S4, if be modified, then performs the step of the script file analysis result obtaining the JS program to be debugged loaded.If be not modified, then do not perform the step of the script file analysis result of the JS program to be debugged that acquisition has loaded.
Like this, only when JS program code changes, just remove the corresponding script file analysis result of buffer memory before JS program does not change, and when JS program code does not change, retain the corresponding script file analysis result of the JS program of institute's buffer memory, reach and prevent the unnecessary object repeating removing, caching, alleviate system burden.
Alternatively, whether the part or all of code detected in JS program to be debugged has been modified can comprise:
S6, whether the JS file that monitoring needs heat to upgrade is changed; And/or
S8, detects editing machine and whether has triggered the trigger mechanism removing script file analysis result when preserving file.
Wherein, the JS file needing heat to upgrade refers in Node.js program development process, needs the JS file upgraded when not restarting current process because some or all of code is modified.It should be noted that, can include but not limited to whether monitor the routing file needing heat to upgrade changes in the present invention.Editing machine can trigger the trigger mechanism removing script file analysis result function when preserving file can be realized by the expanded function of editing machine self.If JS file has been modified, then editing machine can preserve amended JS file, now, just can trigger the trigger mechanism removing the JS file script file analysis result of buffer memory before modification.
Whether the part or all of code detected in JS program to be debugged by above-mentioned any one or various ways is modified, and can reach complete detection accurately to determine the object whether JS program to be debugged is modified.
Alternatively, the means of editing machine trigger mechanism of triggering removing script file analysis result when preserving file can comprise:
S10, editing machine sends trigger pip when preserving file to the process that JS program to be debugged is corresponding; And/or
S12, the URL specified accessed by editing machine when preserving file.
It should be noted that, if all codes realizing the service described by JS file are all in same module, then cannot carry out heat for module and load.Realize heat to load, the foundation code needing some cannot carry out heat renewal controls more new technological process.Now, need some to isolate code cleverly the service code of frequent updating and the foundation code infrequently upgraded are kept apart.After being separated foundation code and service code, also need the trigger mechanism arranging renewal, at this, startup file is monitored as trigger mechanism, and file is monitored and included but are not limited to monitoring routing file, but will monitor all files needing heat to upgrade.Except this means monitored by file, in conjunction with the expanded function of editing machine, the mode such as trigger pip or an access specific URL can also be sent to Node.js process when preserving during JS file and carry out Trigger update JS file.
Alternatively, while removing the script file analysis result obtained, said method can also comprise:
S14, the adduction relationship of the script file that release obtains.Like this, adduction relationship can be discharged simultaneously and remove corresponding caching record, can remove completely unmodified before the object of Node.js program, really reach without the need to restarting the object that process can carry out debugging after update routine, thus achieve the technique effect being convenient to system debug JS program.
Alternatively, before the adduction relationship of the script file of release acquisition, said method can also comprise:
S16, whether detection adduction relationship comprises the adduction relationship except the adduction relationship of process corresponding to the JS program with to be debugged, wherein, if do not comprise, then performs the step of the adduction relationship of the script file that release obtains.
Further alternatively, after whether detection adduction relationship comprises the adduction relationship except the adduction relationship of process corresponding to the JS program with to be debugged, said method also comprises:
S18, if comprise, does not then perform the step of the adduction relationship of the script file that release obtains; Or
S20, if comprise, whether the dormancy time of the process of the adduction relationship except the adduction relationship of the process that then further to have detected identified corresponding except the JS program with to be debugged exceeds threshold value, if exceed threshold value, then perform the step of the adduction relationship of the script file that release obtains, if do not exceed threshold value, then do not perform the step of the adduction relationship of the script file that release obtains.
Like this, when the adduction relationship whether adduction relationship comprise except the adduction relationship of process corresponding to the JS program with to be debugged being detected, by performing above-mentioned steps, the maloperation of being removed in the lump by other adduction relationship when removing current adduction relationship can be avoided.
Embodiment 2
According to the embodiment of the present invention, provide a kind of device embodiment of debugging apparatus of JS program.
Fig. 2 is the schematic diagram of the debugging apparatus of a kind of optional JS program according to the embodiment of the present invention, and as shown in Figure 2, this device comprises: acquiring unit 202, clearing cell 204, loading unit 206 and debugging unit 208.Acquiring unit 202, for obtaining the script file analysis result of the JS program to be debugged loaded; Clearing cell 204, for removing the script file analysis result of acquisition; Loading unit 206, for when needs debugged program, loads JS program to be debugged again; Debugging unit 208, for debugging JS program to be debugged according to loading result again.
Wherein, JS program can be node.js program, and it can be server end, also can be browser section.The module loader code heat that node.js heat can be utilized to dispose upgrades, and also, the module loader utilizing node.js heat to dispose realizes when needs debugged program, again loads the operation of JS program to be debugged when current process is not restarted.The core that realizes of Node.js module management is Module._cache, as long as remove the buffer memory of this module, when upper once require, Node.js module management will reload up-to-date code.
Due to Node.js program be loaded quote time, system can program code read analyzing script file, simultaneously storing and resolving result.And use the present invention, Node.js program is quoted and after buffer memory script file analysis result in loading, by obtaining and removing the script file analysis result of the JS program to be debugged loaded, and when needs debugged program, again load the JS program that this is to be debugged, now, the meeting corresponding script file analysis result of buffer memory again, debugs JS program to be debugged according to the analysis result of buffer memory when again loading.Like this, can avoid restarting process, direct execution debugging operations, especially for the JS program be modified, invention achieves after update routine without the need to restarting the object that process can carry out debugging, thus achieve the technique effect being convenient to system debug JS program, and then solve Node.js program cause due to amendment debug inconvenience technical matters.
Alternatively, said apparatus can also comprise: the first detecting unit.First detecting unit, for before the script file analysis result obtaining the JS program to be debugged loaded, whether the part or all of code detected in JS program to be debugged is modified, when being modified, perform the function that acquiring unit obtains the script file analysis result of the JS program to be debugged loaded.
Like this, only when JS program code changes, just remove the corresponding script file analysis result of buffer memory before JS program does not change, and when JS program code does not change, retain the corresponding script file analysis result of the JS program of institute's buffer memory, reach and prevent the unnecessary object repeating removing, caching, alleviate system burden.
Whether alternatively, the first detecting unit comprises: monitor module, change for monitoring the JS file needing heat to upgrade; And/or detection module, whether trigger for detecting editing machine the trigger mechanism removing script file analysis result when preserving file.
Wherein, the JS file needing heat to upgrade refers in Node.js program development process, needs the JS file upgraded when not restarting current process because some or all of code is modified.It should be noted that, can include but not limited to whether monitor the routing file needing heat to upgrade changes in the present invention.Editing machine can trigger the trigger mechanism removing script file analysis result function when preserving file can be realized by the expanded function of editing machine self.If JS file has been modified, then editing machine can preserve amended JS file, now, just can trigger the trigger mechanism removing the JS file script file analysis result of buffer memory before modification.
Whether the part or all of code detected in JS program to be debugged by above-mentioned any one or various ways is modified, and can reach complete detection accurately to determine the object whether JS program to be debugged is modified.
Alternatively, said apparatus can also comprise trigger element, trigger element triggers the object of the trigger mechanism removing script file analysis result when preserving file for realizing editing machine, wherein, trigger element can comprise: send signal trigger module, sends trigger pip for editing machine when preserving file to the process that JS program to be debugged is corresponding; And/or access URL trigger module, access the URL specified when preserving file for editing machine.
It should be noted that, if all codes realizing the service described by JS file are all in same module, then cannot carry out heat for module and load.Realize heat to load, the foundation code needing some cannot carry out heat renewal controls more new technological process.Now, need some to isolate code cleverly the service code of frequent updating and the foundation code infrequently upgraded are kept apart.After being separated foundation code and service code, also need the trigger mechanism arranging renewal, at this, startup file is monitored as trigger mechanism, and file is monitored and included but are not limited to monitoring routing file, but will monitor all files needing heat to upgrade.Except this means monitored by file, in conjunction with the expanded function of editing machine, the mode such as trigger pip or an access specific URL can also be sent to Node.js process when preserving during JS file and carry out Trigger update JS file.
Alternatively, said apparatus can comprise: releasing unit, for while removing the script file analysis result obtained, and the adduction relationship of the script file that release obtains.
Like this, adduction relationship can be discharged simultaneously and remove corresponding caching record, can remove completely unmodified before the object of Node.js program, really reach without the need to restarting the object that process can carry out debugging after update routine, thus achieve the technique effect being convenient to system debug JS program.
Alternatively, said apparatus can comprise: the second detecting unit, for before the adduction relationship of the script file of release acquisition, whether detection adduction relationship comprises the adduction relationship except the adduction relationship of process corresponding to the JS program with to be debugged, wherein, when not comprising, perform the function of the adduction relationship of the script file that releasing unit release obtains.
Alternatively, said apparatus can comprise: after whether detection adduction relationship comprises the adduction relationship except the adduction relationship of process corresponding to the JS program with to be debugged, when comprising, do not perform the function of the adduction relationship of the script file that releasing unit release obtains; Or when comprising, second detecting unit, whether the dormancy time for the process of the adduction relationship except the adduction relationship of the process that to have detected identified further corresponding except the JS program with to be debugged exceeds threshold value, when exceeding threshold value, perform the step of the adduction relationship of the script file that releasing unit release obtains, when not exceeding threshold value, do not perform the step of the adduction relationship of the script file that releasing unit release obtains.
Like this, when the adduction relationship whether adduction relationship comprise except the adduction relationship of process corresponding to the JS program with to be debugged being detected, by performing above-mentioned steps, the maloperation of being removed in the lump by other adduction relationship when removing current adduction relationship can be avoided.
The invention described above embodiment sequence number, just to describing, does not represent the quality of embodiment.
In the above embodiment of the present invention, the description of each embodiment is all emphasized particularly on different fields, in certain embodiment, there is no the part described in detail, can see the associated description of other embodiments.
In several embodiments that the application provides, should be understood that, disclosed technology contents, the mode by other realizes.Wherein, device embodiment described above is only schematic, the division of such as unit, can be that a kind of logic function divides, actual can have other dividing mode when realizing, such as multiple unit or assembly can in conjunction with or another system can be integrated into, or some features can be ignored, or do not perform.Another point, shown or discussed coupling each other or direct-coupling or communication connection can be by some interfaces, and the indirect coupling of unit or module or communication connection can be electrical or other form.
The unit illustrated as separating component or can may not be and physically separates, and the parts as unit display can be or may not be physical location, namely can be positioned at a place, or also can be distributed on multiple unit.Some or all of unit wherein can be selected according to the actual needs to realize the object of the present embodiment scheme.
In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, also can be that the independent physics of unit exists, also can two or more unit in a unit integrated.Above-mentioned integrated unit both can adopt the form of hardware to realize, and the form of SFU software functional unit also can be adopted to realize.
If integrated unit using the form of SFU software functional unit realize and as independently production marketing or use time, can be stored in a computer read/write memory medium.Based on such understanding, the part that technical scheme of the present invention contributes to prior art in essence in other words or all or part of of this technical scheme can embody with the form of software product, this computer software product is stored in a storage medium, comprises all or part of step of some instructions in order to make a computer equipment (can be personal computer, server or the network equipment etc.) perform each embodiment method of the present invention.And aforesaid storage medium comprises: USB flash disk, ROM (read-only memory) (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), portable hard drive, magnetic disc or CD etc. various can be program code stored medium.
The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.