1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2008 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18
#if defined(__GNUG__) && !defined(__APPLE__)
19
#pragma implementation "DlgItemProperties.h"
24
#include "DlgItemProperties.h"
25
#include "BOINCGUIApp.h"
26
#include "BOINCBaseFrame.h"
28
#include "error_numbers.h"
30
IMPLEMENT_DYNAMIC_CLASS(CDlgItemProperties, wxDialog)
32
BEGIN_EVENT_TABLE(CDlgItemProperties, wxDialog)
37
CDlgItemProperties::CDlgItemProperties(wxWindow* parent) :
38
wxDialog( parent, ID_ANYDIALOG, wxEmptyString, wxDefaultPosition,
39
wxSize( 503,480 ), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ) {
40
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
44
SetSizeHints( wxDefaultSize, wxDefaultSize );
45
SetExtraStyle( GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY );
47
m_bSizer1 = new wxBoxSizer( wxVERTICAL );
49
m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
50
m_scrolledWindow->SetScrollRate( 5, 5 );
51
wxBoxSizer* m_bSizer2;
52
m_bSizer2 = new wxBoxSizer( wxVERTICAL );
54
m_gbSizer = new wxGridBagSizer( 0, 0 );
55
m_gbSizer->AddGrowableCol( 1 );
56
m_gbSizer->SetFlexibleDirection( wxBOTH );
57
m_gbSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
59
m_bSizer2->Add( m_gbSizer, 1, wxEXPAND, 5 );
61
m_scrolledWindow->SetSizer( m_bSizer2 );
62
m_scrolledWindow->Layout();
63
m_bSizer2->Fit( m_scrolledWindow );
64
m_bSizer1->Add( m_scrolledWindow, 1, wxEXPAND | wxALL, 5 );
66
m_btnClose = new wxButton( this, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
67
m_btnClose->SetDefault();
68
m_bSizer1->Add( m_btnClose, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
70
SetSizer( m_bSizer1 );
77
int currentTabView = pFrame->GetCurrentViewPage();
78
switch(currentTabView) {
80
m_strBaseConfigLocation = wxString(wxT("/DlgProjectProperties/"));
83
m_strBaseConfigLocation = wxString(wxT("/DlgTaskProperties/"));
86
m_strBaseConfigLocation = wxString(wxT("/DlgProperties/"));
94
CDlgItemProperties::~CDlgItemProperties() {
98
/* saves dialog size and (on Mac) position */
99
bool CDlgItemProperties::SaveState() {
100
wxConfigBase* pConfig = wxConfigBase::Get(FALSE);
103
if (!pConfig) return false;
105
pConfig->SetPath(m_strBaseConfigLocation);
106
pConfig->Write(wxT("Width"), GetSize().GetWidth());
107
pConfig->Write(wxT("Height"), GetSize().GetHeight());
109
pConfig->Write(wxT("XPos"), GetPosition().x);
110
pConfig->Write(wxT("YPos"), GetPosition().y);
115
/* restores former dialog size and (on Mac) position */
116
bool CDlgItemProperties::RestoreState() {
117
wxConfigBase* pConfig = wxConfigBase::Get(FALSE);
121
if (!pConfig) return false;
123
pConfig->SetPath(m_strBaseConfigLocation);
125
pConfig->Read(wxT("Width"), &iWidth, wxDefaultCoord);
126
pConfig->Read(wxT("Height"), &iHeight, wxDefaultCoord);
129
// Set size to saved values or defaults if no saved values
130
SetSize(iWidth, iHeight);
134
pConfig->Read(wxT("YPos"), &iTop, wxDefaultCoord);
135
pConfig->Read(wxT("XPos"), &iLeft, wxDefaultCoord);
137
// If either co-ordinate is less then 0 then set it equal to 0 to ensure
138
// it displays on the screen.
139
if ((iLeft < 0) && (iLeft != wxDefaultCoord)) iLeft = 30;
140
if ((iTop < 0) && (iTop != wxDefaultCoord)) iTop = 30;
142
// Set size and position to saved values or defaults if no saved values
143
SetSize(iLeft, iTop, iWidth, iHeight, wxSIZE_USE_EXISTING);
145
// Now make sure window is on screen
146
GetScreenPosition(&iLeft, &iTop);
147
GetSize(&iWidth, &iHeight);
149
Rect titleRect = {iTop, iLeft, iTop+22, iLeft+iWidth };
150
InsetRect(&titleRect, 5, 5); // Make sure at least a 5X5 piece visible
151
RgnHandle displayRgn = NewRgn();
152
CopyRgn(GetGrayRgn(), displayRgn); // Region encompassing all displays
153
Rect menuRect = ((**GetMainDevice())).gdRect;
154
menuRect.bottom = GetMBarHeight() + menuRect.top;
155
RgnHandle menuRgn = NewRgn();
156
RectRgn(menuRgn, &menuRect); // Region hidden by menu bar
157
DiffRgn(displayRgn, menuRgn, displayRgn); // Subtract menu bar region
158
if (!RectInRgn(&titleRect, displayRgn)) {
160
SetSize(iLeft, iTop, iWidth, iHeight, wxSIZE_USE_EXISTING);
163
DisposeRgn(displayRgn);
168
// show project properties
170
void CDlgItemProperties::renderInfos(PROJECT* project_in) {
171
std::string projectname;
173
project_in->get_name(projectname);
174
//disk usage needs additional lookups
175
CMainDocument* pDoc = wxGetApp().GetDocument();
176
pDoc->CachedDiskUsageUpdate();
178
// CachedDiskUsageUpdate() may have invalidated our project
179
// pointer, so get an updated pointer to this project
180
PROJECT* project = pDoc->project(project_in->master_url);
181
if(!project) return; // TODO: display some sort of error alert?
183
std::vector<PROJECT*> dp = pDoc->disk_usage.projects;
184
double diskusage=0.0;
185
for (unsigned int i=0; i< dp.size(); i++) {
189
wxString t1(wxString(tname.c_str(),wxConvUTF8));
190
if(t1.IsSameAs(wxString(projectname.c_str(),wxConvUTF8)) || t1.IsSameAs(wxString(project->master_url, wxConvUTF8))) {
191
diskusage =tp->disk_usage;
196
wxString wxTitle = _("Properties of project ");
197
wxTitle.append(wxString(projectname.c_str(),wxConvUTF8));
200
addSection(_("General"));
201
addProperty(_("Master URL"),wxString(project->master_url, wxConvUTF8));
202
addProperty(_("User name"),wxString(project->user_name.c_str(),wxConvUTF8));
203
addProperty(_("Team name"),wxString(project->team_name.c_str(),wxConvUTF8));
204
addProperty(_("Resource share"),wxString::Format(wxT("%0.0f"),project->resource_share));
205
if (project->min_rpc_time > dtime()) {
206
addProperty(_("Scheduler RPC deferred for"), FormatTime(project->min_rpc_time - dtime()));
208
if (project->download_backoff) {
209
addProperty(_("File downloads deferred for"), FormatTime(project->download_backoff));
211
if (project->upload_backoff) {
212
addProperty(_("File uploads deferred for"), FormatTime(project->upload_backoff));
214
addProperty(_("Disk usage"),FormatDiskSpace(diskusage));
215
addProperty(_("Computer ID"), wxString::Format(wxT("%d"), project->hostid));
216
addProperty(_("Non CPU intensive"),project->non_cpu_intensive ? _("yes") : _("no"));
217
addProperty(_("Suspended via GUI"),project->suspended_via_gui ? _("yes") : _("no"));
218
addProperty(_("Don't request more work"),project->dont_request_more_work ? _("yes") : _("no"));
219
addProperty(_("Scheduler call in progress"),project->scheduler_rpc_in_progress ? _("yes") : _("no"));
220
addProperty(_("Added via account manager"),project->attached_via_acct_mgr ? _("yes") : _("no"));
221
addProperty(_("Remove when tasks done"),project->detach_when_done ? _("yes") : _("no"));
222
addProperty(_("Ended"),project->ended ? _("yes") : _("no"));
223
addSection(_("Credit"));
224
addProperty(_("User"),
226
wxT("%0.2f total, %0.2f average"),
227
project->user_total_credit,
228
project->user_expavg_credit
231
addProperty(_("Host"),
233
wxT("%0.2f total, %0.2f average"),
234
project->host_total_credit,
235
project->host_expavg_credit
239
if (!project->non_cpu_intensive) {
240
addSection(_("Scheduling"));
241
if (project->no_cpu_pref) {
242
addProperty(_("Project preference"), _("Don't fetch CPU tasks"));
244
addProperty(_("CPU scheduling priority"),wxString::Format(wxT("%0.2f"), project->cpu_short_term_debt));
245
addProperty(_("CPU work fetch priority"),wxString::Format(wxT("%0.2f"), project->cpu_long_term_debt));
246
double x = project->cpu_backoff_time - dtime();
248
addProperty(_("CPU work fetch deferred for"), FormatTime(x));
249
addProperty(_("CPU work fetch deferral interval"), FormatTime(project->cpu_backoff_interval));
250
if (pDoc->state.have_cuda) {
251
if (project->no_cuda_pref) {
252
addProperty(_("Project preference"), _("Don't fetch NVIDIA GPU tasks"));
254
addProperty(_("NVIDIA GPU scheduling priority"),wxString::Format(wxT("%0.2f"), project->cuda_short_term_debt));
255
addProperty(_("NVIDIA GPU work fetch priority"),wxString::Format(wxT("%0.2f"), project->cuda_debt));
256
x = project->cuda_backoff_time - dtime();
258
addProperty(_("NVIDIA GPU work fetch deferred for"), FormatTime(x));
259
addProperty(_("NVIDIA GPU work fetch deferral interval"), FormatTime(project->cuda_backoff_interval));
261
if (pDoc->state.have_ati) {
262
if (project->no_ati_pref) {
263
addProperty(_("Project preference"), _("Don't fetch ATI GPU tasks"));
265
addProperty(_("ATI GPU scheduling priority"),wxString::Format(wxT("%0.2f"), project->ati_short_term_debt));
266
addProperty(_("ATI GPU work fetch priority"),wxString::Format(wxT("%0.2f"), project->ati_debt));
267
x = project->ati_backoff_time - dtime();
269
addProperty(_("ATI GPU work fetch deferred for"), FormatTime(x));
270
addProperty(_("ATI GPU work fetch deferral interval"), FormatTime(project->ati_backoff_interval));
272
addProperty(_("Duration correction factor"),wxString::Format(wxT("%0.4f"), project->duration_correction_factor));
275
m_scrolledWindow->FitInside();
278
// show task properties
280
void CDlgItemProperties::renderInfos(RESULT* result) {
281
CMainDocument* pDoc = wxGetApp().GetDocument();
283
wxString wxTitle = _("Properties of task ");
284
wxTitle.append(wxString(result->name, wxConvUTF8));
287
APP_VERSION* avp = NULL;
288
WORKUNIT* wup = NULL;
289
RESULT* r = pDoc->state.lookup_result(result->project_url, result->name);
295
addProperty(_("Application"), FormatApplicationName(result));
296
addProperty(_("Workunit name"),wxString(result->wu_name, wxConvUTF8));
297
addProperty(_("State"), result_description(result, false));
298
if (result->received_time) {
299
dt.Set((time_t)result->received_time);
300
addProperty(_("Received"), dt.Format());
302
dt.Set((time_t)result->report_deadline);
303
addProperty(_("Report deadline"), dt.Format());
304
if (strlen(result->resources)) {
305
addProperty(_("Resources"), wxString(result->resources, wxConvUTF8));
308
addProperty(_("Estimated app speed"), wxString::Format(wxT("%.2f GFLOPs/sec"), avp->flops/1e9));
311
addProperty(_("Estimated task size"), wxString::Format(wxT("%.0f GFLOPs"), wup->rsc_fpops_est/1e9));
312
addProperty(_("Max RAM usage"), wxString::Format(wxT("%.0f MB"), wup->rsc_memory_bound/MEGA));
314
if (result->active_task) {
315
addProperty(_("CPU time at last checkpoint"), FormatTime(result->checkpoint_cpu_time));
316
addProperty(_("CPU time"), FormatTime(result->current_cpu_time));
317
if (result->elapsed_time >= 0) {
318
addProperty(_("Elapsed time"), FormatTime(result->elapsed_time));
320
addProperty(_("Estimated time remaining"), FormatTime(result->estimated_cpu_time_remaining));
321
addProperty(_("Fraction done"), wxString::Format(wxT("%.3f %%"), result->fraction_done*100));
322
addProperty(_("Virtual memory size"), FormatDiskSpace(result->swap_size));
323
addProperty(_("Working set size"), FormatDiskSpace(result->working_set_size_smoothed));
324
if (result->slot >= 0) {
325
addProperty(_("Directory"), wxString::Format(wxT("slots/%d"), result->slot));
328
addProperty(_("Process ID"), wxString::Format(wxT("%d"), result->pid));
330
} else if (result->state >= RESULT_COMPUTE_ERROR) {
331
addProperty(_("CPU time"), FormatTime(result->final_cpu_time));
332
addProperty(_("Elapsed time"), FormatTime(result->final_elapsed_time));
335
m_scrolledWindow->FitInside();
339
wxString CDlgItemProperties::FormatDiskSpace(double bytes) {
340
double xTera = 1099511627776.0;
341
double xGiga = 1073741824.0;
342
double xMega = 1048576.0;
343
double xKilo = 1024.0;
344
wxString strBuffer= wxEmptyString;
346
if (bytes >= xTera) {
347
strBuffer.Printf(wxT("%0.2f TB"), bytes/xTera);
348
} else if (bytes >= xGiga) {
349
strBuffer.Printf(wxT("%0.2f GB"), bytes/xGiga);
350
} else if (bytes >= xMega) {
351
strBuffer.Printf(wxT("%0.2f MB"), bytes/xMega);
352
} else if (bytes >= xKilo) {
353
strBuffer.Printf(wxT("%0.2f KB"), bytes/xKilo);
355
strBuffer.Printf(wxT("%0.0f bytes"), bytes);
361
wxString CDlgItemProperties::FormatApplicationName(RESULT* result ) {
362
wxString strBuffer = wxEmptyString;
363
CMainDocument* pDoc = wxGetApp().GetDocument();
364
RESULT* state_result = NULL;
365
wxString strAppBuffer = wxEmptyString;
366
wxString strClassBuffer = wxEmptyString;
369
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
372
state_result = pDoc->state.lookup_result(result->project_url, result->name);
374
pDoc->ForceCacheUpdate();
375
state_result = pDoc->state.lookup_result(result->project_url, result->name);
377
wxASSERT(state_result);
379
if (!state_result) return strBuffer;
380
WORKUNIT* wup = state_result->wup;
381
if (!wup) return strBuffer;
383
if (!app) return strBuffer;
384
APP_VERSION* avp = state_result->avp;
385
if (!avp) return strBuffer;
387
if (strlen(app->user_friendly_name)) {
388
strAppBuffer = wxString(state_result->app->user_friendly_name, wxConvUTF8);
390
strAppBuffer = wxString(state_result->avp->app_name, wxConvUTF8);
393
if (strlen(avp->plan_class)) {
394
strClassBuffer.Printf(
396
wxString(avp->plan_class, wxConvUTF8).c_str()
401
wxT("%s%s %d.%02d %s"),
402
state_result->project->anonymous_platform?_("Local: "):wxT(""),
403
strAppBuffer.c_str(),
404
state_result->avp->version_num / 100,
405
state_result->avp->version_num % 100,
406
strClassBuffer.c_str()
413
wxString CDlgItemProperties::FormatTime(float fBuffer) {
418
wxString strBuffer= wxEmptyString;
421
strBuffer = wxT("---");
423
iHour = (wxInt32)(fBuffer / (60 * 60));
424
iMin = (wxInt32)(fBuffer / 60) % 60;
425
iSec = (wxInt32)(fBuffer) % 60;
427
ts = wxTimeSpan(iHour, iMin, iSec);
429
strBuffer = ts.Format();
435
// adds a title section label to the dialog
436
void CDlgItemProperties::addSection(const wxString& title) {
437
wxStaticText* staticText = new wxStaticText( m_scrolledWindow, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, 0);
438
staticText->Wrap( -1 );
439
staticText->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) );
440
m_gbSizer->Add( staticText, wxGBPosition( m_current_row, 0 ), wxGBSpan( 1, 2 ), wxALL|wxEXPAND, 3);
444
// adds a property row to the dialog
445
void CDlgItemProperties::addProperty(const wxString& name, const wxString& value) {
447
wxStaticText* staticText = new wxStaticText( m_scrolledWindow, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, 0 );
448
staticText->Wrap( -1 );
449
m_gbSizer->Add( staticText, wxGBPosition( m_current_row, 0 ), wxGBSpan( 1, 1 ), wxALL, 3 );
451
staticText = new wxStaticText( m_scrolledWindow, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, 0 );
452
staticText->Wrap( -1 );
453
m_gbSizer->Add( staticText, wxGBPosition( m_current_row, 1 ), wxGBSpan( 1, 1 ), wxALL|wxEXPAND, 3 );