EOS--A smart system running tracking module

Source: Internet
Author: User
Tags fsm

What is the acronym for EOS, I guess it should be the error of System. The first contact with it was at UT that meeting. However, it is designed to be a large array, and it is not included in the call function and the line number, or time, just a few counts. When encoding, add or subtract an EOS is a little trouble, in addition to the call point, it is necessary to modify multiple points, such as the first to define, and then print the function of the name translation. The start time is OK, but the error code is more, the update is a bit troublesome, but also designed a script to automatically generate definitions and printing functions. But it's still not convenient, and developers sometimes prefer to use trace to print. Of course, Eos is not omnipotent, sometimes it is better to use trace than Eos, of course, the tradeoff is the best.

When do I need to use EOS? When the program needs to run for a long time, and want to do as much as possible without affecting the processing of the program's big traffic. such as a telephone exchange system, or a network service backend. If you use trace, the system is bound to be dragged down by a huge amount of print unless it is selectively enabled for a particular user session. If it is for a particular user tracking, it is equal to the selective neglect of the system operation errors, not conducive to the detection of stress test failures, especially some hidden faults, and some difficult to reproduce the failure.

After leaving UT, I improved the EOS design, which has very little knowledge of the program itself, relying on the flexibility to use the knowledge of compiling.

Let's talk about data structures and code:

struct error_no_type{constChar* errstr; Const Char* function; int Line ; int count; int When ;} PACKED eos_t;

The EOS data structure is simple, with two constant string pointers, followed by the file line number, count, and time. On a 32bits system, it accounted for 20 bytes altogether.

In the code provided by the elder brother, the pre-allocated Nhash is 19,997 records, which amounts to 390Kbytes space. For general systems, there is no problem with this memory overhead. Of course, it can be arbitrarily adjusted as needed, as follows:

