• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef OS_ACCOUNT_FRAMEWORKS_COMMON_PERF_STAT_INCLUDE_PERF_STAT_H
17 #define OS_ACCOUNT_FRAMEWORKS_COMMON_PERF_STAT_INCLUDE_PERF_STAT_H
18 
19 #include <cstdint>
20 #include <map>
21 #include "singleton.h"
22 
23 namespace OHOS {
24 namespace AccountSA {
25 class PerfStat : public Singleton<PerfStat> {
26     DECLARE_SINGLETON(PerfStat);
27 
28 public:
29     int64_t GetAccountBindStartTime() const;
30     void SetAccountBindStartTime(int64_t time);
31 
32     int64_t GetAccountBindEndTime() const;
33     void SetAccountBindEndTime(int64_t time);
34 
35     int64_t GetAccountAddStartTime() const;
36     void SetAccountAddStartTime(int64_t time);
37 
38     int64_t GetAccountAddEndTime() const;
39     void SetAccountAddEndTime(int64_t time);
40 
41     int64_t GetAccountDelStartTime() const;
42     void SetAccountDelStartTime(int64_t time);
43 
44     int64_t GetAccountDelEndTime() const;
45     void SetAccountDelEndTime(int64_t time);
46 
47     int64_t GetAccountQueryStartTime() const;
48     void SetAccountQueryStartTime(int64_t time);
49 
50     int64_t GetAccountQueryEndTime() const;
51     void SetAccountQueryEndTime(int64_t time);
52 
53     void SetInstanceStopTime(int64_t);
54     void SetInstanceStartTime(int64_t);
55     void SetInstanceInitTime(int64_t);
56     void SetInstanceCreateTime(int64_t);
57     void SetAccountStateChangeTime(const std::string &stateStr, int64_t time);
58 
59     bool GetPerfStatEnabled() const;
60     void SetPerfStatEnabled(bool enable);
61 
62     void Reset();
63     void Dump(std::string& result) const;
64 
65 private:
66     int64_t accountBindBegin_ = 0;
67     int64_t accountBindEnd_ = 0;
68 
69     int64_t accountAddBegin_ = 0;
70     int64_t accountAddEnd_ = 0;
71 
72     int64_t accountDelBegin_ = 0;
73     int64_t accountDelEnd_ = 0;
74 
75     int64_t accountQueryBegin_ = 0;
76     int64_t accountQueryEnd_ = 0;
77 
78     int64_t instanceCreate_ = 0;
79     int64_t serviceOnStart_ = 0;
80     int64_t serviceOnStop_ = 0;
81     int64_t serviceInit_ = 0;
82 
83     std::map<std::string, int64_t> accountStateChangeRecords_;
84 
85     bool enableStat_ = true;
86 };
87 }  // namespace AccountSA
88 }  // namespace OHOS
89 
90 #endif  // OS_ACCOUNT_FRAMEWORKS_COMMON_PERF_STAT_INCLUDE_PERF_STAT_H
91