Add OOM score adjust func
Change-Id: Ic82837d98499f41b0701d6eba55ff9c000362b41
石博文 authored 6 years ago
sbwtw committed 6 years ago
40 | 40 |
a.loadTranslator();
|
41 | 41 |
a.setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
42 | 42 |
a.setTheme("light");
|
|
43 |
#ifdef Q_OS_UNIX
|
|
44 |
a.setOOMScoreAdj(500);
|
|
45 |
#endif
|
43 | 46 |
|
44 | 47 |
if (!a.setSingleInstance("deepin-tool-kit-examples")) {
|
45 | 48 |
qDebug() << "another instance is running!!";
|
336 | 336 |
|
337 | 337 |
d->setTheme(theme);
|
338 | 338 |
}
|
|
339 |
|
|
340 |
#ifdef Q_OS_UNIX
|
|
341 |
/**
|
|
342 |
* @brief DApplication::setOOMScoreAdj set Out-Of-Memory score
|
|
343 |
* @param score vaild range is [-1000, 1000]
|
|
344 |
*/
|
|
345 |
void DApplication::setOOMScoreAdj(const int score)
|
|
346 |
{
|
|
347 |
if (score > 1000 || score < -1000)
|
|
348 |
qWarning() << "OOM score adjustment value out of range: " << score;
|
|
349 |
|
|
350 |
QFile f("/proc/self/oom_score_adj");
|
|
351 |
if (!f.open(QIODevice::WriteOnly))
|
|
352 |
{
|
|
353 |
qWarning() << "OOM score adjust failed, open file error: " << f.errorString();
|
|
354 |
return;
|
|
355 |
}
|
|
356 |
|
|
357 |
f.write(std::to_string(score).c_str());
|
|
358 |
}
|
|
359 |
#endif
|
339 | 360 |
|
340 | 361 |
/**
|
341 | 362 |
* @brief DApplication::setSingleInstance marks this application to be single instanced.
|
54 | 54 |
|
55 | 55 |
QString theme() const;
|
56 | 56 |
void setTheme(const QString &theme);
|
|
57 |
|
|
58 |
#ifdef Q_OS_UNIX
|
|
59 |
void setOOMScoreAdj(const int score);
|
|
60 |
#endif
|
57 | 61 |
|
58 | 62 |
bool setSingleInstance(const QString &key);
|
59 | 63 |
|