1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/tiles/frame_viewer_instrumentation.h"
7 #include "components/viz/common/traced_value.h"
10 namespace frame_viewer_instrumentation {
14 constexpr const char kCategory[] =
15 "cc," TRACE_DISABLED_BY_DEFAULT("devtools.timeline");
16 const char kTileData[] = "tileData";
17 const char kLayerId[] = "layerId";
18 const char kTileId[] = "tileId";
19 const char kTileResolution[] = "tileResolution";
20 const char kSourceFrameNumber[] = "sourceFrameNumber";
22 const char kAnalyzeTask[] = "AnalyzeTask";
23 const char kRasterTask[] = "RasterTask";
25 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> TileDataAsValue(
27 TileResolution tile_resolution,
28 int source_frame_number,
30 std::unique_ptr<base::trace_event::TracedValue> res(
31 new base::trace_event::TracedValue());
32 viz::TracedValue::SetIDRef(tile_id, res.get(), kTileId);
33 res->SetString(kTileResolution, TileResolutionToString(tile_resolution));
34 res->SetInteger(kSourceFrameNumber, source_frame_number);
35 res->SetInteger(kLayerId, layer_id);
36 return std::move(res);
41 ScopedAnalyzeTask::ScopedAnalyzeTask(const void* tile_id,
42 TileResolution tile_resolution,
43 int source_frame_number,
46 kCategory, kAnalyzeTask, kTileData,
47 TileDataAsValue(tile_id, tile_resolution, source_frame_number, layer_id));
50 ScopedAnalyzeTask::~ScopedAnalyzeTask() {
51 TRACE_EVENT_END0(kCategory, kAnalyzeTask);
54 ScopedRasterTask::ScopedRasterTask(const void* tile_id,
55 TileResolution tile_resolution,
56 int source_frame_number,
59 kCategory, kRasterTask, kTileData,
60 TileDataAsValue(tile_id, tile_resolution, source_frame_number, layer_id));
63 ScopedRasterTask::~ScopedRasterTask() {
64 TRACE_EVENT_END0(kCategory, kRasterTask);
67 bool IsTracingLayerTreeSnapshots() {
68 bool category_enabled;
69 TRACE_EVENT_CATEGORY_GROUP_ENABLED(CategoryLayerTree(), &category_enabled);
70 return category_enabled;
73 } // namespace frame_viewer_instrumentation