Fix Buffer trace events

1. Use object pointer as unique ID to properly match begin/end event
   pairs.
2. Remove trace event from error constructor since it has no end event.
3. Switch to non-deprecated nestable trace events.

Fixed: 417426560
Change-Id: Iec57e62c234077834493adf29ef36efa29c2a2ff
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/241994
Commit-Queue: Kyle Charbonneau <kylechar@google.com>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp
index 946e5a8..40dda63 100644
--- a/src/dawn/native/Buffer.cpp
+++ b/src/dawn/native/Buffer.cpp
@@ -202,8 +202,11 @@
           mCallback(callbackInfo.callback),
           mUserdata1(callbackInfo.userdata1),
           mUserdata2(callbackInfo.userdata2) {
-        TRACE_EVENT_ASYNC_BEGIN0(device->GetPlatform(), General, "Buffer::APIMapAsync",
-                                 uint64_t(serial));
+        // `this` is used as a unique ID to match begin/end events for concurrent MapAsync calls.
+        // It's not a problem that same memory address could be reused for a future MapAsync call
+        // since it won't be concurrent with an earlier call.
+        TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(device->GetPlatform(), General, "Buffer::APIMapAsync",
+                                          this);
     }
 
     // Create an event that's ready at creation (for errors, etc.)
@@ -216,19 +219,15 @@
           mBufferOrError(BufferErrorData{status, message}),
           mCallback(callbackInfo.callback),
           mUserdata1(callbackInfo.userdata1),
-          mUserdata2(callbackInfo.userdata2) {
-        TRACE_EVENT_ASYNC_BEGIN0(device->GetPlatform(), General, "Buffer::APIMapAsync",
-                                 uint64_t(kBeginningOfGPUTime));
-    }
+          mUserdata2(callbackInfo.userdata2) {}
 
     ~MapAsyncEvent() override { EnsureComplete(EventCompletionType::Shutdown); }
 
     void Complete(EventCompletionType completionType) override {
         if (const auto* queueAndSerial = GetIfQueueAndSerial()) {
             if (auto queue = queueAndSerial->queue.Promote()) {
-                TRACE_EVENT_ASYNC_END0(queue->GetDevice()->GetPlatform(), General,
-                                       "Buffer::APIMapAsync",
-                                       uint64_t(queueAndSerial->completionSerial));
+                TRACE_EVENT_NESTABLE_ASYNC_END0(queue->GetDevice()->GetPlatform(), General,
+                                                "Buffer::APIMapAsync", this);
             }
         }