| 541 | } |
| 542 | |
| 543 | TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, |
| 544 | int threadId, |
| 545 | uint64_t profilingGuid, |
| 546 | unsigned char* buffer, |
| 547 | unsigned int remainingBufferSize, |
| 548 | unsigned int& numberOfBytesWritten) |
| 549 | { |
| 550 | // Initialize the output value |
| 551 | numberOfBytesWritten = 0; |
| 552 | // Check that the given buffer is valid |
| 553 | if (buffer == nullptr || remainingBufferSize == 0) |
| 554 | { |
| 555 | return TimelinePacketStatus::BufferExhaustion; |
| 556 | } |
| 557 | |
| 558 | // Utils |
| 559 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 560 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 561 | |
| 562 | // decl_id of the timeline message |
| 563 | uint32_t declId = 4; |
| 564 | |
| 565 | // Calculate the length of the data (in bytes) |
| 566 | unsigned int timelineEventDataLength = uint32_t_size + // decl_id |
| 567 | uint64_t_size + // Timestamp |
| 568 | ThreadIdSize + // Thread id |
| 569 | uint64_t_size; // Profiling GUID |
| 570 | |
| 571 | // Check whether the timeline binary packet fits in the given buffer |
| 572 | if (timelineEventDataLength > remainingBufferSize) |
| 573 | { |
| 574 | return TimelinePacketStatus::BufferExhaustion; |
| 575 | } |
| 576 | |
| 577 | // Initialize the offset for writing in the buffer |
| 578 | unsigned int offset = 0; |
| 579 | |
| 580 | // Write the timeline binary payload to the buffer |
| 581 | WriteUint32(buffer, offset, declId); // decl_id |
| 582 | offset += uint32_t_size; |
| 583 | WriteUint64(buffer, offset, timestamp); // Timestamp |
| 584 | offset += uint64_t_size; |
| 585 | WriteBytes(buffer, offset, &threadId, ThreadIdSize); // Thread id |
| 586 | offset += ThreadIdSize; |
| 587 | WriteUint64(buffer, offset, profilingGuid); // Profiling GUID |
| 588 | offset += uint64_t_size; |
| 589 | // Update the number of bytes written |
| 590 | numberOfBytesWritten = timelineEventDataLength; |
| 591 | |
| 592 | return TimelinePacketStatus::Ok; |
| 593 | } |
| 594 | |
| 595 | uint64_t GetTimestamp() |
| 596 | { |
no test coverage detected