1 | #include <Application.h>
|
---|
2 | #include <MessageRunner.h>
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <OS.h>
|
---|
6 |
|
---|
7 | #include <private/shared/AutoDeleter.h>
|
---|
8 |
|
---|
9 | enum {
|
---|
10 | second = 1000000,
|
---|
11 | };
|
---|
12 |
|
---|
13 | enum {
|
---|
14 | timerMsg = 1,
|
---|
15 | };
|
---|
16 |
|
---|
17 | enum {
|
---|
18 | maxDelay = second/10,
|
---|
19 | minDelay = 1,
|
---|
20 | stepCnt = 5000,
|
---|
21 | };
|
---|
22 |
|
---|
23 | class TestApplication: public BApplication
|
---|
24 | {
|
---|
25 | private:
|
---|
26 | bigtime_t fScheduledTime;
|
---|
27 |
|
---|
28 | int32 fCurStep;
|
---|
29 | bigtime_t fDelays[stepCnt];
|
---|
30 | bigtime_t fStat[stepCnt];
|
---|
31 |
|
---|
32 | public:
|
---|
33 | TestApplication(): BApplication("application/x-vnd.test-app"),
|
---|
34 | fCurStep(0)
|
---|
35 | {
|
---|
36 | for (int32 i = 0; i < stepCnt; i++) {
|
---|
37 | fDelays[i] = minDelay + (maxDelay - minDelay)*i/(stepCnt - 1);
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | void ReadyToRun()
|
---|
42 | {
|
---|
43 | while (fCurStep < stepCnt) {
|
---|
44 | {
|
---|
45 | bigtime_t now = system_time();
|
---|
46 | fScheduledTime = now + fDelays[fCurStep];
|
---|
47 | snooze_until(fScheduledTime, B_SYSTEM_TIMEBASE);
|
---|
48 | }
|
---|
49 | {
|
---|
50 | bigtime_t now = system_time();
|
---|
51 | fStat[fCurStep] = now - fScheduledTime;
|
---|
52 | }
|
---|
53 | fCurStep++;
|
---|
54 | }
|
---|
55 | for (int32 i = 0; i < stepCnt; i++) {
|
---|
56 | printf("%.06E %.06E\n", double(fDelays[i])/second, double(fStat[i])/second);
|
---|
57 | }
|
---|
58 | PostMessage(B_QUIT_REQUESTED);
|
---|
59 | }
|
---|
60 |
|
---|
61 | };
|
---|
62 |
|
---|
63 |
|
---|
64 | int main()
|
---|
65 | {
|
---|
66 | TestApplication app;
|
---|
67 | app.Run();
|
---|
68 | return 0;
|
---|
69 | }
|
---|