!203 hidebug内部代码实现更新,host代码告警处理

Merge pull request !203 from jiangyuan0000/master
This commit is contained in:
openharmony_ci 2022-03-30 11:07:41 +00:00 committed by Gitee
commit e01c3aee22
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 46 additions and 56 deletions

View File

@ -26,7 +26,7 @@ config("napi_hidebug_config") {
"//foundation/ace/napi",
"//foundation/ace/napi/native_engine",
"//foundation/ace/napi/interfaces/kits",
"//third_party/musl/include/malloc.h",
"//base/hiviewdfx/hidumper/interfaces/innerkits/include/",
]
}
@ -36,6 +36,7 @@ ohos_shared_library("hidebug") {
configs = [ ":napi_hidebug_config" ]
deps = [
"//base/hiviewdfx/hidumper/interfaces/innerkits:lib_dump_usage",
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
"//foundation/ace/napi:ace_napi",
"//utils/native/base:utils",

View File

@ -36,7 +36,6 @@ static napi_value CreateUndefined(napi_env env);
static napi_value CreateErrorMessage(napi_env env, std::string msg);
static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType);
static std::string GetFileNameParam(napi_env env, napi_callback_info info);
static uint64_t GetProcessMeminfo(const std::string& matchingItem);
static bool GetBundleNameByUid(std::int32_t uid, std::string& bname);
} // HiviewDFX
} // OHOS

View File

