Adds an event to the buffer with begin timestamp set to the current timestamp. Returns a handle to event that can be used to call EndEvent. If buffer is disabled this has no affect. The tag of the event should remain valid till the buffer is valid.
| 60 | // buffer is disabled this has no affect. |
| 61 | // The tag of the event should remain valid till the buffer is valid. |
| 62 | uint32_t BeginEvent(const char* tag, ProfileEvent::EventType event_type, |
| 63 | uint32_t event_metadata) { |
| 64 | if (!enabled_) { |
| 65 | return kInvalidEventHandle; |
| 66 | } |
| 67 | uint64_t timestamp = time::NowMicros(); |
| 68 | int index = current_index_ % event_buffer_.size(); |
| 69 | if (current_index_ != 0 && index == 0) { |
| 70 | fprintf(stderr, "Warning: ProfileBuffer wrapping.\n"); |
| 71 | } |
| 72 | event_buffer_[index].tag = tag; |
| 73 | event_buffer_[index].event_type = event_type; |
| 74 | event_buffer_[index].event_metadata = event_metadata; |
| 75 | event_buffer_[index].begin_timestamp_us = timestamp; |
| 76 | event_buffer_[index].end_timestamp_us = 0; |
| 77 | current_index_++; |
| 78 | return index; |
| 79 | } |
| 80 | |
| 81 | // Sets the enabled state of buffer to |enabled| |
| 82 | void SetEnabled(bool enabled) { enabled_ = enabled; } |