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