Skip to content

Commit 4691773

Browse files
committed
Signed-off-by: Palash Das <[email protected]>
1 parent 703e8c2 commit 4691773

File tree

12 files changed

+480
-76
lines changed

12 files changed

+480
-76
lines changed

MainWindow.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

MainWindow.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

MainWindow.ui

Lines changed: 0 additions & 21 deletions
This file was deleted.

build_android/QtApp-debug.apk

7.36 MB
Binary file not shown.

build_win32/ADB_Task_Manager.exe

49.5 KB
Binary file not shown.
1.17 MB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ TARGET = ADB_Task_Manager
1212
TEMPLATE = app
1313

1414

15+
QMAKE_CXXFLAGS += -std=c++1y
16+
QMAKE_LFLAGS += -shared-libgcc
17+
18+
CONFIG += C++1y
19+
QMAKE_LINK += -shared-libgcc
20+
1521
SOURCES += main.cpp\
1622
MainWindow.cpp
1723

Lines changed: 174 additions & 19 deletions
Large diffs are not rendered by default.

src/MainWindow.cpp

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#include "MainWindow.h"
2+
#include "ui_MainWindow.h"
3+
4+
int threads=0;
5+
thread_local int tid=++threads;
6+
7+
#define g qDebug()<<"\nDebug["<<tid<<"] @ "<<" #"<<__LINE__<<"\t"<<__PRETTY_FUNCTION__ ;
8+
9+
10+
11+
12+
void setDataset(QTableWidget *tb,auto &&ll)
13+
{
14+
tb->setRowCount(0);
15+
for(auto &cells:ll)
16+
{
17+
tb->insertRow(tb->rowCount());
18+
int j=0;
19+
for(auto &cl:cells)
20+
tb->setItem(tb->rowCount()-1,j++, new QTableWidgetItem(cl));
21+
}
22+
}
23+
24+
25+
26+
MainWindow::MainWindow(QWidget *parent) :
27+
QMainWindow(parent),
28+
ui(new Ui::MainWindow)
29+
{
30+
ui->setupUi(this);
31+
32+
running=1;
33+
mode=-1;
34+
m_nop=ui->nop->value();
35+
m_del=ui->del->value();
36+
37+
auto &&header=tr(" PID PR CPU% S #THR VSS RSS PCY UID Name")
38+
.split(QRegExp("\\s+"),QString::SkipEmptyParts);
39+
qDebug()<<header;
40+
ui->tableWidget->setColumnCount(header.size());
41+
ui->tableWidget->setHorizontalHeaderLabels(header);
42+
43+
g
44+
ipc=std::thread ([&]
45+
{
46+
while(running)
47+
{
48+
if(mode==-1)
49+
{
50+
mode=0;
51+
ll.clear();
52+
stringstream cmd;
53+
#ifdef Q_OS_WIN32
54+
cmd<<"adb shell ";
55+
#endif
56+
cmd<<"top "<<" -m "<<m_nop<<" -d "<<m_del;
57+
58+
// QProcess::execute("taskkill /IM adb.exe /F");
59+
qtop=make_shared<QProcess>();
60+
this_thread::yield();
61+
qtop->start(tr(cmd.str().data()));
62+
qtop->waitForStarted();
63+
qDebug()<<qtop->state()<<":"<<cmd.str().data();
64+
65+
}
66+
67+
68+
QString ln;
69+
{
70+
if(not qtop->canReadLine())
71+
qtop->waitForReadyRead();
72+
73+
if(mode==-1 or qtop->state()!= QProcess::Running)
74+
continue;
75+
unique_lock<mutex> lg(mt);
76+
ln=qtop->readLine();
77+
}
78+
bool isBlank=ln.trimmed().isEmpty();
79+
// qDebug()<<ln<<" vs "<<isBlank;
80+
// qDebug()<<"Mode begin :"<<mode;
81+
82+
switch(mode)
83+
{
84+
case 0 :
85+
if(not isBlank)
86+
mode=(mode+1)%4;
87+
else
88+
break;
89+
case 1 :
90+
bl=ln;
91+
mode=(mode+1)%4;
92+
break;
93+
case 2 :
94+
95+
if(ln.contains("PID"))
96+
mode=(mode+1)%4;
97+
break;
98+
case 3 :
99+
auto &&row=ln.split(QRegExp("\\s+"),QString::SkipEmptyParts);
100+
if(row.size()<10)
101+
row.insert(7,"NA");
102+
// if(not isBlank)
103+
ll.push_back(row);
104+
// else
105+
if(ll.size()==m_nop)
106+
{
107+
mode=(mode+1)%4;
108+
QMetaObject::invokeMethod(ui->tableWidget,"cellActivated",
109+
Qt::QueuedConnection,Q_ARG(int,-1),Q_ARG(int,-1));
110+
111+
sem.acquire();
112+
ll.clear();
113+
}
114+
}
115+
// qDebug()<<"Mode End :"<<mode;
116+
}
117+
});
118+
119+
}
120+
121+
122+
MainWindow::~MainWindow()
123+
{
124+
running=0;
125+
mode=-1;
126+
sem.release(sem.available());
127+
unique_lock<mutex> lg(mt);
128+
qtop->kill();
129+
if(ipc.joinable())
130+
ipc.join();
131+
delete ui;
132+
}
133+
134+
void MainWindow::restarttopProc()
135+
{
136+
sem.release(sem.available());
137+
mode=-1;
138+
unique_lock<mutex> lg(mt);
139+
if(qtop.get())
140+
qtop->kill();
141+
}
142+
143+
void MainWindow::on_tableWidget_cellActivated(int row, int column)
144+
{
145+
if(row < 0 and column < 0 and running)
146+
{
147+
setDataset(ui->tableWidget,ll);
148+
149+
150+
ui->tableWidget->resizeColumnsToContents();
151+
ui->tableWidget->resizeRowsToContents();
152+
ui->statusBar->showMessage(bl);
153+
sem.release();
154+
}
155+
}
156+
157+

src/MainWindow.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
6+
#include <QDebug>
7+
8+
#include <iostream>
9+
#include <sstream>
10+
#include <atomic>
11+
#include <mutex>
12+
#include <thread>
13+
14+
#include <QProcess>
15+
#include <QSemaphore>
16+
17+
using namespace std;
18+
namespace Ui {
19+
class MainWindow;
20+
}
21+
22+
class MainWindow : public QMainWindow
23+
{
24+
Q_OBJECT
25+
26+
public:
27+
explicit MainWindow(QWidget *parent = 0);
28+
~MainWindow();
29+
30+
int m_nop,m_del;
31+
std::thread ipc;
32+
std::mutex mt;
33+
atomic<int> running,mode;
34+
shared_ptr<QProcess> qtop=NULL;
35+
36+
QList<QStringList> ll;
37+
QSemaphore sem;
38+
QString bl;
39+
40+
void restarttopProc();
41+
private slots:
42+
void on_tableWidget_cellActivated(int row, int column);
43+
44+
void on_del_valueChanged(int arg1){ m_del=arg1; restarttopProc(); }
45+
void on_nop_valueChanged(int arg1){ m_nop=arg1; restarttopProc(); }
46+
47+
private:
48+
Ui::MainWindow *ui;
49+
};
50+
51+
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)