xref: /haiku/src/apps/debuganalyzer/gui/main_window/GeneralPage.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "main_window/GeneralPage.h"
7 
8 #include <stdio.h>
9 
10 #include "util/TimeUtils.h"
11 
12 
13 MainWindow::GeneralPage::GeneralPage()
14 	:
15 	AbstractGeneralPage(),
16 	fModel(NULL),
17 	fDataSourceView(NULL),
18 	fCPUCountView(NULL),
19 	fRunTimeView(NULL),
20 	fIdleTimeView(NULL),
21 	fTeamCountView(NULL),
22 	fThreadCountView(NULL)
23 {
24 	fDataSourceView = AddDataView("Data source:");
25 	fCPUCountView = AddDataView("Number of CPUs:");
26 	fRunTimeView = AddDataView("Total time:");
27 	fIdleTimeView = AddDataView("Idle time:");
28 	fTeamCountView = AddDataView("Teams:");
29 	fThreadCountView = AddDataView("Threads:");
30 }
31 
32 
33 MainWindow::GeneralPage::~GeneralPage()
34 {
35 }
36 
37 
38 void
39 MainWindow::GeneralPage::SetModel(Model* model)
40 {
41 	if (model == fModel)
42 		return;
43 
44 	fModel = model;
45 
46 	if (fModel != NULL) {
47 		// data source
48 		fDataSourceView->SetText(fModel->DataSourceName());
49 
50 		// cpu count
51 		char buffer[128];
52 		snprintf(buffer, sizeof(buffer), "%" B_PRId32, fModel->CountCPUs());
53 		fCPUCountView->SetText(buffer);
54 
55 		// run time
56 		nanotime_t runtime = fModel->LastEventTime();
57 		fRunTimeView->SetText(format_nanotime(runtime, buffer, sizeof(buffer)));
58 
59 		// idle time
60 		if (runtime == 0)
61 			runtime = 1;
62 		double idlePercentage = (double)fModel->IdleTime()
63 			/ (runtime * fModel->CountCPUs()) * 100;
64 		char timeBuffer[64];
65 		format_nanotime(fModel->IdleTime(), timeBuffer, sizeof(timeBuffer));
66 		snprintf(buffer, sizeof(buffer), "%s (%.2f %%)", timeBuffer,
67 			idlePercentage);
68 		fIdleTimeView->SetText(buffer);
69 
70 		// team count
71 		snprintf(buffer, sizeof(buffer), "%" B_PRId32, fModel->CountTeams());
72 		fTeamCountView->SetText(buffer);
73 
74 		// threads
75 		snprintf(buffer, sizeof(buffer), "%" B_PRId32, fModel->CountThreads());
76 		fThreadCountView->SetText(buffer);
77 	} else {
78 		fDataSourceView->SetText("");
79 		fCPUCountView->SetText("");
80 		fRunTimeView->SetText("");
81 		fIdleTimeView->SetText("");
82 		fTeamCountView->SetText("");
83 		fThreadCountView->SetText("");
84 	}
85 }
86