diff --git a/hidebug/interfaces/js/kits/napi/BUILD.gn b/hidebug/interfaces/js/kits/napi/BUILD.gn index b113a213e..74e057aa8 100644 --- a/hidebug/interfaces/js/kits/napi/BUILD.gn +++ b/hidebug/interfaces/js/kits/napi/BUILD.gn @@ -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", diff --git a/hidebug/interfaces/js/kits/napi/include/napi_hidebug.h b/hidebug/interfaces/js/kits/napi/include/napi_hidebug.h index 6d9439d12..7a33d4b06 100644 --- a/hidebug/interfaces/js/kits/napi/include/napi_hidebug.h +++ b/hidebug/interfaces/js/kits/napi/include/napi_hidebug.h @@ -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 diff --git a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp index 55f32dbc6..14387a9a2 100644 --- a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp +++ b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp @@ -18,8 +18,9 @@ #include #include #include -#include +#include +#include #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 = std::make_unique(); + 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 = std::make_unique(); + 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; diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/transport/grpc/HiProfilerClient.java b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/transport/grpc/HiProfilerClient.java index 29f0d2206..49f168618 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/transport/grpc/HiProfilerClient.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/transport/grpc/HiProfilerClient.java @@ -333,7 +333,7 @@ public final class HiProfilerClient { } /** - * request destory Session + * request destroy Session * * @param deviceIp deviceIp * @param port port number diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/CommonUtil.java b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/CommonUtil.java index 06e6b57fe..e81869a69 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/CommonUtil.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/CommonUtil.java @@ -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. diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/FileUtils.java b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/FileUtils.java index 7cc9d06ea..e3a0735b5 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/FileUtils.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/common/util/FileUtils.java @@ -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()); diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/monitorconfig/entity/PerfConfig.java b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/monitorconfig/entity/PerfConfig.java index 97efddd6f..9d836e83a 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/monitorconfig/entity/PerfConfig.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/datasources/utils/monitorconfig/entity/PerfConfig.java @@ -173,7 +173,7 @@ public class PerfConfig { } /** - * set sample peroid + * set sample period * * @param period period */ diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/views/distributed/component/DistributedTimeShaft.java b/host/ohosprofiler/src/main/java/ohos/devtools/views/distributed/component/DistributedTimeShaft.java index 4df6bbf4b..f0d9f33e5 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/views/distributed/component/DistributedTimeShaft.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/views/distributed/component/DistributedTimeShaft.java @@ -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; diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/views/layout/chartview/TaskScenePanelChart.java b/host/ohosprofiler/src/main/java/ohos/devtools/views/layout/chartview/TaskScenePanelChart.java index 1049c9281..ca639a2f7 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/views/layout/chartview/TaskScenePanelChart.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/views/layout/chartview/TaskScenePanelChart.java @@ -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); diff --git a/host/ohosprofiler/src/main/java/ohos/devtools/views/perftrace/bean/PrefFunc.java b/host/ohosprofiler/src/main/java/ohos/devtools/views/perftrace/bean/PrefFunc.java index 6a0025968..385520737 100644 --- a/host/ohosprofiler/src/main/java/ohos/devtools/views/perftrace/bean/PrefFunc.java +++ b/host/ohosprofiler/src/main/java/ohos/devtools/views/perftrace/bean/PrefFunc.java @@ -342,7 +342,7 @@ public class PrefFunc extends AppFunc { @Override public List 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