1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "thread_window/GeneralPage.h" 7 8 #include <stdio.h> 9 10 #include "util/TimeUtils.h" 11 12 13 ThreadWindow::GeneralPage::GeneralPage() 14 : 15 AbstractGeneralPage(), 16 fModel(NULL), 17 fThread(NULL), 18 fThreadNameView(NULL), 19 fThreadIDView(NULL), 20 fTeamView(NULL), 21 fRunTimeView(NULL), 22 fWaitTimeView(NULL), 23 fLatencyView(NULL), 24 fPreemptionView(NULL), 25 fUnspecifiedTimeView(NULL) 26 { 27 fThreadNameView = AddDataView("Name:"); 28 fThreadIDView = AddDataView("ID:"); 29 fTeamView = AddDataView("Team:"); 30 fRunTimeView = AddDataView("Run time:"); 31 fWaitTimeView = AddDataView("Wait time:"); 32 fLatencyView = AddDataView("Latencies:"); 33 fPreemptionView = AddDataView("Preemptions:"); 34 fUnspecifiedTimeView = AddDataView("Unspecified time:"); 35 } 36 37 38 ThreadWindow::GeneralPage::~GeneralPage() 39 { 40 } 41 42 43 void 44 ThreadWindow::GeneralPage::SetModel(Model* model, Model::Thread* thread) 45 { 46 if (model == fModel && thread == fThread) 47 return; 48 49 fModel = model; 50 fThread = thread; 51 52 if (fThread != NULL) { 53 // name 54 fThreadNameView->SetText(fThread->Name()); 55 56 // ID 57 char buffer[128]; 58 snprintf(buffer, sizeof(buffer), "%" B_PRId32, fThread->ID()); 59 fThreadIDView->SetText(buffer); 60 61 // team 62 fTeamView->SetText(thread->GetTeam()->Name()); 63 64 // run time 65 char timeBuffer[64]; 66 format_nanotime(fThread->TotalRunTime(), timeBuffer, 67 sizeof(timeBuffer)); 68 snprintf(buffer, sizeof(buffer), "%s (%" B_PRId64 ")", timeBuffer, 69 fThread->Runs()); 70 fRunTimeView->SetText(buffer); 71 72 // wait time 73 format_nanotime(fThread->TotalWaitTime(), timeBuffer, 74 sizeof(timeBuffer)); 75 snprintf(buffer, sizeof(buffer), "%s (%" B_PRId64 ")", timeBuffer, 76 fThread->Waits()); 77 fWaitTimeView->SetText(buffer); 78 79 // latencies 80 format_nanotime(fThread->TotalLatency(), timeBuffer, 81 sizeof(timeBuffer)); 82 snprintf(buffer, sizeof(buffer), "%s (%" B_PRId64 ")", timeBuffer, 83 fThread->Latencies()); 84 fLatencyView->SetText(buffer); 85 86 // preemptions 87 format_nanotime(fThread->TotalRerunTime(), timeBuffer, 88 sizeof(timeBuffer)); 89 snprintf(buffer, sizeof(buffer), "%s (%" B_PRId64 ")", timeBuffer, 90 fThread->Preemptions()); 91 fPreemptionView->SetText(buffer); 92 93 // unspecified time 94 format_nanotime(fThread->UnspecifiedWaitTime(), timeBuffer, 95 sizeof(timeBuffer)); 96 fUnspecifiedTimeView->SetText(timeBuffer); 97 } else { 98 fThreadNameView->SetText(""); 99 fThreadIDView->SetText(""); 100 fTeamView->SetText(""); 101 fRunTimeView->SetText(""); 102 fWaitTimeView->SetText(""); 103 fLatencyView->SetText(""); 104 fPreemptionView->SetText(""); 105 fUnspecifiedTimeView->SetText(""); 106 } 107 } 108