add innerkit for hiviewbase

Signed-off-by: lyj_love_code <liangyujian2@huawei.com>
This commit is contained in:
lyj_love_code 2023-06-27 15:49:35 +08:00
parent d12817f759
commit badb163f4e
80 changed files with 151 additions and 1409 deletions

View File

@ -48,8 +48,7 @@ The code directory structure of Hiview is as follows:
```
/base/hiviewdfx/hiview
├── adapter # Platform adaptation code
│ ├── service # Service adaptation code
│ └── system_service # System API adaptation code
│ └── service # Service adaptation code
├── base # Module definition and utility class
│ └── utility
├── build # Compilation scripts

View File

@ -48,14 +48,13 @@ Hiview源代码目录结构如下
```
/base/hiviewdfx/hiview.
├── adapter #平台适配
│ ├── service #服务适配
│ └── system_service #系统接口适配
│ └── service #服务适配
├── base #模块定义,工具类
│ └── utility
├── build #编译脚本
├── include #公共定义
├── core #插件管理
└── service #平台服务
└── service #平台服务
```
## 约束<a name="section7147138193814"></a>

View File

@ -17,8 +17,6 @@ group("unittest") {
deps = [
"dbstore:unittest",
"plugins/eventservice/service:unittest",
"system_service:unittest",
"utility:unittest",
]
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -17,7 +17,6 @@ config("db_store_config") {
visibility = [ "*:*" ]
include_dirs = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
".",
"include",
]
@ -36,7 +35,7 @@ ohos_source_set("db_store_source") {
]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base/utility:hiview_utility",
"//third_party/ejdb:ejdb",
"//third_party/iowow:iowow",
]
@ -60,7 +59,7 @@ ohos_source_set("db_store_source_static_lib_for_tdd") {
]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base/utility:hiview_utility",
"//third_party/ejdb:ejdb_static_lib_for_tdd",
"//third_party/iowow:iowow",
]

View File

@ -25,7 +25,6 @@ ohos_source_set("eventlogger_adapter_logcatcher") {
sources = [ "impl/log_catcher_utils.cpp" ]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase",
"//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:libdfx_dumpcatcher",
]

View File

@ -96,7 +96,6 @@ ohos_source_set("sys_event_service_ohos") {
deps = [
":sys_event_service_ohos_common",
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase",
"$hiview_base/event_store:event_store_source",
"$hiview_base/running_status_logger:running_status_logger_source",

View File

@ -33,7 +33,6 @@ ohos_source_set("hiview_service_adapter") {
sources = [ "hiview_service_adapter.cpp" ]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
"$hiview_core:hiview_core",
]

View File

@ -40,7 +40,10 @@ ohos_source_set("hiview_service_impl") {
"src/hiview_service_ability_stub.cpp",
]
deps = [ "$hiview_base:hiviewbase" ]
deps = [
"$hiview_base:hiviewbase",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"access_token:libaccesstoken_sdk",

View File

@ -1,51 +0,0 @@
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/hiviewdfx/hiview/hiview.gni")
import("//build/ohos.gni")
config("system_service_config") {
visibility = [ "*:*" ]
include_dirs = [
"//third_party/bounds_checking_function/include",
"include",
]
}
ohos_source_set("system_service") {
part_name = "hiview"
public_configs = [ ":system_service_config" ]
sources = [
"parameter_ex.cpp",
"platform/ohos/parameter_ex.cpp",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"init:libbegetutil",
]
} else {
external_deps = [
"c_utils:utils",
"init_lite:libbegetutil",
]
}
}
group("unittest") {
testonly = true
deps = [ "test:SystemServiceOhosUnitTest" ]
}

View File

@ -1,17 +0,0 @@
set(system_service_headfiles
${CMAKE_CURRENT_SOURCE_DIR}/include/parameter_ex.h
)
set(system_service_sources ${CMAKE_CURRENT_SOURCE_DIR}/parameter_ex.cpp)
if(WIN32)
list(APPEND system_service_sources ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/parameter_ex.cpp)
elseif(UNIX)
list(APPEND system_service_sources ${CMAKE_CURRENT_SOURCE_DIR}/platform/linux/parameter_ex.cpp)
endif()
target_sources(${PROJECT_NAME}
PRIVATE
${system_service_sources}
${system_service_headfiles})
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "parameter_ex.h"
namespace OHOS {
namespace HiviewDFX {
namespace Parameter {
bool IsBetaVersion()
{
auto userType = GetInteger(KEY_HIVIEW_USER_TYPE, UserType::COMMERCIAL);
return ((userType == UserType::BETA) || (userType == UserType::OVERSEAS_BETA));
}
DeviceType GetDeviceType()
{
std::string deviceType = GetString(KEY_BUILD_CHARACTER, "unknown");
if (deviceType == "phone" || deviceType == "default") {
return DeviceType::PHONE;
} else if (deviceType == "watch") {
return DeviceType::WATCH;
} else if (deviceType == "tv") {
return DeviceType::TV;
} else if (deviceType == "car") {
return DeviceType::IVI;
} else {
return DeviceType::UNKNOWN;
}
}
} // namespace Parameter
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "parameter_ex.h"
#include <cstdint>
namespace OHOS {
namespace HiviewDFX {
namespace Parameter {
std::string GetString(const std::string& key, const std::string& defaultValue)
{
return defaultValue;
}
int64_t GetInteger(const std::string& key, const int64_t defaultValue)
{
return defaultValue;
}
uint64_t GetUnsignedInteger(const std::string& key, const uint64_t defaultValue)
{
return defaultValue;
}
bool GetBoolean(const std::string& key, const bool defaultValue)
{
return false;
}
bool SetProperty(const std::string& key, const std::string& defaultValue)
{
return false;
}
} // namespace Parameter
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "parameter_ex.h"
#include <cstdint>
namespace OHOS {
namespace HiviewDFX {
namespace Parameter {
std::string GetString(const std::string& key, const std::string& defaultValue)
{
return defaultValue;
}
int64_t GetInteger(const std::string& key, const int64_t defaultValue)
{
return defaultValue;
}
uint64_t GetUnsignedInteger(const std::string& key, const uint64_t defaultValue)
{
return defaultValue;
}
bool GetBoolean(const std::string& key, const bool defaultValue)
{
return defaultValue;
}
bool SetProperty(const std::string& key, const std::string& defaultValue)
{
return true;
}
} // namespace Parameter
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,52 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/hiviewdfx/hiview/hiview.gni")
import("//build/test.gni")
module_output_path = "hiview/adapter/system_service"
group("unittest") {
testonly = true
deps = [ ":SystemServiceOhosUnitTest" ]
}
config("unittest_config") {
include_dirs = [
"$hiview_adapter/system_service/include",
"$hiview_adapter/system_service/test/unittest/common",
]
cflags_cc = [ "-D__UNITTEST__" ]
}
ohos_unittest("SystemServiceOhosUnitTest") {
module_out_path = module_output_path
configs = [ ":unittest_config" ]
sources = [
"$hiview_adapter/system_service/parameter_ex.cpp",
"$hiview_adapter/system_service/platform/ohos/parameter_ex.cpp",
"$hiview_adapter/system_service/test/unittest/common/system_service_ohos_test.cpp",
]
cflags_cc = [ "-DTEST_LOCAL_SRC" ]
deps = [ "//third_party/googletest:gtest_main" ]
external_deps = [
"init:libbeget_proxy",
"init:libbegetutil",
]
}

View File

@ -1,53 +0,0 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/hiviewdfx/hiview/hiview.gni")
import("//build/ohos.gni")
config("hiview_adapter_utils_config") {
visibility = [ "*:*" ]
include_dirs = [
".",
"include",
"$hiview_adapter/system_service/include",
"$hiview_adapter/utility/include",
]
}
ohos_source_set("hiview_adapter_utility") {
public_configs = [ ":hiview_adapter_utils_config" ]
sources = [
"dynamic_module.cpp",
"platform/ohos/common_utils.cpp",
"platform/ohos/file_util.cpp",
"platform/ohos/socket_util.cpp",
"platform/ohos/thread_util.cpp",
"platform/ohos/time_util.cpp",
"time_util.cpp",
]
deps = [ "$hiview_adapter/system_service:system_service" ]
part_name = "hiview"
subsystem_name = "hiviewdfx"
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}
group("unittest") {
testonly = true
deps = [ "test:unittest" ]
}

View File

@ -1,391 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "file_util.h"
#include <algorithm>
#include <cstdio>
#include <cstring>
#ifdef __gnu_linux__
#include <experimental/filesystem>
#else
#include <filesystem>
#endif
#include <fstream>
#include <iostream>
#include <iterator>
namespace OHOS {
namespace HiviewDFX {
namespace FileUtil {
using namespace std;
#ifdef __gnu_linux__
namespace fs = experimental::filesystem;
#else
namespace fs = std::filesystem;
constexpr int PATH_MAX = 4096;
#endif
constexpr int MODE_MAX = 07777;
constexpr int MAX_FILE_LENGTH = 32 * 1024 * 1024; // 32MB
bool LoadStringFromFile(const string& filePath, string& content)
{
ifstream file(filePath.c_str());
if (!file.is_open()) {
return false;
}
file.seekg(0, ios::end);
const long fileLength = static_cast<long>(file.tellg());
if (fileLength > MAX_FILE_LENGTH) {
return false;
}
content.clear();
file.seekg(0, ios::beg);
copy(istreambuf_iterator<char>(file), istreambuf_iterator<char>(), back_inserter(content));
return true;
}
bool LoadBufferFromNodeFile(const string& filePath, vector<char>& content)
{
string realPath;
if (!PathToRealPath(filePath, realPath)) {
return false;
}
FILE* fp = fopen(realPath.c_str(), "r");
if (fp == nullptr) {
return false;
}
char ch = fgetc(fp);
int byteCount = 1;
while (!feof(fp)) {
if (byteCount > MAX_FILE_LENGTH) {
fclose(fp);
fp = nullptr;
content.clear();
return false;
}
content.push_back(ch);
ch = fgetc(fp);
byteCount++;
}
fclose(fp);
fp = nullptr;
return true;
}
bool LoadBufferFromFile(const std::string& filePath, std::vector<char>& content)
{
ifstream file;
file.open(filePath.c_str(), ios::in | ios::binary);
if (!file.is_open()) {
return false;
}
file.seekg(0, std::ios::end);
const long fileLength = static_cast<long>(file.tellg());
if (fileLength > MAX_FILE_LENGTH) {
return false;
}
// lseek is not support the linux file node
if (fileLength < 0) {
return LoadBufferFromNodeFile(filePath, content);
}
if (fileLength == 0) {
content.clear();
return true;
}
file.seekg(0, std::ios::beg);
if (file.fail()) {
return false;
}
content.resize(fileLength);
file.read(&content[0], fileLength);
return true;
}
bool SaveStringToFile(const std::string& filePath, const std::string& content, bool truncated)
{
if (content.empty()) {
return true;
}
ofstream file;
if (truncated) {
file.open(filePath.c_str(), ios::out | ios::trunc);
} else {
file.open(filePath.c_str(), ios::out | ios::app);
}
if (!file.is_open()) {
return false;
}
file.write(content.c_str(), content.length());
if (file.fail()) {
return false;
}
return true;
}
bool SaveBufferToFile(const string& filePath, const vector<char>& content, bool truncated)
{
// if the file is not exist,create it first!
ios_base::openmode mode = truncated ? (ios::out | ios::binary | ios::trunc) : (ios::out | ios::binary | ios::app);
ofstream file;
file.open(filePath.c_str(), mode);
if (!file.is_open()) {
return false;
}
if (content.empty()) {
return true;
}
file.write(&content[0], content.size());
return true;
}
bool FileExists(const std::string& fileName)
{
error_code ec;
bool ret = fs::exists(fileName, ec); // noexcept
if (ec) {
printf("%s\n", ec.message().c_str());
}
return ret;
}
std::string ExtractFilePath(const std::string& fileFullName)
{
return fs::path(fileFullName).parent_path().string();
}
std::string ExtractFileName(const std::string& fileFullName)
{
return fs::path(fileFullName).filename().string();
}
void GetDirFiles(const std::string& path, std::vector<std::string>& files)
{
files.clear();
for (const auto& p : fs::directory_iterator(path)) {
files.push_back(p.path().string());
}
return;
}
bool ForceCreateDirectory(const std::string& path)
{
error_code ec;
if (fs::exists(path, ec)) {
return true;
}
if (!fs::create_directories(path, ec)) {
return false;
}
return fs::exists(path, ec);
}
bool ForceCreateDirectory(const std::string& path, int mode)
{
if (!ForceCreateDirectory(path)) {
return false;
}
return ChangeModeDirectory(path, mode);
}
bool ForceRemoveDirectory(const std::string& path, bool isNeedDeleteGivenDirSelf)
{
error_code ec;
fs::remove_all(path, ec);
return true;
}
/* return true if file removed successfully, return false if file not exist. */
bool RemoveFile(const std::string& fileName)
{
error_code ec;
return fs::remove(fileName, ec);
}
uint64_t GetFileSize(const std::string& path)
{
error_code ec;
return fs::file_size(path, ec);
}
uint64_t GetFolderSize(const std::string& path)
{
vector<string> files;
struct stat statbuf = {0};
GetDirFiles(path, files);
uint64_t totalSize = 0;
for (auto& file : files) {
if (stat(file.c_str(), &statbuf) == 0) {
totalSize += statbuf.st_size;
}
}
return totalSize;
}
int CreateFile(const std::string &path, mode_t mode)
{
if (FileExists(path)) {
return 0;
} else {
std::ofstream fout(path);
if (!fout.is_open()) {
return -1;
}
fout.flush();
fout.close();
if (ChangeMode(path, mode) != 0) {
return -1;
}
}
return 0;
}
int CopyFile(const std::string &src, const std::string &des)
{
std::ifstream fin(src);
std::ofstream fout(des);
if (!fin.is_open()) {
return -1;
}
if (!fout.is_open()) {
return -1;
}
fout << fin.rdbuf();
if (fout.fail()) {
fout.clear();
}
fout.flush();
return 0;
}
bool IsDirectory(const std::string &path)
{
return fs::is_directory(path);
}
bool GetLastLine(std::istream &fin, std::string &line, uint32_t maxLen)
{
if (fin.tellg() <= 0) {
return false;
} else {
fin.seekg(-1, fin.cur);
}
uint32_t count = 0;
while (fin.good() && fin.peek() == fin.widen('\n') && fin.tellg() > 0 && count < maxLen) {
fin.seekg(-1, fin.cur);
count++;
}
if (!fin.good() || count >= maxLen) {
return false;
}
if (fin.tellg() == 0) {
return true;
}
count = 0;
while (fin.good() && fin.peek() != fin.widen('\n') && fin.tellg() > 0 && count < maxLen) {
fin.seekg(-1, fin.cur);
count++;
}
if (!fin.good() || count >= maxLen) {
return false;
}
if (fin.tellg() != 0) {
fin.seekg(1, fin.cur);
}
auto oldPos = fin.tellg();
getline(fin, line);
fin.seekg(oldPos);
return true;
}
std::string GetParentDir(const std::string &path)
{
string str = ExtractFilePath(path);
if (str.empty()) {
return "";
}
return str.substr(0, str.size() - 1);
}
// inner function, and param is legitimate
bool ChangeMode(const string& fileName, const mode_t& mode)
{
if (!FileExists(fileName)) {
return false;
}
if (mode > MODE_MAX) {
return false;
}
auto perm = static_cast<fs::perms>(mode);
fs::permissions(fileName, perm);
return true;
}
bool ChangeModeDirectory(const string& path, const mode_t& mode)
{
if (!FileExists(path)) {
return false;
}
for (auto& p : fs::recursive_directory_iterator(path)) {
string tmpPath = p.path().string();
replace(tmpPath.begin(), tmpPath.end(), '\\', '/');
if (!ChangeMode(tmpPath, mode)) {
return false;
}
}
return ChangeMode(path, mode);
}
bool PathToRealPath(const std::string& path, std::string& realPath)
{
if (path.empty()) {
return false;
}
if ((path.length() >= PATH_MAX)) {
return false;
}
if (!fs::exists(path)) {
return false;
}
fs::path absolutePath = fs::canonical(path);
realPath = absolutePath.string();
#ifdef _WIN32
FormatPath2UnixStyle(realPath);
#endif
return true;
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HIVIEW_BASE_DEFINES_H
#define HIVIEW_BASE_DEFINES_H
#ifndef __UNUSED
#if defined(_MSC_VER)
#define __UNUSED // Note: actually gcc seems to also supports this syntax.
#else
#if defined(__GNUC__)
#define __UNUSED __attribute__ ((__unused__))
#endif
#endif
#endif
#ifdef _WIN32
#define DllExport __declspec (dllexport)
#else
#define DllExport
#endif // _WIN32
#endif // HIVIEW_BASE_DEFINES_H

View File

@ -1,121 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "file_util.h"
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <iterator>
#include <pthread.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/syscall.h>
namespace OHOS {
namespace HiviewDFX {
namespace FileUtil {
using namespace std;
std::string IncludeTrailingPathDelimiter(const std::string& path)
{
return "";
}
std::string ExcludeTrailingPathDelimiter(const std::string& path)
{
return "";
}
bool ChangeModeFile(const string& fileName, const mode_t& mode)
{
if (access(fileName.c_str(), F_OK) != 0) {
return false;
}
return ChangeMode(fileName, mode);
}
mode_t Umask(const mode_t& mode)
{
return umask(mode);
}
int Open(const std::string& path, const int flags, const mode_t mode)
{
return open(path.c_str(), flags, mode);
}
void CreateDirWithDefaultPerm(const std::string& path, uid_t aidRoot, uid_t aidSystem)
{
FileUtil::ForceCreateDirectory(path);
chown(path.c_str(), aidRoot, aidSystem);
}
bool WriteBufferToFd(int fd, const char* buffer, size_t size)
{
if (fd < 0) {
return false;
}
if (buffer == nullptr) {
return false;
}
ssize_t writeSize = size;
if (writeSize != TEMP_FAILURE_RETRY(write(fd, buffer, size))) {
return false;
}
return true;
}
bool SaveStringToFd(int fd, const std::string& content)
{
if (fd <= 0) {
return false;
}
if (content.empty()) {
return true;
}
const long len = write(fd, content.c_str(), content.length());
if (len < 0) {
return false;
}
if (static_cast<unsigned long>(len) != content.length()) {
return false;
}
return true;
}
bool RenameFile(const std::string& src, const std::string& dest)
{
if (std::rename(src.c_str(), dest.c_str()) == 0) {
return true;
}
return false;
}
} // namespace FileUtil
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "thread_util.h"
#include <pthread.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace OHOS {
namespace HiviewDFX {
namespace Thread {
pid_t GetTid()
{
return syscall(SYS_gettid);
}
void SetThreadDescription(const std::string &name)
{
prctl(PR_SET_NAME, name.c_str());
}
}
}
}

View File

@ -1,106 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "time_util.h"
#include <chrono>
#include <sys/time.h>
#include <unistd.h>
namespace OHOS {
namespace HiviewDFX {
namespace TimeUtil {
time_t StrToTimeStamp(const std::string& tmStr, const std::string& format)
{
std::string stTime = tmStr;
struct tm tmFormat { 0 };
strptime(stTime.c_str(), format.c_str(), &tmFormat);
tmFormat.tm_isdst = -1;
return mktime(&tmFormat);
}
uint64_t GenerateTimestamp()
{
struct timeval now { 0 };
if (gettimeofday(&now, nullptr) == -1) {
return 0;
}
return (now.tv_sec * SEC_TO_MICROSEC + now.tv_usec);
}
void Sleep(unsigned int seconds)
{
sleep(seconds);
}
int GetMillSecOfSec()
{
auto now = std::chrono::system_clock::now();
auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
return millisecs.count() % SEC_TO_MILLISEC;
}
uint64_t GetMilliseconds()
{
auto now = std::chrono::system_clock::now();
auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
return millisecs.count();
}
std::string TimestampFormatToDate(time_t timeStamp, const std::string& format)
{
char date[MAX_TIME_BUFF] = {0};
struct tm result {};
if (localtime_r(&timeStamp, &result) != nullptr) {
strftime(date, MAX_TIME_BUFF, format.c_str(), &result);
}
return std::string(date);
}
std::string GetTimeZone()
{
struct timeval currentTime;
if (gettimeofday(&currentTime, nullptr) != 0) {
return "";
}
time_t systemSeconds = currentTime.tv_sec;
struct tm tmLocal;
if (localtime_r(&systemSeconds, &tmLocal) == nullptr) {
return "";
}
int tzBufSize = 20;
char tz[tzBufSize];
auto ret = strftime(tz, tzBufSize, "%z", &tmLocal);
if (ret > 0) {
return std::string(tz);
}
return std::string("+0000");
}
int64_t Get0ClockStampMs()
{
time_t now = std::time(nullptr);
int64_t zero = now;
struct tm *l = std::localtime(&now);
if (l != nullptr) {
l->tm_hour = 0;
l->tm_min = 0;
l->tm_sec = 0;
zero = std::mktime(l) * SEC_TO_MILLISEC; // time is 00:00:00
}
return zero;
}
} // namespace TimeUtil
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,99 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "file_util.h"
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <iterator>
namespace OHOS {
namespace HiviewDFX {
namespace FileUtil {
using namespace std;
namespace fs = std::filesystem;
constexpr int PATH_MAX = 4096;
constexpr int MODE_MAX = 07777;
constexpr int MAX_FILE_LENGTH = 32 * 1024 * 1024; // 32MB
bool SaveStringToFd(int fd, const std::string& content)
{
return true;
}
std::string IncludeTrailingPathDelimiter(const std::string& path)
{
return "";
}
std::string ExcludeTrailingPathDelimiter(const std::string& path)
{
return "";
}
mode_t Umask(const mode_t& mode)
{
return mode;
}
int Open(const std::string& path, const int flags, const mode_t mode)
{
const mode_t defaultMode = 0;
return open(path.c_str(), flags, defaultMode);
}
void CreateDirWithDefaultPerm(const std::string& path, uid_t aidRoot, uid_t aidSystem)
{
FileUtil::ForceCreateDirectory(path);
}
void FormatPath2UnixStyle(std::string &path)
{
replace(path.begin(), path.end(), '\\', '/');
}
void RemoveFolderBeginWith(const std::string &path, const std::string &folderName)
{
if (!fs::exists(path)) {
return;
}
for (auto& cur : fs::recursive_directory_iterator(path)) {
if (cur.is_directory() &&
strncmp(cur.path().filename().string().c_str(), folderName.c_str(), folderName.length()) == 0) {
ForceRemoveDirectory(cur.path().string());
}
}
}
bool WriteBufferToFd(int fd, const char* buffer, size_t size)
{
return true;
}
bool RenameFile(const std::string& src, const std::string& dest)
{
if (std::rename(src.c_str(), dest.c_str()) == 0) {
return true;
}
return false;
}
} // namespace FileUtil
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,35 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "thread_util.h"
#include <Windows.h>
namespace OHOS {
namespace HiviewDFX {
namespace Thread {
int GetTid()
{
return GetCurrentThreadId();
}
void SetThreadDescription(const std::string &name)
{
std::wstring wThreadName = std::wstring(name.begin(), name.end());
PCWSTR windowsThreadName = wThreadName.c_str();
::SetThreadDescription(GetCurrentThread(), windowsThreadName);
}
}
}
}

View File

@ -1,96 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "time_util.h"
#include <chrono>
#include <iomanip>
#include <sstream>
#include <thread>
namespace OHOS {
namespace HiviewDFX {
namespace TimeUtil {
time_t StrToTimeStamp(const std::string& tmStr, const std::string& format)
{
std::istringstream input(tmStr.c_str());
struct tm tmFormat = { 0 };
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
input >> std::get_time(&tmFormat, format.c_str());
if (input.fail()) {
return 0;
}
return mktime(&tmFormat);
}
uint64_t GetTimeOfDay()
{
struct timespec now = { 0, 0 };
int err = timespec_get(&now, TIME_UTC);
if (err == 0) {
return 0;
}
return static_cast<uint64_t>(now.tv_sec);
}
uint64_t GenerateTimestamp()
{
auto now = std::chrono::system_clock::now();
auto secs = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch());
return static_cast<uint64_t>(secs.count());
}
uint64_t GetMilliseconds()
{
auto now = std::chrono::system_clock::now();
auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
return millisecs.count();
}
void Sleep(unsigned int seconds)
{
std::this_thread::sleep_for(std::chrono::seconds(seconds));
}
int GetMillSecOfSec()
{
auto now = std::chrono::system_clock::now();
auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
return millisecs.count() % SEC_TO_MILLISEC;
}
std::string GetTimeZone()
{
std::string timeZone = "";
return timeZone;
}
int64_t Get0ClockStampMs()
{
time_t now = std::time(nullptr);
int64_t zero = now;
struct tm *l = std::localtime(&now);
if (l != nullptr) {
l->tm_hour = 0;
l->tm_min = 0;
l->tm_sec = 0;
zero = std::mktime(l) * SEC_TO_MILLISEC; // time is 00:00:00
}
return zero;
}
} // namespace TimeUtil
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -1,51 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/hiviewdfx/hiview/hiview.gni")
import("//build/test.gni")
module_output_path = "hiview/adapter/utility"
group("unittest") {
testonly = true
deps = [ ":AdapterUtilityOhosTest" ]
}
config("unittest_config") {
include_dirs = [
"$hiview_adapter/utility/include",
"$hiview_adapter/utility/test/unittest/common",
]
cflags_cc = [ "-D__UNITTEST__" ]
}
ohos_unittest("AdapterUtilityOhosTest") {
module_out_path = module_output_path
configs = [ ":unittest_config" ]
sources = [ "$hiview_adapter/utility/test/unittest/common/adapter_utility_ohos_test.cpp" ]
cflags_cc = [ "-DTEST_LOCAL_SRC" ]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"//third_party/googletest:gtest_main",
]
external_deps = [
"init:libbeget_proxy",
"init:libbegetutil",
]
}

View File

@ -1,30 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "time_util.h"
#include <chrono>
namespace OHOS {
namespace HiviewDFX {
namespace TimeUtil {
uint64_t GetNanoTime()
{
auto nanoNow = std::chrono::steady_clock::now().time_since_epoch();
return nanoNow.count();
}
} // namespace TimeUtil
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -17,15 +17,11 @@ config("hiview_base_config") {
visibility = [ "*:*" ]
include_dirs = [
"//third_party/jsoncpp/include",
"//third_party/bounds_checking_function/include",
"//commonlibrary/c_utils/base/include",
"include",
"utility/include",
"event_pool",
"event_store/include",
"$hiview_root/include",
"$hiview_adapter/utility/include",
"logstore/include",
"$hiview_adapter/dbstore/include",
]
@ -94,15 +90,11 @@ ohos_source_set("hiview_base") {
ohos_shared_library("hiviewbase") {
all_dependent_configs = [ ":hiview_base_config" ]
public_configs = [ ":hiview_base_config" ]
public_configs += [
"event_report:hiview_event_report_config",
"$hiview_core:hiview_core_config",
]
public_configs += [ "event_report:hiview_event_report_config" ]
deps = [
":hiview_base",
"$hiview_adapter/dbstore:db_store_source",
"$hiview_adapter/utility:hiview_adapter_utility",
"logstore:log_store",
]
@ -128,7 +120,6 @@ ohos_static_library("hiviewbase_static_lib_for_tdd") {
deps = [
":hiview_base",
"$hiview_adapter/dbstore:db_store_source_static_lib_for_tdd",
"$hiview_adapter/utility:hiview_adapter_utility",
"logstore:log_store",
]

View File

@ -19,7 +19,6 @@ module_output_path = "hiview/hiview/base"
config("unittest_config") {
include_dirs = [
"../include",
"$hiview_adapter/utility/include",
"unittest/common",
]
@ -36,7 +35,6 @@ ohos_unittest("EventPoolTest") {
sources = [ "unittest/common/event_pool_test.cpp" ]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase_static_lib_for_tdd",
"../:eventpool",
"//third_party/googletest:gtest_main",

View File

@ -21,7 +21,6 @@ config("event_store_config") {
"//third_party/bounds_checking_function/include",
"//commonlibrary/c_utils/base/include",
"include",
"$hiview_adapter/utility/include",
"$hiview_base/log/include",
"$hiview_base/include",
"$hiview_base/running_status_logger/include",

View File

@ -17,7 +17,6 @@ config("event_store_utility_config") {
visibility = [ "*:*" ]
include_dirs = [
"$hiview_adapter/utility/include",
"$hiview_base/event_store/include",
"$hiview_base/utility/include",
"$hiview_base/include",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -15,6 +15,9 @@
#ifndef HIVIEW_BASE_DEFINES_H
#define HIVIEW_BASE_DEFINES_H
#include <unordered_set>
#include <unordered_map>
#ifndef __UNUSED
#if defined(_MSC_VER)
@ -32,4 +35,26 @@
#define DllExport
#endif // _WIN32
namespace OHOS {
namespace HiviewDFX {
struct DllExport DomainRule {
enum FilterType {
INCLUDE,
EXCLUDE
};
uint8_t filterType;
std::unordered_set<std::string> eventlist;
bool FindEvent(const std::string& eventName) const;
};
struct DllExport DispatchRule {
std::unordered_set<uint8_t> typeList;
std::unordered_set<std::string> tagList;
std::unordered_set<std::string> eventList;
std::unordered_map<std::string, DomainRule> domainRuleMap;
bool FindEvent(const std::string &domain, const std::string &eventName);
};
} // namespace HiviewDFX
} // namespace OHOS
#endif // HIVIEW_BASE_DEFINES_H

View File

@ -25,25 +25,6 @@
namespace OHOS {
namespace HiviewDFX {
struct DllExport DomainRule
{
enum FilterType {
INCLUDE,
EXCLUDE
};
uint8_t filterType;
std::unordered_set<std::string> eventlist;
bool FindEvent(const std::string& eventName) const;
};
struct DllExport DispatchRule {
std::unordered_set<uint8_t> typeList;
std::unordered_set<std::string> tagList;
std::unordered_set<std::string> eventList;
std::unordered_map<std::string, DomainRule> domainRuleMap;
bool FindEvent(const std::string &domain, const std::string &eventName);
};
class DllExport HiviewRuleParser {
public:
explicit HiviewRuleParser(const std::string & filePath);

View File

@ -24,7 +24,6 @@
#include <sys/types.h>
#include "defines.h"
#include "public_defines.h"
#include "dispatch_config.h"
#include "base/raw_data.h"
@ -246,7 +245,7 @@ public:
{
return true;
};
virtual std::string GetHandlerInfo()
{
return "";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -19,8 +19,8 @@
#include <memory>
#include <set>
#include "defines.h"
#include "plugin.h"
#include "dispatch_config.h"
namespace OHOS {
namespace HiviewDFX {

View File

@ -26,7 +26,6 @@
#include "event.h"
#include "event_loop.h"
#include "plugin_extra_info.h"
#include "dispatch_config.h"
class HiEvent;
namespace OHOS {
@ -51,7 +50,7 @@ public:
*/
virtual bool CanProcessEvent(std::shared_ptr<Event> event) override;
/* If the plugin is in a pipeline, this function will be used to determine
/* If the plugin is in a pipeline, this function will be used to determine
* whether the current pipeline event can be processed by the plugin.
*/
virtual bool IsInterestedPipelineEvent(std::shared_ptr<Event> event) override;

View File

@ -289,6 +289,11 @@
"OHOS::HiviewDFX::EventStore::EventCol::LEVEL";
"OHOS::HiviewDFX::EventStore::EventCol::SEQ";
"OHOS::HiviewDFX::EventStore::EventCol::TAG";
"OHOS::HiviewDFX::TimeUtil::Get0ClockStampMs()";
"OHOS::HiviewDFX::TimeUtil::TimestampFormatToDate(long, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
"OHOS::HiviewDFX::TimeUtil::TimestampFormatToDate(long long, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
"OHOS::HiviewDFX::TimeUtil::GetMilliseconds()";
"OHOS::HiviewDFX::Parameter::GetString(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
};
local:
*;

View File

@ -30,10 +30,7 @@ ohos_source_set("log_store") {
"log_store_ex.cpp",
]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiview_base",
]
deps = [ "$hiview_base:hiview_base" ]
external_deps = [ "hilog:libhilog" ]
}

View File

@ -20,6 +20,7 @@
#include "hiview_event_report.h"
#include "thread_util.h"
#include "time_util.h"
namespace OHOS {
namespace HiviewDFX {
Plugin::~Plugin()

View File

@ -20,7 +20,6 @@ config("running_status_logger_config") {
include_dirs = [
"include",
"$hiview_adapter/dbstore/include",
"$hiview_adapter/utility/include",
"$hiview_base/log/include",
"$hiview_base/include",
"$hiview_base/running_status_logger/include",
@ -48,6 +47,7 @@ ohos_source_set("running_status_logger_source") {
deps = [
"$hiview_base/event_raw:hiview_event_raw_decode",
"$hiview_base/event_raw:hiview_event_raw_encode",
"$hiview_base/utility:hiview_utility",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -19,7 +19,6 @@ config("hiview_utils_config") {
include_dirs = [
".",
"include",
"$hiview_adapter/utility/include",
]
}
@ -27,12 +26,17 @@ ohos_source_set("hiview_utility") {
public_configs = [ ":hiview_utils_config" ]
sources = [
"common_utils.cpp",
"dynamic_module.cpp",
"file_util.cpp",
"memory_util.cpp",
"parameter_ex.cpp",
"socket_util.cpp",
"string_util.cpp",
"thread_util.cpp",
"time_util.cpp",
]
deps = [ "$hiview_adapter/utility:hiview_adapter_utility" ]
defines = []
if (use_musl && use_jemalloc && use_jemalloc_dfx_intf) {
defines += [ "USE_JEMALLOC_DFX_INTF" ]
@ -41,6 +45,7 @@ ohos_source_set("hiview_utility") {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
]
part_name = "hiview"

View File

@ -19,7 +19,6 @@
#if defined(_WIN32)
#include <windows.h>
#endif
#include "defines.h"
namespace OHOS {
namespace HiviewDFX {
#if defined(_WIN32)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -50,6 +50,28 @@ int WaitParamSync(const char *key, const char *value, int timeout)
{
return WaitParameter(key, value, timeout);
}
bool IsBetaVersion()
{
auto userType = GetInteger(KEY_HIVIEW_USER_TYPE, UserType::COMMERCIAL);
return ((userType == UserType::BETA) || (userType == UserType::OVERSEAS_BETA));
}
DeviceType GetDeviceType()
{
std::string deviceType = GetString(KEY_BUILD_CHARACTER, "unknown");
if (deviceType == "phone" || deviceType == "default") {
return DeviceType::PHONE;
} else if (deviceType == "watch") {
return DeviceType::WATCH;
} else if (deviceType == "tv") {
return DeviceType::TV;
} else if (deviceType == "car") {
return DeviceType::IVI;
} else {
return DeviceType::UNKNOWN;
}
}
} // namespace Parameter
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -18,7 +18,11 @@ module_output_path = "hiview/base/utility"
group("unittest") {
testonly = true
deps = [ ":BaseUtilityUnitTest" ]
deps = [
":AdapterUtilityOhosTest",
":BaseUtilityUnitTest",
":SystemServiceOhosUnitTest",
]
}
config("base_utility_config_test") {
@ -40,10 +44,48 @@ ohos_unittest("BaseUtilityUnitTest") {
sources = [ "unittest/common/base_utility_unit_test.cpp" ]
deps = [
"$hiview_base:hiviewbase_static_lib_for_tdd",
"$hiview_core:hiview_core",
"//base/hiviewdfx/hiview/base/utility:hiview_utility",
"$hiview_base/utility:hiview_utility",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
]
}
ohos_unittest("SystemServiceOhosUnitTest") {
module_out_path = module_output_path
configs = [ ":base_utility_config_test" ]
sources = [ "unittest/common/system_service_ohos_test.cpp" ]
cflags_cc = [ "-DTEST_LOCAL_SRC" ]
deps = [
"$hiview_base/utility:hiview_utility",
"//third_party/googletest:gtest_main",
]
external_deps = [
"init:libbeget_proxy",
"init:libbegetutil",
]
}
ohos_unittest("AdapterUtilityOhosTest") {
module_out_path = module_output_path
configs = [ ":base_utility_config_test" ]
sources = [ "unittest/common/adapter_utility_ohos_test.cpp" ]
cflags_cc = [ "-DTEST_LOCAL_SRC" ]
deps = [
"$hiview_base/utility:hiview_utility",
"//third_party/googletest:gtest_main",
]
external_deps = [
"init:libbeget_proxy",
"init:libbegetutil",
]
}

View File

@ -134,6 +134,11 @@ std::string FormatTime(const int64_t timestamp, const std::string &format)
return std::string(buffer);
}
uint64_t GetNanoTime()
{
auto nanoNow = std::chrono::steady_clock::now().time_since_epoch();
return nanoNow.count();
}
} // namespace TimeUtil
} // namespace HiviewDFX
} // namespace OHOS

View File

@ -101,6 +101,18 @@
"xpower_event_jsvm.h"
]
}
},
{
"name": "//base/hiviewdfx/hiview/base:hiviewbase",
"header": {
"header_base": "//base/hiviewdfx/hiview/base/include",
"header_files": [
"plugin_factory.h",
"event_loop.h",
"plugin.h",
"event.h"
]
}
}
],
"test": [ "//base/hiviewdfx/hiview:hiview_test_package" ]

View File

@ -19,7 +19,6 @@ config("hiview_core_config") {
"include",
"$hiview_root/include",
"$hiview_base/utility/include",
"$hiview_adapter/utility/include",
"//third_party/jsoncpp/include",
]
cflags_cc = [ "-D__HIVIEW_OHOS__" ]
@ -40,7 +39,6 @@ ohos_source_set("hiview_core") {
deps = [
"$hiview_adapter/plugins/eventservice/service:sys_event_service_adapter",
"$hiview_adapter/plugins/eventservice/service/idl:sys_event_service_ohos",
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase",
"platform_config:hiviewplatform_config",
]

View File

@ -33,7 +33,6 @@ ohos_source_set("hiviewplatform_config") {
deps = [
":hiview_platform_config",
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase",
]
}

View File

@ -121,7 +121,6 @@ ohos_unittest("HiviewPlatformConfigTest") {
sources = [ "unittest/common/hiview_platform_config_test.cpp" ]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiview_base",
"$hiview_core:hiview_core",
"../platform_config:hiviewplatform_config",
@ -136,7 +135,7 @@ ohos_unittest("EventServerTest") {
sources = [ "unittest/common/event_server_test.cpp" ]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base/utility:hiview_utility",
"$hiview_plugin/sysevent_source:sysevent_source",
"//third_party/googletest:gtest_main",
]

View File

@ -36,7 +36,6 @@ ohos_fuzztest("EventServiceFuzzTest") {
deps = [
"$hiview_adapter/plugins/eventservice/service/idl:sys_event_service_ohos",
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase_static_lib_for_tdd",
"$hiview_core:hiview_core",
"//third_party/jsoncpp:jsoncpp",

View File

@ -28,7 +28,6 @@ ohos_source_set("eventlogger") {
sources = [ "event_logger.cpp" ]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
"$hiview_plugin/freeze_detector:freeze_detector",
"config:eventlogger_config",

View File

@ -41,7 +41,6 @@ ohos_source_set("eventlogger_config") {
deps = [
":EventloggerPipeline",
":event_logger_config",
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
]
}

View File

@ -41,7 +41,6 @@ ohos_source_set("log_catcher") {
deps = [
"$hiview_adapter/plugins/eventlogger/log_catcher:eventlogger_adapter_logcatcher",
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
"//base/hiviewdfx/hidumper/frameworks/native:hidumperclient",
]

View File

@ -19,7 +19,6 @@ module_output_path = "hiview/hiview/eventlogger/logCatcher"
config("unittest_config") {
include_dirs = [
"../include",
"$hiview_adapter/utility/include",
"unittest/common",
]

View File

@ -20,7 +20,6 @@ config("unittest_config") {
include_dirs = [
"../include",
"../log_catcher/include",
"$hiview_adapter/utility/include",
"unittest/common",
]

View File

@ -26,7 +26,7 @@ ohos_shared_library("faultlogger_napi") {
]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base/utility:hiview_utility",
"$hiview_plugin/faultlogger/interfaces/cpp/innerkits:faultlogger_client_impl",
]
external_deps = [ "napi:ace_napi" ]

View File

@ -66,7 +66,6 @@ ohos_source_set("faultlogger_service") {
deps = [
":faultlogger_service_ability",
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
"$hiview_plugin/faultlogger/common:faultlogger_common",
"$hiview_plugin/faultlogger/common:log_analyzer",

View File

@ -47,8 +47,6 @@ ohos_unittest("FaultloggerUnittest") {
]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase_static_lib_for_tdd",
"$hiview_core:hiview_core",
"$hiview_plugin/faultlogger/common:faultlogger_common",

View File

@ -38,8 +38,6 @@ ohos_fuzztest("FaultloggerServiceFuzzTest") {
]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase_static_lib_for_tdd",
"$hiview_core:hiview_core",
"$hiview_plugin/faultlogger/common:faultlogger_common",

View File

@ -19,7 +19,6 @@ module_output_path = "hiview/hiview/freezedetector"
config("unittest_config") {
include_dirs = [
"./unittest/common/",
"$hiview_adapter/utility/include",
"$hiview_plugin/freeze_detector",
]
@ -54,7 +53,6 @@ ohos_unittest("FreezeDetectorUnittest") {
include_dirs = [
"./unittest/common/",
"$hiview_adapter/utility/include",
"$hiview_plugin/freeze_detector",
"//third_party/libxml2/include",
"//base/hiviewdfx/hiview/base/include",

View File

@ -34,7 +34,6 @@ ohos_source_set("hicollie_collector") {
external_deps = [ "hisysevent:libhisysevent" ]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
"$hiview_root/utility/common_utils:hiview_reliability_common_utils",
]

View File

@ -19,7 +19,6 @@ module_output_path = "hiview/hiview/hicollieCollector"
config("unittest_config") {
include_dirs = [
"./unittest/common/",
"$hiview_adapter/utility/include",
"$hiview_core/",
"$hiview_plugin/hicollie_collector",
]

View File

@ -36,7 +36,6 @@ ohos_source_set("bbox_detector") {
]
deps = [
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
"$hiview_base/event_store:event_store_source",
"$hiview_root/utility/common_utils:hiview_reliability_common_utils",

View File

@ -15,7 +15,10 @@ import("//build/ohos.gni")
config("hiview_core_config") {
visibility = [ "*:*" ]
include_dirs = [ "include" ]
include_dirs = [
"include",
"//third_party/jsoncpp/include",
]
cflags_cc = [ "-D__HIVIEW_OHOS__" ]
}
@ -29,7 +32,6 @@ ohos_source_set("sys_dispatcher") {
deps = [
"$hiview_adapter/plugins/eventservice/service:sys_event_service_adapter",
"$hiview_adapter/plugins/eventservice/service/idl:sys_event_service_ohos",
"$hiview_adapter/system_service:system_service",
"$hiview_base:hiviewbase",
]

View File

@ -39,7 +39,6 @@ if (enable_hiview_usage_event_report_build) {
]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/jsoncpp:jsoncpp",

View File

@ -41,7 +41,6 @@ ohos_executable("usage_report") {
]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base:hiviewbase",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -45,7 +45,7 @@ ohos_unittest("UtilityCommonUtilsTest") {
cflags_cc = [ "-DTEST_LOCAL_SRC" ]
deps = [
"$hiview_adapter/utility:hiview_adapter_utility",
"$hiview_base/utility:hiview_utility",
"$hiview_root/utility/common_utils:hiview_reliability_common_utils",
"//third_party/googletest:gtest_main",
"//third_party/openssl:libcrypto_shared",