1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gpu/command_buffer/service/dawn_platform.h"
6
7 #include "base/trace_event/trace_arguments.h"
8 #include "base/trace_event/trace_event.h"
9
10 namespace gpu {
11 namespace webgpu {
12
13 DawnPlatform::DawnPlatform() = default;
14
15 DawnPlatform::~DawnPlatform() = default;
16
GetTraceCategoryEnabledFlag(dawn_platform::TraceCategory category)17 const unsigned char* DawnPlatform::GetTraceCategoryEnabledFlag(
18 dawn_platform::TraceCategory category) {
19 // For now, all Dawn trace categories are put under "gpu.dawn"
20 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
21 TRACE_DISABLED_BY_DEFAULT("gpu.dawn"));
22 }
23
MonotonicallyIncreasingTime()24 double DawnPlatform::MonotonicallyIncreasingTime() {
25 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
26 }
27
AddTraceEvent(char phase,const unsigned char * category_group_enabled,const char * name,uint64_t id,double timestamp,int num_args,const char ** arg_names,const unsigned char * arg_types,const uint64_t * arg_values,unsigned char flags)28 uint64_t DawnPlatform::AddTraceEvent(
29 char phase,
30 const unsigned char* category_group_enabled,
31 const char* name,
32 uint64_t id,
33 double timestamp,
34 int num_args,
35 const char** arg_names,
36 const unsigned char* arg_types,
37 const uint64_t* arg_values,
38 unsigned char flags) {
39 base::TimeTicks timestamp_tt =
40 base::TimeTicks() + base::TimeDelta::FromSecondsD(timestamp);
41
42 base::trace_event::TraceArguments args(
43 num_args, arg_names, arg_types,
44 reinterpret_cast<const unsigned long long*>(arg_values));
45
46 base::trace_event::TraceEventHandle handle =
47 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
48 phase, category_group_enabled, name,
49 trace_event_internal::kGlobalScope, id, trace_event_internal::kNoId,
50 base::PlatformThread::CurrentId(), timestamp_tt, &args, flags);
51
52 uint64_t result = 0;
53 static_assert(sizeof(base::trace_event::TraceEventHandle) <= sizeof(result),
54 "TraceEventHandle must be at most the size of uint64_t");
55 static_assert(std::is_pod<base::trace_event::TraceEventHandle>(),
56 "TraceEventHandle must be memcpy'able");
57 memcpy(&result, &handle, sizeof(base::trace_event::TraceEventHandle));
58 return result;
59 }
60
61 } // namespace webgpu
62 } // namespace gpu
63