51 |
52 |
52 void |
53 void |
53 Bench::ReadDistribution (std::istream &input) |
54 Bench::ReadDistribution (std::istream &input) |
54 { |
55 { |
55 double data; |
56 double data; |
56 while (!input.eof ()) { |
57 while (!input.eof ()) |
57 if (input >> data) { |
58 { |
|
59 if (input >> data) |
|
60 { |
58 uint64_t ns = (uint64_t) (data * 1000000000); |
61 uint64_t ns = (uint64_t) (data * 1000000000); |
59 m_distribution.push_back (ns); |
62 m_distribution.push_back (ns); |
60 } else { |
63 } |
|
64 else |
|
65 { |
61 input.clear (); |
66 input.clear (); |
62 std::string line; |
67 std::string line; |
63 input >> line; |
68 input >> line; |
64 } |
69 } |
65 } |
70 } |
66 } |
71 } |
67 |
72 |
68 void |
73 void |
69 Bench::RunBench (void) |
74 Bench::RunBench (void) |
70 { |
75 { |
71 SystemWallClockMs time; |
76 SystemWallClockMs time; |
72 double init, simu; |
77 double init, simu; |
73 time.Start (); |
78 time.Start (); |
74 for (std::vector<uint64_t>::const_iterator i = m_distribution.begin (); |
79 for (std::vector<uint64_t>::const_iterator i = m_distribution.begin (); |
75 i != m_distribution.end (); i++) { |
80 i != m_distribution.end (); i++) |
|
81 { |
76 Simulator::Schedule (NanoSeconds (*i), &Bench::Cb, this); |
82 Simulator::Schedule (NanoSeconds (*i), &Bench::Cb, this); |
77 } |
83 } |
78 init = time.End (); |
84 init = time.End (); |
79 |
85 |
80 m_current = m_distribution.begin (); |
86 m_current = m_distribution.begin (); |
81 |
87 |
82 time.Start (); |
88 time.Start (); |
94 } |
100 } |
95 |
101 |
96 void |
102 void |
97 Bench::Cb (void) |
103 Bench::Cb (void) |
98 { |
104 { |
99 if (m_n > m_total) { |
105 if (m_n > m_total) |
|
106 { |
100 return; |
107 return; |
101 } |
108 } |
102 if (m_current == m_distribution.end ()) { |
109 if (m_current == m_distribution.end ()) |
|
110 { |
103 m_current = m_distribution.begin (); |
111 m_current = m_distribution.begin (); |
104 } |
112 } |
105 if (gDebug) { |
113 if (g_debug) |
|
114 { |
106 std::cerr << "event at " << Simulator::Now ().GetSeconds () << "s" << std::endl; |
115 std::cerr << "event at " << Simulator::Now ().GetSeconds () << "s" << std::endl; |
107 } |
116 } |
108 Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb, this); |
117 Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb, this); |
109 m_current++; |
118 m_current++; |
110 m_n++; |
119 m_n++; |
111 } |
120 } |
112 |
121 |
132 PrintHelp (); |
141 PrintHelp (); |
133 return 0; |
142 return 0; |
134 } |
143 } |
135 argc-=2; |
144 argc-=2; |
136 argv+= 2; |
145 argv+= 2; |
137 if (strcmp (filename, "-") == 0) { |
146 if (strcmp (filename, "-") == 0) |
|
147 { |
138 input = &std::cin; |
148 input = &std::cin; |
139 } else { |
149 } |
|
150 else |
|
151 { |
140 input = new std::ifstream (filename); |
152 input = new std::ifstream (filename); |
141 } |
153 } |
142 while (argc > 0) { |
154 while (argc > 0) |
143 if (strcmp ("--list", argv[0]) == 0) { |
155 { |
|
156 if (strcmp ("--list", argv[0]) == 0) |
|
157 { |
144 Simulator::SetLinkedList (); |
158 Simulator::SetLinkedList (); |
145 } else if (strcmp ("--heap", argv[0]) == 0) { |
159 } |
|
160 else if (strcmp ("--heap", argv[0]) == 0) |
|
161 { |
146 Simulator::SetBinaryHeap (); |
162 Simulator::SetBinaryHeap (); |
147 } else if (strcmp ("--map", argv[0]) == 0) { |
163 } |
|
164 else if (strcmp ("--map", argv[0]) == 0) |
|
165 { |
148 Simulator::SetStdMap (); |
166 Simulator::SetStdMap (); |
149 } else if (strcmp ("--debug", argv[0]) == 0) { |
167 } |
150 gDebug = true; |
168 else if (strcmp ("--debug", argv[0]) == 0) |
151 } else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) { |
169 { |
|
170 g_debug = true; |
|
171 } |
|
172 else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) |
|
173 { |
152 char const *filename = argv[0] + strlen ("--log="); |
174 char const *filename = argv[0] + strlen ("--log="); |
153 Simulator::EnableLogTo (filename); |
175 Simulator::EnableLogTo (filename); |
154 } |
176 } |
155 argc--; |
177 argc--; |
156 argv++; |
178 argv++; |
157 } |
179 } |
158 Bench *bench = new Bench (); |
180 Bench *bench = new Bench (); |
159 bench->ReadDistribution (*input); |
181 bench->ReadDistribution (*input); |