• 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.MetricsSql;
19 
20 import java.util.HashMap;
21 import java.util.Map;
22 
23 /**
24  * MetadataStrategy
25  *
26  * @since 2021/5/19 16:39
27  */
28 public class MetricsFactory {
29     private static final MetricsFactory FACTORY = new MetricsFactory();
30 
31     private final Map<MetricsSql, Strategy> strategyMap = new HashMap<>();
32 
MetricsFactory()33     private MetricsFactory() {
34         strategyMap.put(MetricsSql.TRACE_METADATA, new MetadataStrategy());
35         strategyMap.put(MetricsSql.TRACE_CPU, new CpuStrategy());
36         strategyMap.put(MetricsSql.TRACE_CPU_TOP10, new CpuStrategy());
37         strategyMap.put(MetricsSql.TRACE_TASK_NAMES, new TraceTaskStrategy());
38         strategyMap.put(MetricsSql.TRACE_STATS, new TraceStatsStrategy());
39         strategyMap.put(MetricsSql.TRACE_MEM, new MemStrategy());
40         strategyMap.put(MetricsSql.TRACE_MEM_TOP10, new MemStrategy());
41         strategyMap.put(MetricsSql.TRACE_MEM_UNAGG, new MemAggStrategy());
42         strategyMap.put(MetricsSql.DISTRIBUTED_TERM, new DistributeTermStrategy());
43         strategyMap.put(MetricsSql.SYS_CALLS_TOP10, new SysCallsTopStrategy());
44         strategyMap.put(MetricsSql.SYS_CALLS, new SysCallsStrategy());
45     }
46 
47     /**
48      * Get singleton
49      *
50      * @return MetricsFactory MetricsFactory
51      */
getInstance()52     public static MetricsFactory getInstance() {
53         return FACTORY;
54     }
55 
56     /**
57      * Get Strategy
58      *
59      * @param sql sql
60      * @return Strategy Strategy
61      */
getStrategy(MetricsSql sql)62     public Strategy getStrategy(MetricsSql sql) {
63         return strategyMap.get(sql);
64     }
65 }
66