File: main.cxx

package info (click to toggle)
ptlib 2.10.4~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 58,836 kB
  • sloc: cpp: 135,080; ansic: 8,534; yacc: 3,059; sh: 2,776; makefile: 1,082; lex: 390
file content (164 lines) | stat: -rw-r--r-- 4,066 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * main.cxx
 *
 * PTLib application source file for testing speed of PSyncPoint class.
 *
 * Main program entry point.
 *
 * Copyright 2009 Derek J Smithies
 *
 * $Revision: 23419 $
 * 
 *  You can read the comments to this program in the file main.h
 *
 *  In linux, you can get nice html docs by doing "make docs"
 *
 */

#include <ptlib.h>

using namespace std;

#include "main.h"


PCREATE_PROCESS(SyncPoints);

SyncPoints::SyncPoints()
  : PProcess("Derek Smithies code factory", "SyncPoints", 1, 0, AlphaCode, 1)
{
}

SyncPoints::~SyncPoints()
{
}

void SyncPoints::ListFinished()
{
  ++syncPointsSignalled;
  allDone.Signal(); 
}

void SyncPoints::Main()
{
  PArgList & args = GetArguments();
  args.Parse("l-loops:     "
	     "s-size:    "
	     "h-help.    "
#if PTRACING
             "o-output:"             "-no-output."
             "t-trace."              "-no-trace."
#endif
	     "v-version.    "
	     );

  if (args.HasOption('h')) {
    cout << "usage: map_dict "
         << endl
         << "     -l --loops #   : count of loops to run over the map/dicts  (1000)" << endl
	 << "     -s --size  #   : number of elements to pu in map/dict (200) " << endl
	 << "     -h --help      : Get this help message" << endl
	 << "     -v --version  : Get version information " << endl
#if PTRACING
         << "  -t --trace   : Enable trace, use multiple times for more detail" << endl
         << "  -o --output  : File for trace output, default is stderr" << endl
#endif
         << endl;
    return;
  }


  PTrace::Initialise(args.GetOptionCount('t'),
                     args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
         PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);

  if (args.HasOption('v')) {
    cout << endl
         << "Product Name: " <<  (const char *)GetName() << endl
         << "Manufacturer: " <<  (const char *)GetManufacturer() << endl
         << "Version     : " <<  (const char *)GetVersion(PTrue) << endl
         << "System      : " <<  (const char *)GetOSName() << '-'
         <<  (const char *)GetOSHardware() << ' '
         <<  (const char *)GetOSVersion() << endl
         << endl;
    return;
  }

  loops = 1000;
  size  = 200;

  if (args.HasOption('l')) {
    PINDEX t = args.GetOptionString('l').AsInteger();
    if (t != 0) {
      cerr << " running " << t << " loops over the list of syncPoints " << endl;
      loops = t;
    }
  }

  if (args.HasOption('s')) {
    PINDEX t = args.GetOptionString('s').AsInteger();
    if (t != 0) {
      cerr << " running " << t << " Sync Point tests in a row " << endl;
      size = t;
    }
  }

  Runner *lastRunner = NULL;
  for (PINDEX i = 0; i < size; i++) {
    Runner * thisRunner = new Runner(*this, lastRunner, i);
    
    list.push_back(thisRunner);
    lastRunner = thisRunner;    
  }

  PTime a;
  for(PINDEX i = 0; i < loops; i++) {
    lastRunner->RunNow();
    allDone.Wait();
  }
  PTime b;
  PInt64 c = b.GetTimestamp() - a.GetTimestamp();
  PTimeInterval g = b-a;

  cerr << "Number of SyncPoint operations is " << syncPointsSignalled << endl << endl;

  cerr << "Elapsed time for " 
       << size << " elements, done "
       << loops << "x  is " 
       << c << " micseconds" << endl << endl;

  cerr << "Elapsed wall time for the test is " << g << " seconds" << endl << endl;

  cerr << "Time per syncpoint is " 
       << (c/(syncPointsSignalled * 1.00)) << " microseconds" << endl;
}

/////////////////////////////////////////////////////////////////////////////
Runner::Runner(SyncPoints & _app, Runner * _nextThread, PINDEX _id)
  :PThread(1000, NoAutoDeleteThread),
   app(_app),
   nextThread(_nextThread),
   id(_id)
{
  Resume();
}

void Runner::Main()
{
  for (;;) {
    syncPoint.Wait();

    //    cerr << id << endl;
    if (nextThread == NULL) 
      app.ListFinished();
    else
      nextThread->RunNow();
  }
}   

void Runner::RunNow() 
{ 
  syncPoint.Signal();   
  ++app.syncPointsSignalled; 
}
// End of File ///////////////////////////////////////////////////////////////