Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
QHyodaJob.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#include <QHyodaTcp.h>
8#include <QHyodaMachine.h>
9#include "QHyodaPapi.h"
10
11
12/******************************************************************************
13 * STATIC DECLARATIONS
14 *****************************************************************************/
15static double rawStringToDouble(QString);
16static unsigned long long rawStringToULongLong(QString);
17
18
19/******************************************************************************
20 * CONSTRUCTOR
21 *****************************************************************************/
22QHyodaJob::
23QHyodaJob(QHyodaMachine *_machine,int _argc,char *_argv[])
24: machine(_machine)
25, argc(_argc)
26, argv(_argv)
27, id(-1)
28, has_been_broadcasted(false)
29, tcpAdrs(0x100007Ful)
30, tcpPort(3889)
31, tcpPyld(8*1024)
32, iceWidthHeight(0x04000300ul)
33, gdb(new QHyodaGdb(this,machine,0x100007Ful,tcpPort,tcpPyld))
34, gdbserver(new QProcess())
35, tack_toggle(0)
36, data(nullptr)
37, tcp(new QHyodaTcp(this))
38, arcane_variables_names(new QStringList())
39{
40 qDebug() << "\33[36m[QHyodaJob::QHyodaJob] NEW @"<<machine->localHostName<<"\33[m";
41 setupUi(this);
42
43 // Ratio entre la partie gdb et les tools
44 jobSplitter->setSizes(QList<int>()<<128<<1024);
45 // Ratio entre l'output gdbserver, celui de gdb et les common variables d'Arcane
46 gdbSplitter->setSizes(QList<int>()<<128<<1024);
47
48 // Ratio entre les tools elles mêmes
49 toolsSplitter->setSizes(QList<int>()<<512<<256);
50 topToolsSplitter->setSizes(QList<int>()<<512<<512);
51 bottomToolsSplitter->setSizes(QList<int>()<<512<<512);
52
53 topLeftTools->hide(); // Matrix
54 topRightTools->hide(); // IceT mesh
55 bottomLeftTools->hide(); // xterm log
56 bottomRightTools->hide(); // papi,cell
57
58 host=machine->localHostName;
59
60 topLeftTools->setJob(this);
61 topRightTools->setJob(this);
62 bottomLeftTools->setJob(this);
63 bottomRightTools->setJob(this);
64
65 // On prépare les connections
66 connect(tackButton,SIGNAL(clicked()),this,SLOT(tack_slot()));
67 connect(startButton,SIGNAL(clicked()),this,SLOT(start_slot()));
68 connect(stepButton,SIGNAL(clicked()),this,SLOT(step_slot()));
69 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop_slot()));
70
71 connect(matrixButton,SIGNAL(clicked()),this,SLOT(matrix_slot()));
72 connect(logButton,SIGNAL(clicked()),this,SLOT(log_slot()));
73 connect(srcButton,SIGNAL(clicked()),this,SLOT(src_slot()));
74 connect(meshButton,SIGNAL(clicked()),this,SLOT(mesh_slot()));
75 connect(cellButton,SIGNAL(clicked()),this,SLOT(cell_slot()));
76 connect(papiButton,SIGNAL(clicked()),this,SLOT(papi_slot()));
77
78 if ((data=(hyoda_taxi_data*)calloc(1,sizeof(hyoda_taxi_data)))==NULL)
79 qFatal("\33[36m[QHyodaJob::QHyodaJob] Could not allocate data space for hook\33[m");
80
81 // C'est le log slot qui va lancer l'xterm et la commande
82 bottomLeftTools->show();
83 bottomLeftTools->add_log();
84
85 //bottomRightTools->show();bottomRightTools->add_papi();
86 //bottomRightTools->add_cell();
87 //bottomRightTools->add_papi();
88
89 //topRightTools->show();topRightTools->add_mesh();
90
91 //topLeftTools->show();topLeftTools->add_matrix();
92}
93
94
95
96/******************************************************************************
97 * QHyodaJob::~QHyodaJob
98 *****************************************************************************/
99QHyodaJob::~QHyodaJob(void){
100 qDebug() << "\33[36m[QHyodaJob::~QHyodaJob] DELETE\33[m";
101 delete tcp;
102 delete gdb;
103 delete gdbserver;
104 delete arcane_variables_names;
105 free(data);
106}
107
108
109/******************************************************************************
110 * GDBSERVER process
111 *****************************************************************************/
112void QHyodaJob::gdbserver_hook(void){
113 gdbServerGroupBox->setEnabled(true);
114 qDebug() << "\33[36m[QHyodaJob::gdbserver_hook] #### LOCAL gdbserver ####\33[m";
115 //QString command("/usr/local/bin/gdbserver");
116 QString command("/usr/bin/gdbserver");
117 QStringList args = QStringList() << "--attach"
118 << ":3883"
119 << pid;
120 gdbserver->setProcessChannelMode(QProcess::MergedChannels);
121 connect(gdbserver,SIGNAL(readyReadStandardOutput()),this,SLOT(gdbserver_slot()));
122 gdbserver->start(command, args);
123 if (!gdbserver->waitForStarted())
124 qFatal("\33[36m[QHyodaJob::gdbserver_hook] NOT started!\33[m");
125}
126
127
128
129/******************************************************************************
130 * GDB SERVER process
131 * C'est ici qu'on lance le gdbserver coté rank0
132 *****************************************************************************/
133void QHyodaJob::gdbserver_slot(void){
134 QString output=QString(gdbserver->readAllStandardOutput());
135 //qDebug() << "\33[36m[QHyodaJob::gdbserver_slot] output="<<output<<"\33[m";
136 if (output.endsWith('\n'))
137 output.replace(output.length()-1,1,' ');
138 gdbServerTextEdit->append(output);
139 if (output.contains("Listening")){
140 qDebug() << "\33[33m[QHyodaJob::gdbserver_slot] Launching gdb_hook\33[m";
141 gdb_hook();
142 }
143}
144
145/******************************************************************************
146 * GDB process
147 * C'est ici qu'on setup les breapoints avec lesquels nous allons jouer
148 *****************************************************************************/
149void QHyodaJob::gdb_hook(void){
150 gdb->cmdline=(has_been_broadcasted==true)?broadcasted_cmdline:cmdline;
151 qDebug() << "\33[36m[QHyodaJob::gdb_hook] Now launching\33[m";
152 gdb->launch();
153 gdbGroupBox->setEnabled(true);
154 jobButtons->setEnabled(true);
155}
156
157/******************************************************************************
158 * TOOLBAR SLOTS
159 *****************************************************************************/
160void QHyodaJob::stop_slot(void){
161 gdb->state=QHyodaGdb::Interrupt;
162 startButton->setEnabled(true);
163 stepButton->setEnabled(true);
164}
165
166void QHyodaJob::step_slot(void){
167 stepButton->setEnabled(false);
168 startButton->setEnabled(false);
169 tackButton->setEnabled(false);
170 if (gdb->state!=QHyodaGdb::Step)
171 gdb->state=QHyodaGdb::Step;
172 else
173 gdb->enqueue("-exec-continue");
174}
175
176void QHyodaJob::start_slot(void){
177 gdb->state=QHyodaGdb::Continue;
178 gdb->enqueue("-break-disable 3"); // On enlève le softbreak
179 gdb->enqueue("-break-disable 4"); // On enlève les entryPoints
180 gdb->enqueue("-exec-continue");
181 tackButton->setEnabled(true);
182 startButton->setEnabled(false);
183}
184
185void QHyodaJob::tack_slot(void){
186 tack_toggle=(tack_toggle+1)%2;
187 if (tack_toggle!=0){
188 gdb->state=QHyodaGdb::Untack;
189 arcaneCommonVariablesGroupBox->setEnabled(false);
190 //gdbInputLineEdit->setEnabled(false);
191 stopButton->setEnabled(false);
192 stepButton->setEnabled(false);
193 }else{
194 gdb->state=QHyodaGdb::Retack;
195 gdb->enqueue("-exec-interrupt");
196 arcaneCommonVariablesGroupBox->setEnabled(true);
197 //gdbInputLineEdit->setEnabled(true);
198 stopButton->setEnabled(true);
199 stepButton->setEnabled(true);
200 }
201}
202
203
204
205void QHyodaJob::log_slot(void){
206 //qDebug() << "\33[36m[QHyodaJob::log_slot]\33[m";
207 if (bottomLeftTools->isHidden())
208 bottomLeftTools->show();
209 else
210 bottomLeftTools->hide();
211}
212void QHyodaJob::cell_slot(void){
213 qDebug() << "\33[36m[QHyodaJob::cell_slot]\33[m";
214 if (!bottomRightTools->cell) bottomRightTools->add_cell();
215 bottomRightTools->show();
216 //if (bottomRightTools->isHidden()) bottomRightTools->show(); else bottomRightTools->hide();
217}
218
219void QHyodaJob::mesh_slot(void){
220 qDebug() << "\33[36m[QHyodaJob::mesh_slot]\33[m";
221 if (!topRightTools->mesh) topRightTools->add_mesh();
222 if (topRightTools->isHidden()) topRightTools->show();
223 else topRightTools->hide();
224}
225
226void QHyodaJob::src_slot(void){
227 qDebug() << "\33[36m[QHyodaJob::src_slot]\33[m";
228 topLeftTools->show();
229 topLeftTools->add_src();
230}
231
232void QHyodaJob::matrix_slot(void){
233 qDebug() << "\33[36m[QHyodaJob::matrix_slot]\33[m";
234 topLeftTools->show();
235 topLeftTools->add_matrix();
236}
237
238void QHyodaJob::papi_slot(void){
239 if (!bottomRightTools->papi) bottomRightTools->add_papi();
240 if (bottomRightTools->isHidden()) bottomRightTools->show();
241 else bottomRightTools->hide();
242}
243
244
249 qDebug() << "\33[36m[QHyodaJob::detach] Queuing Detach and interrupting job\33[m";
250 gdb->state=QHyodaGdb::Detach;
251 gdb->enqueue("-exec-interrupt");
252}
253
254
259 qDebug() << "\33[36m[QHyodaJob::quit]\33[m";
260 gdb->process->close();
261 if (gdb->process->state()!=QProcess::NotRunning)
262 qDebug() << "\33[36m[QHyodaJob::quit] GDB NOT closed\33[m";
263 else
264 qDebug() << "\33[36m[QHyodaJob::quit] GDB closed\33[m";
265
266 gdbserver->close();
267 if (gdbserver->state()!=QProcess::NotRunning)
268 qDebug() << "\33[36m[QHyodaJob::quit] GDBSERVER NOT closed\33[m";
269 else
270 qDebug() << "\33[36m[QHyodaJob::quit] GDBSERVER closed\33[m";
271
272 this->close();
273 machine->hyoda->quit();
274}
275
276
277/******************************************************************************
278 * REFRESH'MENTS
279 *****************************************************************************/
280void QHyodaJob::refresh_common_variables(const QStringList &splitted_output){
281 //qDebug() << "QHyodaJob::jobid_read_gdb splitted_output="<<splitted_output;
282
283 quint64 global_iteration=rawStringToULongLong(splitted_output.at(17));
284 globalIterationLine->setText(QString("%1").arg(global_iteration));
285
286 double global_time=rawStringToDouble(splitted_output.at(19));
287 globalTimeLine->setText(QString("%1").arg(global_time));
288
289 double global_deltat=rawStringToDouble(splitted_output.at(21));
290 globalDeltaTLine->setText(QString("%1").arg(global_deltat));
291
292 double global_cpu_time=rawStringToDouble(splitted_output.at(23));
293 globalCPUTimeLine->setText(QString("%1").arg(global_cpu_time));
294
295 quint64 mesh_total_nb_cell=rawStringToULongLong(splitted_output.at(25));
296 if (mesh_total_nb_cell!=data->mesh_total_nb_cell){
297 data->mesh_total_nb_cell=mesh_total_nb_cell;
298 //qDebug() << "QHyodaJob::refresh_common_variables new mesh_total_nb_cell="<<mesh_total_nb_cell;
299 }
300 unsigned long long got_target_cell_nb_nodes=rawStringToULongLong(splitted_output.at(31));
301}
302
303
304
305
306
307
308/******************************************************************************
309 * STATIC TOOLS
310 *****************************************************************************/
311static double rawStringToDouble(QString qStr){
312 const char *s=qStr.toLocal8Bit().constData();
313 double ret=0.;
314 sscanf(s, "%llx", (unsigned long long *)&ret);
315 return ret;
316}
317
318static unsigned long long rawStringToULongLong(QString qStr){
319 const char *s=qStr.toLocal8Bit().constData();
320 unsigned long long ret=0;
321 sscanf(s, "%llx", &ret);
322 return ret;
323}
324
void quit()
Definition QHyodaJob.cc:258
void detach()
Definition QHyodaJob.cc:248