1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "src/trace_processor/analysis/describe_slice.h"
18 
19 namespace perfetto {
20 namespace trace_processor {
21 
DescribeSlice(const tables::SliceTable & table,tables::SliceTable::Id id,base::Optional<SliceDescription> * description)22 util::Status DescribeSlice(const tables::SliceTable& table,
23                            tables::SliceTable::Id id,
24                            base::Optional<SliceDescription>* description) {
25   auto opt_row = table.id().IndexOf(id);
26   if (!opt_row)
27     return util::ErrStatus("Unable to find slice id");
28 
29   uint32_t row = *opt_row;
30 
31   base::StringView name = table.name().GetString(row);
32   if (name == "inflate") {
33     *description = SliceDescription{
34         "Constructing a View hierarchy from pre-processed XML via "
35         "LayoutInflater#layout. This includes constructing all of the View "
36         "objects in the hierarchy, and applying styled attributes.",
37         ""};
38     return util::OkStatus();
39   }
40 
41   if (name == "measure") {
42     *description = SliceDescription{
43         "First of two phases in view hierarchy layout. Views are asked to size "
44         "themselves according to constraints supplied by their parent. Some "
45         "ViewGroups may measure a child more than once to help satisfy their "
46         "own constraints. Nesting ViewGroups that measure children more than "
47         "once can lead to excessive and repeated work.",
48         "https://developer.android.com/reference/android/view/"
49         "View.html#Layout"};
50     return util::OkStatus();
51   }
52 
53   *description = base::nullopt;
54   return util::OkStatus();
55 }
56 
57 }  // namespace trace_processor
58 }  // namespace perfetto
59