/** /#defineEos_nhash 19997 = {{0,},};

Nhash can be completely emptied of data structures, but deleting a node operation is not supported.

The next step is to implement the code, which is simpler:

/*errstr Table*//*Hash a errstr*/StaticUnsigned errnovalue (Const Char*errstr) {  return* (unsigned*) Errstr;}intZeospeg (Const Char* Errstr,Const Char* Function,intLine ) {  if(!g_zeosenabled | |!errstr)return-1; intnum = Errnovalue (errstr)%Eos_nhash; intCount =Eos_nhash;  while(--count >=0) {eos_t*ptr = &Eosnhash[num]; if(!PTR-&GT;ERRSTR)//Not exist yet{ptr->errstr =Errstr; PTR->function =function; PTR->line =Line ; PTR->count =1; PTR->when =Ztime (); return 1; }    Else if(Ptr->errstr = = Errstr && Ptr->function = = function && Ptr->line = =Line ) {ptr->count + =1; PTR->when =Ztime (); }        if(++num >= Eos_nhash) num=0;/*try the next entry*/  }  //Overflow  return-1;}intZeosshow (Const Char*errstr) {  intnum; ZTRACEP ("EOS Enabled:%s\n", g_zeosenabled?"YES":"NO");  for(num=0; num<eos_nhash; num++) {eos_t*ptr = &Eosnhash[num]; if(!PTR-&GT;ERRSTR)Continue; if(errstr) {if(!strcasestr (Ptr->errstr, ERRSTR))Continue; ZTRACEP ("[%5d]:%s%d--%s:%d%s\n", num, Ptr->errstr, Ptr->count, Ptr->function, Ptr->line, Zctime (&ptr->When )); }    Else{ztracep ("[%5d]:%s%d--%s:%d%s\n", num, Ptr->errstr, Ptr->count, Ptr->function, Ptr->line, Zctime (&ptr->When )); }  }  return 0;}

Well, it's just a few lines of code, one is to add a new EOS record or statistic to the hash, and the other is to print out the error code. Finally, it is a user header file, as follows:

int zeospeg (constcharconstcharintint Zeosshow (constChar* errstr); /* overrides the per nodal Set_eos */ #undef Set_eos#define set_eos (EOS) Zeospeg (_STR (EOS), __function__, __line__)

Of course, when the user is in use, it is not recommended to call the PEG function directly here, then, then refused the kindness of brother. The program should use that macro definition instead of using the self-test code style that I have in footprint.c. That, is a negative, used to describe how EOS works!

We can use EOS as follows:

/*----------------------------------------------------------File Name:xxx.cDescription:Author: [Email protected ] (Bug fixing and consulting) date:2007-05-15------------------------------------------------------------*/#include"ztype_def.h"#include"zFootprintApi.h"intTesteospeg () {Set_eos (put any thing your like here.-only no comma); Set_eos (Ooh ... really?); Set_eos (Ooh ... really?); Set_eos (Ooh ... really?); Set_eos (sure. JustTry!); return 0;}

Then, run Zeosshow () under Cshell, and you'll get the result:

CSHELL_PRJ $ bin/Target_a.linux.i32.exe-testeospeg () $1/>testeospeg ()=0(0x0) <funcall:size=0>->zeosshow () $2/>zeosshow () EOS enabled:yes[4839]: Put any thing. Only no comma1--Testeospeg: -Mon Dec7  -: -: $  -[13012]: Ooh ... really?1--Testeospeg: -Mon Dec7  -: -: $  -[13013]: Ooh ... really?1--Testeospeg: theMon Dec7  -: -: $  -[13014]: Ooh ... really?1--Testeospeg: -Mon Dec7  -: -: $  -[15323]: Sure. JustTry!1--Testeospeg: -Mon Dec7  -: -: $  -=0(0x0) <funcall:size=153>->testeospeg () $3/>testeospeg ()=0(0x0) <funcall:size=344>->zeosshow () $4/>zeosshow () EOS enabled:yes[4839]: Put any thing. Only no comma2--Testeospeg: -Mon Dec7  -: -: -  -[ 4840]: Put any thing. Only no comma1--Testeospeg: -Mon Dec7  -: -: -  -[13012]: Ooh ... really?2--Testeospeg: -Mon Dec7  -: -: -  -[13013]: Ooh ... really?2--Testeospeg: theMon Dec7  -: -: -  -[13014]: Ooh ... really?2--Testeospeg: -Mon Dec7  -: -: -  -[13015]: Ooh ... really?1--Testeospeg: -Mon Dec7  -: -: -  -[13016]: Ooh ... really?1--Testeospeg: theMon Dec7  -: -: -  -[13017]: Ooh ... really?1--Testeospeg: -Mon Dec7  -: -: -  -[15323]: Sure. JustTry!2--Testeospeg: -Mon Dec7  -: -: -  -[15324]: Sure. JustTry!1--Testeospeg: -Mon Dec7  -: -: -  -=0(0x0) <funcall:size=153>->

Now, let's talk about the principle, and some precautions to use.

The first is a question about that string pointer. Someone will hesitate, how to just save a pointer, not a string it? This requires an understanding of the compiler and the elf file format. The string that appears in the source code of the program will eventually appear in the Elf file, and after the program is loaded, it will also appear in memory. The use of such strings is naturally safe.

Perhaps some people hesitate, Nhash is the best choice? Look what you want to do with it.
The biggest benefit of Nhash is that after the program is loaded, the resulting list is already initialized. In this way, you can add EOS to the earlier initialization code without worrying about whether the service is already available. The Nhash is lightweight and allows you to migrate EOS to any desired program.
If your system can execute an initialization function after loading and before it is necessary to call Eos, then of course you can choose a more efficient type of data structure such as AVL. Nhash does have a degradation problem, and when there is a lot of EOS, there are serious performance problems when there is a certain percentage in the Nhash entry. But this is not so easy, if we remember to make the Nhash entry much larger than the actual number of possible entries, and only provide EOS when appropriate. Uncontrolled use of EOS, not just performance issues, but more, you get too many EOS stats, just as bad as you have too many books and see but.

is the function name and line number necessary? I suggest that, otherwise, Set_eos will count the different statistical points as the same error code.

In addition, you can consider setting a switch to enable it, by default, the world is always someone who likes to talk about the performance problem, since there is a objection, then turn it off, so as not to waste their breath. Talking about performance issues with people of different properties can tarnish IQ, so don't argue, and tell them that Eos is just a test tool.

You need to make a reset statistics interface, so that you can easily detect problems during the test period. You can also make an output function to sort the EOS by time, so that many times you can see the running trajectory of the program, which is helpful for errors. The FSM trace is actually integrated with EOS, but it needs to be done by the user in the FSM call. Interested in studying the FSM I gave the children's shoes can try.

Finally, Eos is not omnipotent, in practice need to cooperate with the trace function, that is, the log printing function. Zlib in the ztrace is a good choice, there is a need to read!

EOS--A smart system running tracking module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.