• 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 #ifndef SP_TASK_H
16 #define SP_TASK_H
17 #include <iostream>
18 #include <functional>
19 #include <vector>
20 #include <thread>
21 #include <map>
22 #include <mutex>
23 #include "sp_csv_util.h"
24 namespace OHOS {
25 namespace SmartPerf {
26 enum class ExceptionMsg {
27     NO_ERR,
28     SESSION_ID_NULL,
29     TASK_CONFIG_NULL,
30     PACKAGE_NULL,
31 };
32 
33 const std::map<ExceptionMsg, std::string> ExceptionMsgMap = {
34     {ExceptionMsg::NO_ERR, "NoErr"},
35     {ExceptionMsg::SESSION_ID_NULL, "SessionIdNull"},
36     {ExceptionMsg::TASK_CONFIG_NULL, "TaskConfigNull"},
37     {ExceptionMsg::PACKAGE_NULL, "PackageNull"},
38 };
39 
40 enum class ErrCode {
41     OK,
42     FAILED,
43 };
44 
45 struct TaskInfo {
46     std::string sessionId;
47     std::string packageName;
48     std::vector<std::string> taskConfig = {};
49     long long freq;
50 };
51 
52 class SPTask {
53 public:
GetInstance()54     static SPTask &GetInstance()
55     {
56         static SPTask instance;
57         return instance;
58     }
59     ErrCode InitTask(std::string recvStr);
60     ErrCode StartTask(std::function<void(std::string data)> msgTask);
61     void StopTask();
62 private:
63     TaskInfo curTaskInfo;
64     long long startTime;
65     std::thread thread;
66     std::vector<SPData> vmap;
67     bool isRunning = false;
68     bool isInit = false;
69     std::mutex mtx;
70     const std::string baseOutPath = "/data/local/tmp/smartperf";
71 };
72 }
73 }
74 
75 
76 #endif