• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package ohos.devtools.views.trace.metrics.strategy;
17 
18 import ohos.devtools.views.trace.metrics.MetricsDb;
19 import ohos.devtools.views.trace.metrics.MetricsSql;
20 import ohos.devtools.views.trace.metrics.bean.SysCallsTop;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 /**
26  * SysCalls Strategy
27  *
28  * @since 2021/5/19 16:39
29  */
30 public class SysCallsTopStrategy implements Strategy {
31     /**
32      * Query Sys Calls top10 Result
33      *
34      * @param sql sql
35      * @return string string
36      */
37     @Override
getQueryResult(MetricsSql sql)38     public String getQueryResult(MetricsSql sql) {
39         List<SysCallsTop> list = new ArrayList<>() {
40         };
41         MetricsDb.getInstance().query(sql, list);
42         return handleSysCallsInfo(list);
43     }
44 
handleSysCallsInfo(List<SysCallsTop> result)45     private String handleSysCallsInfo(List<SysCallsTop> result) {
46         StringBuilder builder = new StringBuilder();
47         builder.append("sys_calls_top10{").append(System.lineSeparator());
48         for (SysCallsTop item : result) {
49             builder.append("\tprocess_info {").append(System.lineSeparator());
50             builder.append("\t\tname:").append(item.getProcessName()).append(System.lineSeparator());
51             builder.append("\t\tpid:").append(item.getPid()).append(System.lineSeparator());
52             builder.append("\t\tthreads{").append(System.lineSeparator());
53             builder.append("\t\t\tname:").append(item.getThreadName()).append(System.lineSeparator());
54             builder.append("\t\t\ttid:").append(item.getTid()).append(System.lineSeparator());
55             builder.append("\t\t\tfunction{").append(System.lineSeparator());
56             builder.append("\t\t\t\tfunction_name:").append(item.getFunName()).append(System.lineSeparator());
57             builder.append("\t\t\t\tdurMax:").append(item.getMaxDur()).append(System.lineSeparator());
58             builder.append("\t\t\t\tdurMin:").append(item.getMinDur()).append(System.lineSeparator());
59             builder.append("\t\t\t\tdurAvg:").append(item.getAvgDur()).append(System.lineSeparator());
60             builder.append("\t\t\t}").append(System.lineSeparator());
61             builder.append("\t\t}").append(System.lineSeparator());
62             builder.append("\t}").append(System.lineSeparator());
63         }
64         builder.append("}").append(System.lineSeparator());
65         return builder.toString();
66     }
67 }
68