C ++ Profile Auxiliary Template

zhaozj2021-02-08  266

Profile See http://www.9cbs.net/develop/read_article.asp?id=18504 What should I translate? Hope to inform (similar to Rational Quantify is now included in new Rational PurifyPlus http://www-900.ibm.com/cn/software/rational/products/purifyplus/index.shtml)

The software developed by our company is highly required by the program's running speed, so PROFILE is very necessary but VC6's Profile and Rational Quantify are very annoying.

If it is the default manner that uses my program originally calculated 10 minutes to run, it is Of course, I can use it for this time and drink tea with my colleagues. After 1 hour, I will drink tea and chat. There is no mood to continue Profile.

If it is a custom-to-analysis code check related information setting parameters my god! Trouble!

Rational Quantify has a request: Debug Edition 886 Rational Quantify

When I met the VC6's PROFILE, I used the same parameters to calculate the same parameters. The longest b function accounted for time 0 ??? Sometimes the longest A function occupied by the B function accounts for time 0 ??? The result of Profile is always blamed, and maybe I won't use?

However, it didn't matter my own DIY an example: Procedure_time (1, Sleep (200)); for (char i = 0; i! = 5; i) {total_count (2); total_time (3); rt = func_time 4, mysleep (200));} After running the result: 4: 5 Times, 1.00 Seconds.3: 5 Times, 1.00 Seconds.2: 5 Times.1: 1 Times, 0.20 Seconds. It is convenient?

As a result, it will be displayed on the console. If your program is not a console program, it doesn't matter. I recommend a good Dongdong DebugViewHttp://www.sysinternals.com/ntw2k/freeware/debugview.shtml results will also be displayed

I think this play is two o'clock. 1. You can't use string to mark Total_Time (3); inside (3) cannot be used ("mysleep") I think a method is similar to make_mask ('m', 'y) ',' S ',' l ',' e ',' e ',' p ') converts it into a __INT64 final result in the result of the result of the __int64 to the string, but every time you have Write something similar to Make_Mask ('M', 'Y', 'S', 'L', 'E', 'E', 'P') ... Rao me ~~~ 2. It is always This seems to have an extra sale. There is no way to solve the problem. If it is a release version, the error is very small.

The place to pay attention to: 0. Sign only can only be integer range: 0 <= x <= int_max with the same number to make a sign timing / count result superimposed (Total_count only superimposed with Total_Count): total_time (0); Procedure_time 0, Sleep (200)); Total_Count (0); Total_count (0); Total_time and procedure_time The result is superimposed on the results of TOTAL_COVNT before and after it also overlapping

1. If the function returns a reference (&) or constant reference (const &), although it can be compiled with REF_FUNC_TIME, it can be compiled with func_time but will change the original mode of operation. Remove the additional overhead of the return value

3. If the function does not return, only procedure_time is allowed

4. Total_count sometimes you only want to count the cost to minimize this

5. mmm ... Nothing ...

