• 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.datasources.utils.common.util;
17 
18 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager;
19 import ohos.devtools.views.common.LayoutConstants;
20 import org.apache.logging.log4j.LogManager;
21 import org.apache.logging.log4j.Logger;
22 
23 /**
24  * Extract saves for individual function tool methods.
25  *
26  * @since 2021/5/19 16:39
27  */
28 public class CommonUtil {
29     private static final Logger LOGGER = LogManager.getLogger(CommonUtil.class);
30 
31     private static volatile Integer requestId = 1;
32 
CommonUtil()33     private CommonUtil() {
34     }
35 
36     /**
37      * Sets the intial collection size.
38      *
39      * @param size size
40      * @return Returns the initial collection size.
41      */
collectionSize(int size)42     public static int collectionSize(int size) {
43         if (ProfilerLogManager.isInfoEnabled()) {
44             LOGGER.info("collectionSize");
45         }
46         return (size <= 0) ? LayoutConstants.SIXTEEN : (int) (size / LayoutConstants.LOAD_FACTOR + 1.0F);
47     }
48 
49     /**
50      * Gets the request ID.
51      *
52      * @return Returns the initial collection size.
53      */
getRequestId()54     public static int getRequestId() {
55         if (ProfilerLogManager.isInfoEnabled()) {
56             LOGGER.info("getRequestId");
57         }
58         if (requestId == Integer.MAX_VALUE) {
59             requestId = 1;
60         }
61         return requestId++;
62     }
63 
64     /**
65      * Generates a session name.
66      *
67      * @param deviceName Indicates the device name.
68      * @param pid Indicates the process ID.
69      * @return String
70      */
generateSessionName(String deviceName, int pid)71     public static String generateSessionName(String deviceName, int pid) {
72         if (ProfilerLogManager.isInfoEnabled()) {
73             LOGGER.info("generateSessionName");
74         }
75         return deviceName + pid;
76     }
77 
78     /**
79      * Gets the ID of a local session.
80      *
81      * @return Long
82      */
getLocalSessionId()83     public static Long getLocalSessionId() {
84         if (ProfilerLogManager.isInfoEnabled()) {
85             LOGGER.info("getLocalSessionId");
86         }
87         return System.currentTimeMillis();
88     }
89 }
90