1 // Copyright 2013 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.
5 #include "content/common/gpu/devtools_gpu_agent.h"
7 #include "base/logging.h"
8 #include "content/common/devtools_messages.h"
9 #include "content/common/gpu/gpu_channel.h"
10 #include "content/common/gpu/gpu_channel_manager.h"
14 DevToolsGpuAgent::DevToolsGpuAgent(GpuChannel
* gpu_channel
) :
15 gpu_channel_(gpu_channel
),
16 route_id_(MSG_ROUTING_NONE
) {
19 DevToolsGpuAgent::~DevToolsGpuAgent() {
22 bool DevToolsGpuAgent::StartEventsRecording(int32 route_id
) {
23 DCHECK(CalledOnValidThread());
24 if (route_id_
!= MSG_ROUTING_NONE
) {
25 // Events recording is already in progress, so "fail" the call by
30 tasks_
.reset(new GpuTaskInfoList());
31 GpuEventsDispatcher
* dispatcher
=
32 gpu_channel_
->gpu_channel_manager()->gpu_devtools_events_dispatcher();
33 dispatcher
->AddProcessor(this);
37 void DevToolsGpuAgent::StopEventsRecording() {
38 DCHECK(CalledOnValidThread());
39 if (route_id_
== MSG_ROUTING_NONE
)
41 GpuEventsDispatcher
* dispatcher
=
42 gpu_channel_
->gpu_channel_manager()->gpu_devtools_events_dispatcher();
43 dispatcher
->RemoveProcessor(this);
44 route_id_
= MSG_ROUTING_NONE
;
47 void DevToolsGpuAgent::ProcessEvent(
49 GpuEventsDispatcher::EventPhase phase
,
50 GpuChannel
* channel
) {
51 DCHECK(CalledOnValidThread());
52 if (route_id_
== MSG_ROUTING_NONE
)
56 task
.timestamp
= (timestamp
- TimeTicks()).InSecondsF();
58 task
.foreign
= channel
!= gpu_channel_
;
59 task
.gpu_memory_used_bytes
= channel
->GetMemoryUsage();
60 task
.gpu_memory_limit_bytes
= gpu_channel_
->gpu_channel_manager()->
61 gpu_memory_manager()->GetMaximumClientAllocation();
63 const int kFlushIntervalMs
= 100;
64 const unsigned kMaxPendingItems
= 100;
65 if (!tasks_
->empty() &&
66 ((timestamp
- last_flush_time_
).InMilliseconds() >= kFlushIntervalMs
||
67 tasks_
->size() >= kMaxPendingItems
)) {
68 Send(new DevToolsAgentMsg_GpuTasksChunk(route_id_
, *tasks_
));
70 last_flush_time_
= timestamp
;
72 tasks_
->push_back(task
);
75 bool DevToolsGpuAgent::Send(IPC::Message
* msg
) {
76 scoped_ptr
<IPC::Message
> message(msg
);
77 return gpu_channel_
&& gpu_channel_
->Send(message
.release());
80 } // namespace content