what? Linux's? It doesn't matter to change GetTickCount to CLOCK to change OutputDebugstring to ... (this change I don't know if it should be almost?

I wish you all a good job!

The following code is compiled with VC6 GCC.

// filename: Showruntime.h

#ifndef showtime_h

#define showtime_h

#include

#include

#include

Template

Class cshowruntimeSass

{

PUBLIC:

Unsigned int total_times;

Cshowruntimesass ()

{

Total_times = 0;

}

~ Cshowruntimesass ()

{

CHAR TMP [256];

Sprintf (TMP, "/ N% D:% U Times./N", I, TOTAL_TIMES);

PRINTF (TMP);

OutputDebugstring (TMP);

}

Static void addshowruntimes ()

{

Static cshowruntimesss tt;

TT.TOTAL_TIMES;

}

}

Template

Class cshowruntimeass

{

PUBLIC:

Unsigned int total_time;

Unsigned int total_times;

Cshowruntimeass ()

{

Total_time = Total_Times = 0;

}

~ Cshowruntimeass ()

{

CHAR TMP [256];

Sprintf (TMP, "/ N% D:% U TIMES,% 4.2F Seconds./N", I, TOTAL_TIMES, (Double) Total_Time / Clocks_Per_Sec);

PRINTF (TMP);

OutputDebugstring (TMP);

}

}

Template

Class cshowruntime

{

PUBLIC:

Cshowruntime ()

{

Showruntimebegin ();

}

~ Cshowruntime ()

{

ShowrunTimeEnd (0);

}

Static CShowRuntimeAss & gett ()

{

Static cshowruntimeass tt;

Return TT;

}

Static Bool ShowRuntimeBegin ()

{

//Gettt().total_time - = clock (); // more slowly

Gett (). Total_time - = gettickcount ();

Return True;

}

Template

Static T ShowruntimeEnd (t t) {

//Gettt().total_time = clock ();

Gett (). Total_time = gettickcount ();

Gett (). Total_Times;

Return T;

}

}

//

#define total_count (i) do {cshowruntimesss :: addshowruntimes ();} while (0)

#define Total_Time (i) cshowruntime _showruntime _ ## i

#define procedure_time (i, x) DO {cshowruntime _showruntime_; x;} while (0)

#define total_time_begin (i) cshowruntime :: ShowRuntimeBegin ()

#define Total_Time_END (i, x) cshowruntime :: ShowRuntimeEnd (x)

#define func_time (i, x) (total_time_egin (i) otal_time_end (i, x): total_time_end (i, x))

#define ref_func_time (i, x) (total_time_begin (i) * total_time_end (i, & (x)): * Total_time_end (i, & (x))))

#ndif // #ifndef showtime_h

// filename: main.cpp

#include

#include "showruntime.h"

Using namespace std;

Class ctest1

{

PUBLIC:

CTEST1 (Const Ctest1 & RHS) {cout << "CTEST1 () COPY / N";

CTEST1 () {cout << "ctest1 () / n";}

~ ctest1 () {cout << "~ ctest1 () / n";

}

CTEST1 ftest1 ()

{

COUT << "ftest1 () / n";

Return ctest1 ();

}

Int testVal ()

{

Cout << "TestVal () / n";

Return 0;

}

INT & TESTREF ()

{

Static Int i;

COUT << "TestRef ()" << i << endl;

Return I;

}

Const Int & TestConstref ()

{

Static Int i;

Cout << "TestConstref () << i << Endl;

Return I;

}

Int MySleep (DWORD DWMILLISECONDS)

{

Sleep (dwmilliseconds);

Return 0;

}

int main ()

{

Total_time (0);

CTEST1 T;

int rt;

COUT << "Call ftest1 Direct / N";

FTEST1 ();

COUT << "/ call ftest1 direct / n"; cout << "call ftest1 indirect / n";

FUNC_TIME (1, ftest1 ());

Cout << "/ call ftest1 indIRECT / N";

Cout << Endl;

TestRef () = 1;

// TestConstRef () = 2;

// TestVal () = 3;

REF_FUNC_TIME (11, TestRef ()) = 4;

// REF_FUNC_TIME (11, TestConstref ()) = 5; // VC6 Error! SHOULD NOT BE OK. Assignment of Read-Only Location!

// reb_func_time (11, testval ()) = 6;

COUT << "Call Testref Direct / N";

Cout << "Result address is:" << (int) & testRef () << endl

Cout << "/ call testref Direct / n";

COUT << "Call testRef indirect / n";

Cout << "Result address is:" << (int) & ref_func_time (11, testRef ()) << ENDL;

Cout << "/ Call Address Indirect / N";

Cout << Endl;

Procedure_time (11, SLEEP (200));

For (char i = 0; i! = 5; i)

{

Total_count (2);

Total_time (3);

Rt = func_time (4, mysleep (200));

}

COUT << "Call ftest1 indirect overce again / n";

FUNC_TIME (1, ftest1 ());

Cout << "/ call ftest1 indirect overce again / n";

COUT << "Call ftest1 Indirect Once Again, And Use Another Counter / N";

FUNC_TIME (5, ftest1 ());

Cout << "/ call ftest1 Indirect Once Again, And Use ANother Counter / N";

// system ("pause");

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-3048.html

New Post(0)