@ -18,8 +18,9 @@
#include <cerrno>
#include <fstream>
#include <string>
#include <malloc.h>
#include <memory>
#include <malloc.h>
#include "bundle_manager_helper.h"
#include "directory_ex.h"
#include "file_ex.h"
@ -29,6 +30,7 @@
#include "native_engine/native_engine.h"
#include "securec.h"
#include "unistd.h"
#include "dump_usage.h"
namespace OHOS {
namespace HiviewDFX {
@ -111,80 +113,67 @@ napi_value CreateErrorMessage(napi_env env, std::string msg)
static napi_value GetPss(napi_env env, napi_callback_info info)
{
napi_value pss;
std::string item = "pss";
uint64_t pssInfo = GetProcessMeminfo(item);
napi_create_bigint_uint64(env, pssInfo, &pss);
std::unique_ptr<DumpUsage> dumpUsage = std::make_unique<DumpUsage>();
if (dumpUsage) {
int pid = getpid();
uint64_t pssInfo = dumpUsage->GetPss(pid);
napi_create_bigint_uint64(env, pssInfo, &pss);
} else {
napi_create_bigint_uint64(env, 0, &pss);
}
return pss;
}
static napi_value GetSharedDirty(napi_env env, napi_callback_info info)
{
napi_value share_dirty;
std::string item = "Shared_Dirty";
uint64_t shareDirtyInfo = GetProcessMeminfo(item);
napi_create_bigint_uint64(env, shareDirtyInfo, &share_dirty);
std::unique_ptr<DumpUsage> dumpUsage = std::make_unique<DumpUsage>();
if (dumpUsage) {
int pid = getpid();
uint64_t shareDirtyInfo = dumpUsage->GetSharedDirty(pid);
napi_create_bigint_uint64(env, shareDirtyInfo, &share_dirty);
} else {
napi_create_bigint_uint64(env, 0, &share_dirty);
}
return share_dirty;
}
static napi_value GetNativeHeapSize(napi_env env, napi_callback_info info)
{
struct mallinfo mi;
struct mallinfo mi = mallinfo();
napi_value native_heap_size;
napi_create_bigint_uint64(env, mi.usmblks, &native_heap_size);
if (mi.usmblks >= 0) {
napi_create_bigint_uint64(env, mi.usmblks, &native_heap_size);
} else {
napi_create_bigint_uint64(env, 0, &native_heap_size);
}
return native_heap_size;
}
static napi_value GetNativeHeapAllocatedSize(napi_env env, napi_callback_info info)
{
struct mallinfo mi;
struct mallinfo mi = mallinfo();
napi_value native_heap_allocated_size;
napi_create_bigint_uint64(env, mi.uordblks, &native_heap_allocated_size);
if (mi.uordblks >= 0) {
napi_create_bigint_uint64(env, mi.uordblks, &native_heap_allocated_size);
} else {
napi_create_bigint_uint64(env, 0, &native_heap_allocated_size);
}
return native_heap_allocated_size;
}
static napi_value GetNativeHeapFreeSize(napi_env env, napi_callback_info info)
{
struct mallinfo mi;
struct mallinfo mi = mallinfo();
napi_value native_heap_free_size;
napi_create_bigint_uint64(env, mi.fordblks, &native_heap_free_size);
if (mi.fordblks >= 0) {
napi_create_bigint_uint64(env, mi.fordblks, &native_heap_free_size);
} else {
napi_create_bigint_uint64(env, 0, &native_heap_free_size);
}
return native_heap_free_size;
}
static uint64_t GetProcessMeminfo(const std::string& matchingItem)
{
size_t pid = getpid();
std::string filePath = "/proc/" + std::to_string(pid) + "/smaps_rollup";
FILE* smapsRollupInfo = fopen(filePath.c_str(), "r");
if (smapsRollupInfo == nullptr) {
HiLog::Error(LABEL, "The smaps_rollup file was not found.");
return 0;
}
char line[256];
while (true) {
char* flag = fgets(line, sizeof(line), smapsRollupInfo);
if (flag == nullptr) {
HiLog::Error(LABEL, "The parameter was not found.");
(void)fclose(smapsRollupInfo);
return 0;
}
uint64_t meminfo = 0;
if (matchingItem == "pss") {
if (sscanf_s(line, "Pss: %llu kB", &meminfo) == 1) {
(void)fclose(smapsRollupInfo);
return meminfo;
}
} else if (matchingItem == "Shared_Dirty") {
if (sscanf_s(line, "Shared_Dirty: %llu kB", &meminfo) == 1) {
(void)fclose(smapsRollupInfo);
return meminfo;
}
}
}
(void)fclose(smapsRollupInfo);
return 0;
}
bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType)
{
napi_valuetype valueType = napi_undefined;

View File

@ -333,7 +333,7 @@ public final class HiProfilerClient {
}
/**
* request destory Session
* request destroy Session
*
* @param deviceIp deviceIp
* @param port port number

View File

@ -34,7 +34,7 @@ public class CommonUtil {
}
/**
* Sets the intial collection size.
* Sets the initial collection size.
*
* @param size size
* @return Returns the initial collection size.

View File

@ -59,7 +59,7 @@ public final class FileUtils {
tarArchiveInputStream = new TarArchiveInputStream(new FileInputStream(file));
while (true) {
TarArchiveEntry nextTarEntry = tarArchiveInputStream.getNextTarEntry();
if (Objects.isNull(nextTarEntry)) {
if (Objects.isNull(nextTarEntry) || nextTarEntry.getName().startsWith("../")) {
break;
}
fileNames.add(nextTarEntry.getName());

View File

@ -173,7 +173,7 @@ public class PerfConfig<T> {
}
/**
* set sample peroid
* set sample period
*
* @param period period
*/

View File

@ -395,6 +395,7 @@ public class DistributedTimeShaft extends JBPanel implements KeyListener, MouseL
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setComposite(alpha100);
g2.setColor(JBColor.foreground());
// g2.drawString("CPU Usage", 3, 13);
g2.setComposite(alpha100);
if (startX == 0 && endX == 0) {
startX = 0;

View File

@ -495,7 +495,7 @@ public class TaskScenePanelChart extends JBPanel {
number += LayoutConstants.SIXTY;
numberJlabel += LayoutConstants.INDEX_THREE;
sessionList.add(jLabelRight);
// margin left lable
// margin left label
if (hosJLabel.isOnline()) {
CustomJLabel left = new CustomJLabel("");
left.setOpaque(true);

View File

@ -342,7 +342,7 @@ public class PrefFunc extends AppFunc {
@Override
public List<String> getStringList(String time) {
return Arrays.asList(time, funcName, "Thread:" + threadName, "Tid:" + tid, "depth:" + depth,
"Runing: " + TimeUtils.getTimeWithUnit(dur), "idle:0μs", "Total: " + TimeUtils.getTimeWithUnit(dur));
"Running: " + TimeUtils.getTimeWithUnit(dur), "idle:0μs", "Total: " + TimeUtils.getTimeWithUnit(dur));
}
@Override