| 1 | /* $Id: PrfTstProcess-4.c,v 1.1 2003-05-01 14:00:32 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * Test program which checks how long it takes to execute another | 
|---|
| 4 | * user specified process. | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright (c) 2001-2003 knut st. osmundsen (bird@anduin.net) | 
|---|
| 7 | * | 
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 9 | * | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 | /** @design Process Startup and Termination cost. | 
|---|
| 13 | * | 
|---|
| 14 | * The purpose is to compare the cost of creating a child process on different | 
|---|
| 15 | * platforms; revealing which is the best ones... | 
|---|
| 16 | * | 
|---|
| 17 | * Later analysis on why will be done I hope... | 
|---|
| 18 | * | 
|---|
| 19 | * | 
|---|
| 20 | * @subsection Test Results | 
|---|
| 21 | * | 
|---|
| 22 | * | 
|---|
| 23 | * @subsection  Compilation OS/2 | 
|---|
| 24 | * Just as normal odin apps:<br> | 
|---|
| 25 | * wcl386 -d__OS2__=1 -bt=os2v2 /los2v2 -I%WATCOM\h\os2 PrfTstProcess-4.c | 
|---|
| 26 | * | 
|---|
| 27 | * @subsection  Complation NT | 
|---|
| 28 | * This works from OS/2 and NT: | 
|---|
| 29 | * wcl386 -d__WINNT__=1 -bt=nt /lnt -I%WATCOM\h\nt PrfTstProcess-4.c   kernel32.lib | 
|---|
| 30 | * | 
|---|
| 31 | * Optimized: | 
|---|
| 32 | *  Add -Otx | 
|---|
| 33 | * | 
|---|
| 34 | */ | 
|---|
| 35 |  | 
|---|
| 36 | #include "PrfTiming.h" | 
|---|
| 37 |  | 
|---|
| 38 | int main(int argc, char **argv) | 
|---|
| 39 | { | 
|---|
| 40 | long double rdCur; | 
|---|
| 41 | long double rdStart; | 
|---|
| 42 | long double rdEnd; | 
|---|
| 43 | unsigned    cChilds; | 
|---|
| 44 | int         pid; | 
|---|
| 45 | #ifdef __NOTPC__ | 
|---|
| 46 | int         status; | 
|---|
| 47 | #endif | 
|---|
| 48 |  | 
|---|
| 49 | if (    argc == 1 | 
|---|
| 50 | ||  argv[1][0] == '-' | 
|---|
| 51 | ||  argv[1][0] == '/') | 
|---|
| 52 | { | 
|---|
| 53 | printf("syntax: %s <executable> [args]\n" | 
|---|
| 54 | "\n" | 
|---|
| 55 | "The executable is started executed repeatedly for 20 seconds.\n", | 
|---|
| 56 | argv[0]); | 
|---|
| 57 | return 8; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | /* | 
|---|
| 61 | * Mainloop. | 
|---|
| 62 | */ | 
|---|
| 63 | cChilds = 0;                        /* child count */ | 
|---|
| 64 | rdEnd = getHz() * 20.0;             /* loop for 20 seconds */ | 
|---|
| 65 | rdStart = rdCur = gettime(); | 
|---|
| 66 | rdEnd += gettime(); | 
|---|
| 67 | while (rdEnd > rdCur) | 
|---|
| 68 | { | 
|---|
| 69 | #ifndef __NOTPC__ | 
|---|
| 70 | pid = spawnv(P_WAIT, argv[1], &argv[1]); /* pid == 0 on success */ | 
|---|
| 71 | #else | 
|---|
| 72 | pid = fork(); | 
|---|
| 73 | if (pid == 0) | 
|---|
| 74 | {/* child code */ | 
|---|
| 75 | execv(argv[1], &argv[1]); | 
|---|
| 76 | fprintf(stderr, "we should NEVER be here!!\n"); | 
|---|
| 77 | return 0; | 
|---|
| 78 | } | 
|---|
| 79 | #endif | 
|---|
| 80 |  | 
|---|
| 81 | if (pid < 0) | 
|---|
| 82 | { | 
|---|
| 83 | fprintf(stderr, "Failed to spawn child\n"); | 
|---|
| 84 | return 0; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | #ifdef __NOTPC__ | 
|---|
| 88 | if (pid > 0) | 
|---|
| 89 | pid = wait(&status); | 
|---|
| 90 | #endif | 
|---|
| 91 | cChilds++; | 
|---|
| 92 | rdCur = gettime(); | 
|---|
| 93 | } | 
|---|
| 94 | printf("Spawned %d childs in %Lf seconds\n", cChilds, (rdCur - rdStart) / getHz()); | 
|---|
| 95 | printSystemInfo(); | 
|---|
| 96 | return 0; | 
|---|
| 97 | } | 
|---|