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.SysCalls; 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 SysCallsStrategy implements Strategy { 31 /** 32 * Query SysCalls Result 33 * 34 * @param sql sql 35 * @return string string 36 */ 37 @Override getQueryResult(MetricsSql sql)38 public String getQueryResult(MetricsSql sql) { 39 List<SysCalls> list = new ArrayList<>() { 40 }; 41 MetricsDb.getInstance().query(sql, list); 42 return handleSysCallsInfo(list); 43 } 44 handleSysCallsInfo(List<SysCalls> result)45 private String handleSysCallsInfo(List<SysCalls> result) { 46 StringBuilder builder = new StringBuilder(); 47 builder.append("sys_calls{").append(System.lineSeparator()); 48 for (SysCalls item : result) { 49 builder.append("\tfunction{").append(System.lineSeparator()); 50 builder.append("\t\tfunction_name:").append(item.getFunName()).append(System.lineSeparator()); 51 builder.append("\t\tdurMax:").append(item.getMaxDur()).append(System.lineSeparator()); 52 builder.append("\t\tdurMin:").append(item.getMinDur()).append(System.lineSeparator()); 53 builder.append("\t\tdurAvg:").append(item.getAvgDur()).append(System.lineSeparator()); 54 builder.append("\t}").append(System.lineSeparator()); 55 } 56 builder.append("}").append(System.lineSeparator()); 57 return builder.toString(); 58 } 59 } 60