Results 1 to 11 of 11

Thread: Qt App Killed After 45 mins

  1. #1
    Join Date
    Jul 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Qt App Killed After 45 mins

    I have written an app that runs on mini2440. I've compiled qt-everywhere-opensource-src-4.6.2 for arm and I'm using that libraries for my app. The problem is, the app runs like 40-45 minutes on arm but then I get 'Killed' message.
    What can be the cause?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt App Killed After 45 mins

    What can be the cause?
    'Killed' might suggest that it was killed by the system (but it doesn't have to be).
    Make sure your application is not leaking, prompting the system to kill it due to it eating the systems resources.
    Or, you have a segmentation fault somewhere in your code.
    Or, any one of infinite other reasons - you should supply more information.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    gokceng (4th August 2011)

  4. #3
    Join Date
    Jul 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qt App Killed After 45 mins

    Thanks for your reply.
    It is most probably about memory management issue. I call repaint function with timer(per 50 ms). I have 4 worker threads that fills 4 separate arrays and after each 50 ms I call repaint to draw the values to the screen. The gui thread works well until 45 minutes passed, then paint function is not called anymore. I'm clearing arrays in paint function so this might be the cause. The arrays causes segmentation fault some way and programs blows up. By the way, commenting out other 3 threads, with 1 working worker thread it takes about 55 minutes program to be killed.

  5. #4
    Join Date
    Jul 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qt App Killed After 45 mins

    I still have this problem. Please help me.

  6. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt App Killed After 45 mins

    By the way, commenting out other 3 threads, with 1 working worker thread it takes about 55 minutes program to be killed.
    My guess is that you have a memory leak somewhere in your thread code, so having just one thread makes the memory usage grows slower (and your app can run slightly longer).
    I still have this problem. Please help me.
    It's impossible without seeing the code.

  7. The following user says thank you to stampede for this useful post:

    gokceng (4th August 2011)

  8. #6
    Join Date
    Jul 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qt App Killed After 45 mins

    I'm posting code, sorry it seems complicated. The work mechanism is like that. I create a serial and updateUIEcg thread. I'm reading from serial, and unpacking that packets. I have a counter in unpacking process and when it reaches to 40 I'm signaling updateUIEcg thread. This thread reads the points from ecg1Vector and ecg2Vector, creates lines. Also I have a timer that calls repaint every 50 ms. In my paintEvent method, I'm drawing lines and clearing line vector. I do not append points to ecg1Vector and ecg2Vector. I'm just setting beatX index to the value as you see. At some point, for example for regarding this code it takes 1 hour, line vector becomes so big and paint event starts to not being called. Until 55 or so mins passed sizes are normal. I mean they rise and down. @55 min, it suddenly grows and after 2-3 minutes program gets killed. The paintEvent method is not called anymore and it is normal that the vectors grow and causes kill. I'm wondering why my timer is not causes paintEvent call.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MainWindow w;
    5. Global::w = &w;
    6. Global::w->showFullScreen();
    7. //Global::w->show();
    8. init();
    9. return a.exec();
    10. }
    11.  
    12. void init()
    13. {
    14. pthread_t serial;
    15. int thrid;
    16. void *t;
    17. thrid = pthread_create(&serial, NULL, &SerialRead, (void *) t);
    18. Global::stigmaECG.updateUIEcgID = pthread_create(&(Global::stigmaECG.updateUIEcgThread), NULL, &updateUIEcg, (void *) Global::stigmaECG.tEcg);
    19. Global::initialize();//I'm initializing integer values etc., no memory related process
    20. }
    21.  
    22. void* SerialRead(void *t)
    23. {
    24. //serial port
    25. StigmaSerialRead::fd = StigmaSerialRead::open_port();
    26. StigmaSerialRead::set_port(StigmaSerialRead::fd);
    27.  
    28. while (1)
    29. {
    30. unsigned char* pack = stigmaSerialRead.SerialRead();
    31. if (pack!=NULL)
    32. {
    33. int check = StigmaSerialUtil::checksum(pack, 8);
    34. if (check == -2 || check == -1)
    35. {
    36. return;
    37. }
    38. unsigned char data_head = pack[1];
    39. unsigned char ecg1_wave_high = pack[2];
    40. unsigned char ecg1_wave_low = pack[3];
    41. unsigned char ecg2_wave_high = pack[4];
    42. unsigned char ecg2_wave_low = pack[5];
    43. unsigned char status = pack[6];
    44.  
    45. if (data_head & 0x01);
    46. else {
    47. ecg1_wave_high &= 0x7F;
    48. }
    49. if (data_head & 0x02);
    50. else {
    51. ecg1_wave_low &= 0x7F;
    52. }
    53. if (data_head & 0x04);
    54. else {
    55. ecg2_wave_high &= 0x7F;
    56. }
    57. if (data_head & 0x08);
    58. else {
    59. ecg2_wave_low &= 0x7F;
    60. }
    61. if (data_head & 0x10);
    62. else {
    63. status &= 0x7F;
    64. }
    65.  
    66. short int temp, mask;
    67. mask = 0xFF00;
    68. temp = 0;
    69.  
    70. temp = ecg1_wave_high;
    71. temp = temp << 8;
    72. temp = temp & mask;
    73. temp += ecg1_wave_low;
    74.  
    75. short int differenceGG = temp - 2048;
    76. pthread_mutex_lock( &(ecg_array_mutex));
    77. ecg1Vector[beatX] = differenceGG;
    78. pthread_mutex_unlock(&(ecg_array_mutex));
    79.  
    80. temp = 0;
    81. temp = ecg2_wave_high;
    82. temp = temp << 8;
    83. temp = temp & mask;
    84. temp += ecg2_wave_low;
    85.  
    86. pthread_mutex_lock( &(ecg_array_mutex));
    87. ecg2Vector[beatX] = temp - 2048;
    88. pthread_mutex_unlock(&(ecg_array_mutex));
    89.  
    90. char mask2 = 0x01;
    91. temp = 0;
    92. temp = status & mask2;
    93. if (temp == 1)
    94. {
    95. printf("\007");
    96. fflush(stdout);
    97. }
    98. mask2 = 0x02;
    99. temp = 0;
    100. temp = status & mask2;
    101.  
    102. if (temp == 1)
    103. {
    104. pacingPulse = 1;
    105. printf("Pacing pulse");
    106. fflush(stdout);
    107. }
    108.  
    109. beatX = (++beatX) % zoommod; //2000
    110. ecgHandlerIndexCounter++;
    111. if(ecgHandlerIndexCounter == 40)
    112. {
    113. ecgHandlerIndexCounter = 0;
    114. pthread_mutex_lock( &(ecg_update_mutex ));
    115. pthread_cond_signal( &(ecg_condition_var));
    116. pthread_mutex_unlock( &(ecg_update_mutex ));
    117. }
    118. internalCounter++;
    119. }
    120. }
    121. close(StigmaSerialRead::fd);
    122. }
    123.  
    124. void* updateUIEcg(void *tEcg)
    125. {
    126. for(;;)
    127. {
    128. pthread_mutex_lock( &(Global::stigmaECG.ecg_update_mutex ));
    129. pthread_cond_wait( &(Global::stigmaECG.ecg_condition_var), &(Global::stigmaECG.ecg_update_mutex));
    130. Global::w->refreshEcgGraphs();
    131. pthread_mutex_unlock( &(Global::stigmaECG.ecg_update_mutex ));
    132. }
    133. }
    134.  
    135. void MainWindow::refreshEcgGraphs()
    136. {
    137. qreal scalex = ui->ecgChannelGraph1->calcScaleX(2000);
    138. qreal scaley = ui->ecgChannelGraph1->calcScaleY();
    139. qreal ty = ui->ecgChannelGraph1->calcTy();
    140. QList<QPointF> ValueList1;
    141. QList<QPointF> ValueList2;
    142.  
    143. int ind = countEcg*40;
    144. for(int i=0;i<40;i++)
    145. {
    146. int sira = (ind + i)%2000;
    147. pthread_mutex_lock( &(Global::stigmaECG.ecg_array_mutex));
    148. double ecg1 = (double)(Global::stigmaECG.ecg1Vector[sira]);
    149. double ecg2 = (double)(Global::stigmaECG.ecg2Vector[sira]);
    150. pthread_mutex_unlock( &(Global::stigmaECG.ecg_array_mutex));
    151.  
    152. qreal orgX = (ind+i)%2000;
    153. qreal xPos = orgX * scalex;
    154. qreal orgY1 = ecg1;
    155. qreal orgY2 = ecg2;
    156. qreal yPos1 = (orgY1 + ty) * scaley;
    157. qreal yPos2 = (orgY2 + ty) * scaley;
    158.  
    159. QPointF *ecg1Point = new QPointF(xPos, -yPos1);
    160. QPointF *ecg2Point = new QPointF(xPos, -yPos2);
    161. ValueList1.append(*ecg1Point);
    162. ValueList2.append(*ecg2Point);
    163. }
    164. ui->ecgChannelGraph1->addPoint(ValueList1, QList<QList<QPointF> >(), "ECG1");
    165. ui->ecgChannelGraph2->addPoint(ValueList2, QList<QList<QPointF> >(), "ECG2");
    166.  
    167. countEcg++;
    168. countEcg = countEcg%(2000/40);
    169. }
    170.  
    171. int QtBasicGraph::addPoint(const QList<QPointF> pointList, QList<QList<QPointF> > gridPointList, char* type)
    172. {
    173. try
    174. {
    175. Mutex.lock();
    176. int size = pointList.size();
    177. QPointF FirstPoint;
    178. if(lines.isEmpty())
    179. FirstPoint = pointList.first();
    180. else
    181. FirstPoint = lines.last().p2();
    182. for (int i = 1 ; i < size; i++)
    183. {
    184. QPointF pt = pointList[i];
    185. lines.append(QLineF(FirstPoint, pt));
    186. FirstPoint = pt;
    187. }
    188. gridLines.clear();
    189. for(int j = 0 ; j<gridPointList.size();j++)
    190. {
    191. QList<QPointF> gridLinePointPair = gridPointList.at(j);
    192. QPointF start = gridLinePointPair.at(0);
    193. QPointF end = gridLinePointPair.at(1);
    194. gridLines.append(QLineF(start, end));
    195. }
    196. Mutex.unlock();
    197. }
    198. catch(char * str)
    199. {
    200. qDebug()<<"error"<<str;
    201. }
    202. }
    203.  
    204. //Repaint called every 50 ms and clearing lines, points
    205. void QtBasicGraph::paintEvent(QPaintEvent *e)
    206. {
    207. QPainter p(this);
    208. if (m_render_hints)
    209. p.setRenderHints(m_render_hints);
    210.  
    211. QVarLengthArray<QLineF> temp;
    212. QVarLengthArray<QLineF> tempGrids;
    213. QVarLengthArray<QLineF> xLinelist;
    214. QVarLengthArray<QLineF> yLinelist;
    215.  
    216. int lineIndex=0;
    217. Mutex.lock();
    218. int lineSize=lines.size();
    219.  
    220. if(lineSize!=0)
    221. {
    222. temp.append(lines[0]);
    223. }
    224. for (lineIndex = 0; lineIndex < lineSize-1; lineIndex++)
    225. {
    226. if(lines[lineIndex].p1().x()<lines[lineIndex+1].p1().x())
    227. {
    228. temp.append(lines[lineIndex+1]);
    229. }
    230. else
    231. {
    232. lines.erase(lines.begin(),lines.begin()+lineIndex+1);
    233. if(temp[lineIndex].p2().x()<temp[lineIndex].p1().x())
    234. {
    235. temp.removeLast();
    236. }
    237. break;
    238. }
    239.  
    240. }
    241. if(lineIndex==lineSize-1)
    242. {
    243. lines.erase(lines.begin(), lines.end()-1);
    244. }
    245.  
    246. for(int i = 0; i<gridLines.size();i++)
    247. {
    248. tempGrids.append(gridLines.at(i));
    249. }
    250. Mutex.unlock();
    251.  
    252. QRectF qrectf(temp[0].p1().x(), 0.0, temp[temp.size()-1].p2().x()-temp[0].p1().x()+clearAfter, yRange());
    253.  
    254. p.fillRect(qrectf, QBrush(Qt::black, Qt::SolidPattern));
    255.  
    256. p.setPen(gridPen);
    257. p.drawLines(tempGrids.constData(), tempGrids.size());
    258. if(temp[0].p1().x()<20)
    259. {
    260. for (int i = 0; i < xLines.size(); ++i)
    261. {
    262. qreal lineEnd=(temp[temp.size()-1].p2().x()+clearAfter) < 20 ? temp[temp.size()-1].p2().x()+clearAfter : 20;
    263. xLinelist.append( QLineF(temp[0].p1().x(),-xLines[i],lineEnd,-xLines[i]));
    264. }
    265. p.drawLines(xLinelist.constData(), xLinelist.size());
    266. }
    267.  
    268. p.setPen(lineColor);
    269. p.drawLines(temp.constData(), temp.size());
    270. temp.clear();
    271. }
    To copy to clipboard, switch view to plain text mode 

  9. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt App Killed After 45 mins

    Qt Code:
    1. QPointF *ecg1Point = new QPointF(xPos, -yPos1);
    2. QPointF *ecg2Point = new QPointF(xPos, -yPos2);
    3. ValueList1.append(*ecg1Point);
    4. ValueList2.append(*ecg2Point);
    To copy to clipboard, switch view to plain text mode 
    This is a memory leak, you never delete ecg1Point and ecg2Point. No need to create them on a heap, this will be enough:
    Qt Code:
    1. ValueList1.append( QPointF(xPos, -yPos1) );
    2. ValueList2.append( QPointF(xPos, -yPos2) );
    To copy to clipboard, switch view to plain text mode 
    There may be more problems in this code, but you should do the dirty work yourself.

  10. The following user says thank you to stampede for this useful post:

    gokceng (15th August 2011)

  11. #8
    Join Date
    Aug 2011
    Location
    East Sussex
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qt App Killed After 45 mins

    1 $ ./yourapp &
    2 $ top
    3 Stare at the %MEM column for 45mins
    4 Job's a good'un

    DaRab

  12. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt App Killed After 45 mins

    to OP:
    Your code is VERY C styled.
    You are using some C++ objects, but your code is C in thought.
    As such it is also very dangerous, as you work a lot with naked pointers and even more dangerous void*.
    It looks that you are using vectors or lists, so at least there use the ::at() instead of operator[] as the '[]' is unsafe (the same as accessing pointer outside bounds).
    It really hurts the eye to read this code, and I bet that at least some of your problems stem from how the code is written.
    Pack it in classes at it should be, make it more defensive (you do not check pointer everywhere for example) and if you are using Qt, use Qt classes , such as QVecotrs, QThread ect.
    This will reduce the chances for errors.
    Then we can look further.
    But to try and debug this even with stepping through a running debugger is madness.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. The following user says thank you to high_flyer for this useful post:

    gokceng (15th August 2011)

  14. #10
    Join Date
    Jul 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qt App Killed After 45 mins

    Thank you high_flyer, DaRabman and stampede.

    @DaRabman: I'm sorry but I couldn't understand step 4: Job's a good'un

    @stampede: Thank you for your valuable advice. I will check and correct similar problems asap.

    @high_flyer:
    I have a very big performance issue. I've started using QT classes wherever possible but then I needed to convert them C++. I couldn't manage to access the speed which I want to. So I've slipped to C. But you are right, correctness must be thought before speed. I will change the code as you said, may the problem solved that way.

    I'll inform you when it is done.

  15. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt App Killed After 45 mins

    Quote Originally Posted by gokceng View Post
    @high_flyer:
    I have a very big performance issue. I've started using QT classes wherever possible but then I needed to convert them C++. I couldn't manage to access the speed which I want to. So I've slipped to C. But you are right, correctness must be thought before speed. I will change the code as you said, may the problem solved that way.
    Switching to a lower-level language will not give you much performance gain. Usually problems such as those come from the fact that the algorithm is suboptimal in its core and improving it gives a bigger boost than anything else. If your app gets killed because the system runs out of memory then probably for some time it swaps like hell which is a performance killer for the whole system. Fix the leaks and then worry about performance.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. App can't be killed?
    By chandantheracer in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd June 2011, 13:50
  2. collect2: ld terminated with signal 9 [Killed]
    By mailtome in forum Installation and Deployment
    Replies: 2
    Last Post: 12th July 2008, 22:57
  3. Why when I close QDialog my main application gets killed?
    By alex chpenst in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 22:57
  4. kdesu in a kprocess - cant be killed
    By soul_rebel in forum KDE Forum
    Replies: 4
    Last Post: 24th March 2006, 23:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.