| | 224 | class PollTraceEntry : public AbstractTraceEntry { |
|---|
| | 225 | protected: |
|---|
| | 226 | PollTraceEntry(pollfd* fds, int count, bool resultEvents) |
|---|
| | 227 | : |
|---|
| | 228 | fEntries(NULL), |
|---|
| | 229 | fCount(0) |
|---|
| | 230 | { |
|---|
| | 231 | if (fds != NULL && count > 0) { |
|---|
| | 232 | for (int i = 0; i < count; i++) { |
|---|
| | 233 | if (resultEvents ? fds[i].revents : fds[i].events) |
|---|
| | 234 | fCount++; |
|---|
| | 235 | } |
|---|
| | 236 | } |
|---|
| | 237 | |
|---|
| | 238 | if (fCount == 0) |
|---|
| | 239 | return; |
|---|
| | 240 | |
|---|
| | 241 | fEntries = (FDEntry*)alloc_tracing_buffer(fCount * sizeof(FDEntry)); |
|---|
| | 242 | if (fEntries != NULL) { |
|---|
| | 243 | for (int i = 0; i < fCount; fds++) { |
|---|
| | 244 | uint16 events = resultEvents ? fds->revents : fds->events; |
|---|
| | 245 | if (events != 0) { |
|---|
| | 246 | fEntries[i].fd = fds->fd; |
|---|
| | 247 | fEntries[i].events = events; |
|---|
| | 248 | i++; |
|---|
| | 249 | } |
|---|
| | 250 | } |
|---|
| | 251 | } |
|---|
| | 252 | } |
|---|
| | 253 | |
|---|
| | 254 | void AddDump(TraceOutput& out) |
|---|
| | 255 | { |
|---|
| | 256 | if (fEntries == NULL) |
|---|
| | 257 | return; |
|---|
| | 258 | |
|---|
| | 259 | static const struct { |
|---|
| | 260 | const char* name; |
|---|
| | 261 | uint16 event; |
|---|
| | 262 | } kEventNames[] = { |
|---|
| | 263 | { "r", POLLIN }, |
|---|
| | 264 | { "w", POLLOUT }, |
|---|
| | 265 | { "rb", POLLRDBAND }, |
|---|
| | 266 | { "wb", POLLWRBAND }, |
|---|
| | 267 | { "rp", POLLPRI }, |
|---|
| | 268 | { "err", POLLERR }, |
|---|
| | 269 | { "hup", POLLHUP }, |
|---|
| | 270 | { "inv", POLLNVAL }, |
|---|
| | 271 | { NULL, 0 } |
|---|
| | 272 | }; |
|---|
| | 273 | |
|---|
| | 274 | bool firstFD = true; |
|---|
| | 275 | for (int i = 0; i < fCount; i++) { |
|---|
| | 276 | if (firstFD) { |
|---|
| | 277 | out.Print("<%u: ", fEntries[i].fd); |
|---|
| | 278 | firstFD = false; |
|---|
| | 279 | } else |
|---|
| | 280 | out.Print(", <%u: ", fEntries[i].fd); |
|---|
| | 281 | |
|---|
| | 282 | bool firstEvent = true; |
|---|
| | 283 | for (int k = 0; kEventNames[k].name != NULL; k++) { |
|---|
| | 284 | if ((fEntries[i].events & kEventNames[k].event) != 0) { |
|---|
| | 285 | if (firstEvent) { |
|---|
| | 286 | out.Print("%s", kEventNames[k].name); |
|---|
| | 287 | firstEvent = false; |
|---|
| | 288 | } else |
|---|
| | 289 | out.Print(", %s", kEventNames[k].name); |
|---|
| | 290 | } |
|---|
| | 291 | } |
|---|
| | 292 | |
|---|
| | 293 | out.Print(">"); |
|---|
| | 294 | } |
|---|
| | 295 | } |
|---|
| | 296 | |
|---|
| | 297 | protected: |
|---|
| | 298 | struct FDEntry { |
|---|
| | 299 | uint16 fd; |
|---|
| | 300 | uint16 events; |
|---|
| | 301 | }; |
|---|
| | 302 | |
|---|
| | 303 | FDEntry* fEntries; |
|---|
| | 304 | int fCount; |
|---|
| | 305 | }; |
|---|
| | 306 | |
|---|
| | 307 | |
|---|
| | 308 | class PollBegin : public PollTraceEntry { |
|---|
| | 309 | public: |
|---|
| | 310 | PollBegin(pollfd* fds, int count, bigtime_t timeout) |
|---|
| | 311 | : |
|---|
| | 312 | PollTraceEntry(fds, count, false), |
|---|
| | 313 | fTimeout(timeout) |
|---|
| | 314 | { |
|---|
| | 315 | Initialized(); |
|---|
| | 316 | } |
|---|
| | 317 | |
|---|
| | 318 | virtual void AddDump(TraceOutput& out) |
|---|
| | 319 | { |
|---|
| | 320 | out.Print("poll begin: "); |
|---|
| | 321 | PollTraceEntry::AddDump(out); |
|---|
| | 322 | out.Print(", timeout: %lld", fTimeout); |
|---|
| | 323 | } |
|---|
| | 324 | |
|---|
| | 325 | private: |
|---|
| | 326 | bigtime_t fTimeout; |
|---|
| | 327 | }; |
|---|
| | 328 | |
|---|
| | 329 | |
|---|
| | 330 | class PollDone : public PollTraceEntry { |
|---|
| | 331 | public: |
|---|
| | 332 | PollDone(pollfd* fds, int count, int result) |
|---|
| | 333 | : |
|---|
| | 334 | PollTraceEntry(fds, result >= 0 ? count : 0, true), |
|---|
| | 335 | fResult(result) |
|---|
| | 336 | { |
|---|
| | 337 | Initialized(); |
|---|
| | 338 | } |
|---|
| | 339 | |
|---|
| | 340 | virtual void AddDump(TraceOutput& out) |
|---|
| | 341 | { |
|---|
| | 342 | if (fResult >= 0) { |
|---|
| | 343 | out.Print("poll done: count: %d: ", fResult); |
|---|
| | 344 | PollTraceEntry::AddDump(out); |
|---|
| | 345 | } else |
|---|
| | 346 | out.Print("poll done: error: 0x%x", fResult); |
|---|
| | 347 | } |
|---|
| | 348 | |
|---|
| | 349 | private: |
|---|
| | 350 | int fResult; |
|---|
| | 351 | }; |
|---|
| | 352 | |
|---|