From: j-h.choi Date: Tue, 2 Jan 2024 07:52:01 +0000 (+0900) Subject: Add --set-priority option in dotnettool X-Git-Tag: accepted/tizen/unified/20240220.115648~15 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fdotnet%2Flauncher.git;a=commitdiff_plain;h=7a91946e9f06c8779cff7ee84177eea05a5fe111 Add --set-priority option in dotnettool Change-Id: I9d7c0291e24e6be28e6974be360e5c271f9c3c1e --- diff --git a/NativeLauncher/inc/ni_common.h b/NativeLauncher/inc/ni_common.h index c4e6a8f..0493216 100644 --- a/NativeLauncher/inc/ni_common.h +++ b/NativeLauncher/inc/ni_common.h @@ -40,6 +40,7 @@ #define NI_FLAGS_PRINT_CMD 0x0200 #define NI_FLAGS_SKIP_RO_APP 0x0400 #define NI_FLAGS_RM_ORIGIN_AFTER_NI 0x0800 +#define NI_FLAGS_SET_PRIORITY 0x1000 typedef std::function afterCreate; @@ -61,6 +62,7 @@ typedef struct NIOption{ std::vector extraRefPath; std::vector inputBubbleRefFiles; std::vector mibcPath; + int priority; } NIOption; /** @@ -146,4 +148,9 @@ ni_error_e regenerateAppNI(NIOption* opt); */ ni_error_e regenerateTACNI(NIOption* opt); +/** + * @brief Sets the priority of the process to the specified values from -20 to 19.(default : 0) + */ +void setPriority(NIOption* opt); + #endif /* __NI_COMMON_H__ */ diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc index 4343b49..628124c 100644 --- a/NativeLauncher/tool/dotnettool.cc +++ b/NativeLauncher/tool/dotnettool.cc @@ -75,7 +75,9 @@ void DisplayUsage() { " (This option works with --ni-regen-all-app only)\n" " --rm-origin-after-ni - Remove original dll after creating native image\n" " Note!: App ATOC options(--ni-pkg, --ni-regen-all-app, --tac-regen-all) cannot be used with --rm-origin-after-ni option.\n" - " (Use only for assemblies that will not be AOTed again afterward.)" + " (Use only for assemblies that will not be AOTed again afterward.)\n" + " --set-priority - Sets the priority of the process to the specified values from -20(highest priority) to 19(lowest priority).(default : 0)\n" + "\n" "Usage: dotnettool [options] [command] [arguments]\n" "\n" @@ -136,6 +138,23 @@ int main(int argc, char* argv[]) opt->flags |= NI_FLAGS_SKIP_RO_APP; } else if (arg == "--rm-origin-after-ni") { opt->flags |= NI_FLAGS_RM_ORIGIN_AFTER_NI; + } else if (arg == "--set-priority") { + ++i; + if (i >= argc) { + _SOUT("Priority value(-20 ~ 19) should be followed for --set-priority option"); + DisplayUsage(); + return 0; + } + + opt->flags |= NI_FLAGS_SET_PRIORITY; + try { + opt->priority = std::stoi(argv[i]); + setPriority(opt); + } catch (...) { + _SERR("Invalid argument: %s", argv[i]); + DisplayUsage(); + return 0; + } } else if (arg == "--mibc") { ++i; if (i >= argc) { @@ -417,7 +436,9 @@ int main(int argc, char* argv[]) gettimeofday(&tv, NULL); endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; - _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime)); + int ms = (int)(endtime - starttime); + float sec = (float)(ms/1000); + _SOUT("\nSpend time for dotnettool is [%d]ms, [%.3f]sec", ms, sec); return 0; } diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index df98335..7cc1d63 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include @@ -505,6 +507,22 @@ static ni_error_e crossgen2PostAction(const std::string& dllPath, const std::str return NI_ERROR_NONE; } +void setPriority(NIOption* opt) +{ + pid_t pid = getpid(); + if (setpriority(PRIO_PROCESS, pid, opt->priority) == 0) { + std::string str = " "; + if (opt->priority <= -20) { + str = " highest "; + } else if (opt->priority >= 19) { + str = " lowest "; + } + _SOUT("Success to set the%spriority of the process. pid : [%d], priority : [%d]", str.c_str(), pid, getpriority(PRIO_PROCESS, pid)); + } else { + _SERR("Failed to set the priority of the process. pid : [%d], priority : [%d]", pid, getpriority(PRIO_PROCESS, pid)); + } +} + static ni_error_e crossgen2PipeLine(const std::vector& dllList, const std::vector& refPaths, NIOption* opt) { // fork crossgen2 @@ -527,6 +545,9 @@ static ni_error_e crossgen2PipeLine(const std::vector& dllList, con return NI_ERROR_ABNORMAL_PROCESS_TERMINATION; } } else { + if (opt->flags & NI_FLAGS_SET_PRIORITY) { + setPriority(opt); + } std::vector argv; makeArgs(argv, refPaths, opt); argv.push_back(CROSSGEN_OPT_OUT_NEAR_INPUT); @@ -600,6 +621,9 @@ static ni_error_e crossgen2NoPipeLine(const std::vector& dllList, c return NI_ERROR_ABNORMAL_PROCESS_TERMINATION; } } else { + if (opt->flags & NI_FLAGS_SET_PRIORITY) { + setPriority(opt); + } std::vector argv; makeArgs(argv, refPaths, opt);