-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocpage.cpp
4733 lines (3639 loc) · 125 KB
/
procpage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//+-------------------------------------------------------------------------
//
// TaskMan - NT TaskManager
// Copyright (C) Microsoft
//
// File: procpage.cpp
//
// History: Nov-16-95 DavePl Created
//
//--------------------------------------------------------------------------
#include "precomp.h"
//
// Project-scope globals
//
DWORD g_cProcesses = 0;
extern WCHAR g_szTimeSep[];
extern WCHAR g_szGroupThousSep[];
extern ULONG g_ulGroupSep;
//--------------------------------------------------------------------------
// TERMINAL SERVICES
//-- cache this state
BOOL IsUserAdmin( )
{
// Note that local static initialization is not thread safe,
// but this function is only called from the process page dialog
// proc (i.e. single thread).
static BOOL sbIsUserAdmin = SHTestTokenMembership(NULL, DOMAIN_ALIAS_RID_ADMINS);
return sbIsUserAdmin;
}
// get/set current session id.
// we use this session id to filter the processes for current session.
DWORD gdwSessionId = static_cast<DWORD>(-1);
inline DWORD GetCurrentSessionID( )
{
return gdwSessionId;
}
inline VOID SetCurrentSessionID( DWORD dwSessionId )
{
gdwSessionId = dwSessionId;
}
// END OF TERMINAL SERVICES DECLs
//--------------------------------------------------------------------------
//
// File-scope globals
//
SYSTEM_BASIC_INFORMATION g_BasicInfo;
//
// Table of which resource IDs in the column selection dialog
// correspond to which columns
//
const int g_aDlgColIDs[] =
{
IDC_IMAGENAME,
IDC_PID,
IDC_USERNAME,
IDC_SESSIONID,
IDC_CPU,
IDC_CPUTIME,
IDC_MEMUSAGE,
IDC_MEMPEAK,
IDC_MEMUSAGEDIFF,
IDC_PAGEFAULTS,
IDC_PAGEFAULTSDIFF,
IDC_COMMITCHARGE,
IDC_PAGEDPOOL,
IDC_NONPAGEDPOOL,
IDC_BASEPRIORITY,
IDC_HANDLECOUNT,
IDC_THREADCOUNT,
IDC_USEROBJECTS,
IDC_GDIOBJECTS,
IDC_READOPERCOUNT,
IDC_WRITEOPERCOUNT,
IDC_OTHEROPERCOUNT,
IDC_READXFERCOUNT,
IDC_WRITEXFERCOUNT,
IDC_OTHERXFERCOUNT,
IDC_COMMANDLINE
};
//
// Column ID on which to sort in the listview, and for
// compares in general
//
COLUMNID g_iProcSortColumnID = (COLUMNID)COL_PID;
INT g_iProcSortDirection = 1; // 1 = asc, -1 = desc
//
// Column Default Info
//
struct
{
INT Format;
INT Width;
} ColumnDefaults[NUM_COLUMN] =
{
{ LVCFMT_LEFT, 0x6B }, // COL_IMAGENAME
{ LVCFMT_RIGHT, 50 }, // COL_PID
{ LVCFMT_LEFT, 0x6B }, // COL_USERNAME
{ LVCFMT_RIGHT, 70 }, // COL_SESSIONID
{ LVCFMT_RIGHT, 35}, // COL_CPU
{ LVCFMT_RIGHT, 70 }, // COL_CPUTIME
{ LVCFMT_RIGHT, 70 }, // COL_MEMUSAGE
{ LVCFMT_RIGHT, 100 }, // COL_MEMPEAK
{ LVCFMT_RIGHT, 70 }, // COL_MEMUSAGEDIFF
{ LVCFMT_RIGHT, 70 }, // COL_PAGEFAULTS
{ LVCFMT_RIGHT, 70 }, // COL_PAGEFAULTSDIFF
{ LVCFMT_RIGHT, 70 }, // COL_COMMITCHARGE
{ LVCFMT_RIGHT, 70 }, // COL_PAGEDPOOL
{ LVCFMT_RIGHT, 70 }, // COL_NONPAGEDPOOL
{ LVCFMT_RIGHT, 60 }, // COL_BASEPRIORITY
{ LVCFMT_RIGHT, 60 }, // COL_HANDLECOUNT
{ LVCFMT_RIGHT, 60 }, // COL_THREADCOUNT
{ LVCFMT_RIGHT, 60 }, // COL_USEROBJECTS
{ LVCFMT_RIGHT, 60 }, // COL_GDIOBJECTS
{ LVCFMT_RIGHT, 70 }, // COL_READOPERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_WRITEOPERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_OTHEROPERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_READXFERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_WRITEXFERCOUNT
{ LVCFMT_RIGHT, 70 }, // COL_OTHERXFERCOUNT
{ LVCFMT_LEFT, 0x6B } // COL_COMMANDLINE
};
/*++ class CProcInfo
Class Description:
Represents the last known information about a running process
Arguments:
Return Value:
Revision History:
Nov-16-95 Davepl Created
--*/
class CProcInfo
{
public:
__int64 m_uPassCount;
DWORD m_UniqueProcessId;
LPWSTR m_pszUserName;
ULONG m_SessionId;
BYTE m_CPU;
BYTE m_DisplayCPU;
__int64 m_CPUTime;
__int64 m_DisplayCPUTime;
SIZE_T m_MemUsage;
SSIZE_T m_MemDiff;
ULONG m_PageFaults;
LONG m_PageFaultsDiff;
ULONG_PTR m_CommitCharge;
ULONG_PTR m_PagedPool;
ULONG_PTR m_NonPagedPool;
KPRIORITY m_PriClass;
ULONG m_HandleCount;
ULONG m_ThreadCount;
ULONG m_GDIObjectCount;
ULONG m_USERObjectCount;
LONGLONG m_IoReadOperCount;
LONGLONG m_IoWriteOperCount;
LONGLONG m_IoOtherOperCount;
LONGLONG m_IoReadXferCount;
LONGLONG m_IoWriteXferCount;
LONGLONG m_IoOtherXferCount;
LPWSTR m_pszImageName;
LPWSTR m_pszCommandLine;
CProcInfo * m_pWowParentProcInfo; // non-NULL for WOW tasks
WORD m_htaskWow; // non-zero for WOW tasks
BOOL m_fWowProcess:1; // TRUE for real WOW process
BOOL m_fWowProcessTested:1; // TRUE once fWowProcess is valid
SIZE_T m_MemPeak;
//
// This is a union of who (which column) is dirty. You can look at
// or set any particular column's bit, or just inspect m_fDirty
// to see if anyone at all is dirty. Used to optimize listview
// painting
//
union
{
DWORD m_fDirty;
#pragma warning(disable:4201) // Nameless struct or union
struct
{
DWORD m_fDirty_COL_CPU :1;
DWORD m_fDirty_COL_CPUTIME :1;
DWORD m_fDirty_COL_MEMUSAGE :1;
DWORD m_fDirty_COL_MEMUSAGEDIFF :1;
DWORD m_fDirty_COL_PAGEFAULTS :1;
DWORD m_fDirty_COL_PAGEFAULTSDIFF :1;
DWORD m_fDirty_COL_COMMITCHARGE :1;
DWORD m_fDirty_COL_PAGEDPOOL :1;
DWORD m_fDirty_COL_NONPAGEDPOOL :1;
DWORD m_fDirty_COL_BASEPRIORITY :1;
DWORD m_fDirty_COL_HANDLECOUNT :1;
DWORD m_fDirty_COL_IMAGENAME :1;
DWORD m_fDirty_COL_PID :1;
DWORD m_fDirty_COL_SESSIONID :1;
DWORD m_fDirty_COL_USERNAME :1;
DWORD m_fDirty_COL_THREADCOUNT :1;
DWORD m_fDirty_COL_GDIOBJECTS :1;
DWORD m_fDirty_COL_USEROBJECTS :1;
DWORD m_fDirty_COL_MEMPEAK :1;
DWORD m_fDirty_COL_READOPERCOUNT :1;
DWORD m_fDirty_COL_WRITEOPERCOUNT :1;
DWORD m_fDirty_COL_OTHEROPERCOUNT :1;
DWORD m_fDirty_COL_READXFERCOUNT :1;
DWORD m_fDirty_COL_WRITEXFERCOUNT :1;
DWORD m_fDirty_COL_OTHERXFERCOUNT :1;
DWORD m_fDirty_COL_COMMANDLINE :1;
};
#pragma warning(default:4201) // Nameless struct or union
};
HRESULT SetData(__int64 TotalTime,
PSYSTEM_PROCESS_INFORMATION pInfo,
__int64 uPassCount,
CProcPage * pProcPage,
BOOL fUpdateOnly);
HRESULT SetProcessUsername(const FILETIME *CreationTime);
HRESULT SetDataWowTask(__int64 TotalTime,
DWORD dwThreadId,
CHAR * pszFilePath,
__int64 uPassCount,
CProcInfo * pParentProcInfo,
__int64 *pTimeLeft,
WORD htask,
BOOL fUpdateOnly);
CProcInfo()
{
ZeroMemory(this, sizeof(*this));
m_SessionId = 832;
}
~CProcInfo()
{
if (m_pszImageName)
{
LocalFree( m_pszImageName );
}
if( m_pszUserName != NULL )
{
LocalFree( m_pszUserName );
}
if (m_pszCommandLine)
{
LocalFree(m_pszCommandLine);
}
}
BOOL OkToShowThisProcess ()
{
// this function determines if the process should be listed in the view.
return GetCurrentSessionID() == m_SessionId;
}
// Invalidate() marks this proc with a bogus pid so that it is removed
// on the next cleanup pass
void Invalidate()
{
m_UniqueProcessId = PtrToUlong(INVALID_HANDLE_VALUE);
}
LONGLONG GetCPUTime() const
{
return m_CPUTime;
}
INT Compare(CProcInfo * pOther);
//
// Is this a WOW task psuedo-process?
//
INT_PTR IsWowTask(void) const
{
return (INT_PTR) m_pWowParentProcInfo;
}
//
// Get the Win32 PID for this task
//
DWORD GetRealPID(void) const
{
return m_pWowParentProcInfo
? m_pWowParentProcInfo->m_UniqueProcessId
: m_UniqueProcessId;
}
void SetCPU(__int64 CPUTimeDelta,
__int64 TotalTime,
BOOL fDisplayOnly);
};
/*++ ColSelectDlgProc
Function Description:
Dialog Procedure for the column selection dialog
Arguments:
Standard wndproc stuff
Revision History:
Jan-05-96 Davepl Created
--*/
INT_PTR CALLBACK ColSelectDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static CProcPage * pPage = NULL;
switch(uMsg)
{
case WM_INITDIALOG:
{
pPage = (CProcPage *) lParam;
//
// Start with none of the boxes checked
//
for (int i = 0; i < NUM_COLUMN; i++)
{
CheckDlgButton(hwndDlg, g_aDlgColIDs[i], BST_UNCHECKED);
}
//
// HIDE the Username and SessionId if its not Terminal Server.
//
if( !g_fIsTSEnabled )
{
ShowWindow( GetDlgItem( hwndDlg , IDC_USERNAME ) , SW_HIDE );
ShowWindow( GetDlgItem( hwndDlg , IDC_SESSIONID ) , SW_HIDE );
}
//
// Then turn on the ones for the columns we have active
//
for (int i = 0; i < NUM_COLUMN + 1; i++)
{
if (g_Options.m_ActiveProcCol[i] == -1)
{
break;
}
CheckDlgButton(hwndDlg, g_aDlgColIDs[g_Options.m_ActiveProcCol[i]], BST_CHECKED);
}
}
return TRUE; // don't set focus
case WM_COMMAND:
//
// If user clicked OK, add the columns to the array and reset the listview
//
if (LOWORD(wParam) == IDOK)
{
// First, make sure the column width array is up to date
pPage->SaveColumnWidths();
INT iCol = 1;
g_Options.m_ActiveProcCol[0] = (COLUMNID)COL_IMAGENAME;
for (int i = 1; i < NUM_COLUMN && g_aDlgColIDs[i] >= 0; i++)
{
if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, g_aDlgColIDs[i]))
{
// It is checked
if (g_Options.m_ActiveProcCol[iCol] != (COLUMNID) i)
{
// If the column wasn't already there, insert its column
// width into the column width array
ShiftArray(g_Options.m_ColumnWidths, iCol, (SHIFT_DIRECTION)SHIFT_UP);
ShiftArray(g_Options.m_ActiveProcCol, iCol, (SHIFT_DIRECTION)SHIFT_UP);
g_Options.m_ColumnWidths[iCol] = ColumnDefaults[ i ].Width;
g_Options.m_ActiveProcCol[iCol] = (COLUMNID) i;
}
iCol++;
}
else
{
// Not checked, column not active. If it used to be active,
// remove its column width from the column width array
if (g_Options.m_ActiveProcCol[iCol] == (COLUMNID) i)
{
ShiftArray(g_Options.m_ColumnWidths, iCol, (SHIFT_DIRECTION)SHIFT_DOWN);
ShiftArray(g_Options.m_ActiveProcCol, iCol, (SHIFT_DIRECTION)SHIFT_DOWN);
}
}
}
// Terminate the column list
g_Options.m_ActiveProcCol[iCol] = (COLUMNID) -1;
pPage->SetupColumns();
pPage->TimerEvent();
EndDialog(hwndDlg, IDOK);
}
else if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwndDlg, IDCANCEL);
}
break;
}
return FALSE;
}
/*++ CProcPage::~CProcPage()
- Destructor
*/
CProcPage::~CProcPage()
{
Destroy( );
}
/*++ CProcPage::PickColumns()
Function Description:
Puts up UI that lets the user select what columns to display in the
process page, and then resets the listview with the new column list
Arguments:
none
Return Value:
none
Revision History:
Jan-05-96 Davepl Created
--*/
void CProcPage::PickColumns()
{
DialogBoxParam(g_hInstance,
MAKEINTRESOURCE(IDD_SELECTPROCCOLS),
g_hMainWnd,
ColSelectDlgProc,
(LPARAM) this);
}
/*++ GetPriRanking
Function Description:
Since the priority class defines aren't in order, this helper
exists to make comparisons between pri classes easier. It returns
a larger number for "higher" priority classes
Arguments:
Return Value:
rank of priority (0 to 5)
Revision History:
Nov-27-95 Davepl Created
--*/
DWORD GetPriRanking(DWORD dwClass)
{
switch(dwClass)
{
case REALTIME_PRIORITY_CLASS:
return 5;
case HIGH_PRIORITY_CLASS:
return 4;
case ABOVE_NORMAL_PRIORITY_CLASS:
return 3;
case NORMAL_PRIORITY_CLASS:
return 2;
case BELOW_NORMAL_PRIORITY_CLASS:
return 1;
default:
return 0;
}
}
/*++ QuickConfirm
Function Description:
Gets a confirmation for things like terminating/debugging processes
Arguments:
idtitle - string ID of title for message box
idmsg - string ID of message body
Return Value:
IDNO/IDYES, whatever comes back from MessageBox
Revision History:
Nov-28-95 Davepl Created
--*/
UINT CProcPage::QuickConfirm(UINT idTitle, UINT idBody)
{
//
// Get confirmation before we dust the process, or something similar
//
WCHAR szTitle[MAX_PATH];
WCHAR szBody[MAX_PATH];
if (0 == LoadString(g_hInstance, idTitle, szTitle, ARRAYSIZE(szTitle)) ||
0 == LoadString(g_hInstance, idBody, szBody, ARRAYSIZE(szBody)))
{
return IDNO;
}
if (IDYES == MessageBox(m_hPage, szBody, szTitle, MB_ICONEXCLAMATION | MB_YESNO))
{
return IDYES;
}
return IDNO;
}
/*++ class CProcPage::SetupColumns
Class Description:
Removes any existing columns from the process listview and
adds all of the columns listed in the g_Options.m_ActiveProcCol array.
Arguments:
Return Value:
HRESULT
Revision History:
Nov-16-95 Davepl Created
--*/
static const int _aIDColNames[NUM_COLUMN] =
{
IDS_COL_IMAGENAME,
IDS_COL_PID,
IDS_COL_USERNAME,
IDS_COL_SESSIONID,
IDS_COL_CPU,
IDS_COL_CPUTIME,
IDS_COL_MEMUSAGE,
IDS_COL_MEMPEAK,
IDS_COL_MEMUSAGEDIFF,
IDS_COL_PAGEFAULTS,
IDS_COL_PAGEFAULTSDIFF,
IDS_COL_COMMITCHARGE,
IDS_COL_PAGEDPOOL,
IDS_COL_NONPAGEDPOOL,
IDS_COL_BASEPRIORITY,
IDS_COL_HANDLECOUNT,
IDS_COL_THREADCOUNT,
IDS_COL_USEROBJECTS,
IDS_COL_GDIOBJECTS,
IDS_COL_READOPERCOUNT,
IDS_COL_WRITEOPERCOUNT,
IDS_COL_OTHEROPERCOUNT,
IDS_COL_READXFERCOUNT,
IDS_COL_WRITEXFERCOUNT,
IDS_COL_OTHERXFERCOUNT,
IDS_COL_COMMANDLINE
};
HRESULT CProcPage::SetupColumns()
{
HWND hwndList = GetDlgItem(m_hPage, IDC_PROCLIST);
if (NULL == hwndList)
{
return E_UNEXPECTED;
}
ListView_DeleteAllItems(hwndList);
// Remove all existing columns
LV_COLUMN lvcolumn;
while(ListView_DeleteColumn(hwndList, 0))
{
NULL;
}
// Add all of the new columns
INT iColumn = 0;
while (g_Options.m_ActiveProcCol[iColumn] >= 0)
{
INT idColumn = g_Options.m_ActiveProcCol[iColumn];
// idc_username or IDC_SESSIONID are available only for terminalserver.
ASSERT((idColumn != COL_USERNAME && idColumn != COL_SESSIONID) || g_fIsTSEnabled);
WCHAR szTitle[MAX_PATH];
LoadString(g_hInstance, _aIDColNames[idColumn], szTitle, ARRAYSIZE(szTitle));
lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_TEXT | LVCF_WIDTH;
lvcolumn.fmt = ColumnDefaults[ idColumn ].Format;
// If no width preference has been recorded for this column, use the
// default
if (-1 == g_Options.m_ColumnWidths[iColumn])
{
lvcolumn.cx = ColumnDefaults[ idColumn ].Width;
}
else
{
lvcolumn.cx = g_Options.m_ColumnWidths[iColumn];
}
lvcolumn.pszText = szTitle;
lvcolumn.iSubItem = iColumn;
if (-1 == ListView_InsertColumn(hwndList, iColumn, &lvcolumn))
{
return E_FAIL;
}
iColumn++;
}
return S_OK;
}
//
// Take two unsigned 64-bit values and compare them in a manner
// that CProcInfo::Compare likes.
//
int Compare64(unsigned __int64 First, unsigned __int64 Second)
{
if (First < Second)
{
return -1;
}
else if (First > Second)
{
return 1;
}
else
{
return 0;
}
}
/*++ class CProcInfo::Compare
Class Description:
Compares this CProcInfo object to another, and returns its ranking
based on the g_iProcSortColumnID field.
Note that if the objects are equal based on the current sort column,
the PID is used as a secondary sort key to prevent items from
jumping around in the listview
WOW psuedo-processes always sort directly after their parent
ntvdm.exe process. So really the sort order is:
1. WOW task psuedo-processes under parent in alpha order
2. User's selected order.
3. PID
Arguments:
pOther - the CProcInfo object to compare this to
Return Value:
< 0 - This CProcInfo is "less" than the other
0 - Equal (Can't happen, since PID is used to sort)
> 0 - This CProcInfo is "greater" than the other
Revision History:
Nov-20-95 Davepl Created
--*/
INT CProcInfo::Compare(CProcInfo * pOther)
{
CProcInfo * pMyThis;
CProcInfo * pMyOther;
INT iRet = 0;
//
// Wow psuedo-processes don't have any performance information,
// so use the parent "real" ntvdm.exe CProcInfo for sorting.
//
ASSERT(this != pOther);
pMyThis = this->IsWowTask()
? this->m_pWowParentProcInfo
: this;
pMyOther = pOther->IsWowTask()
? pOther->m_pWowParentProcInfo
: pOther;
if (pMyThis == pMyOther) {
//
// This implies one or the other or both this and pOther
// are WOW tasks, and they're in the same WOW VDM. Sort
// the "real" process entry first, followed by its associated
// WOW task entries alphabetical.
//
if (this->IsWowTask()) {
if (pOther->IsWowTask()) {
//
// They are siblings and we sort by
// image name.
//
ASSERT(this->m_pWowParentProcInfo == pOther->m_pWowParentProcInfo);
iRet = lstrcmpi(this->m_pszImageName, pOther->m_pszImageName);
} else {
//
// pOther is not a Wow task, it must be ntvdm.exe
// the parent of this. this sorts after pOther.
//
ASSERT(pOther == this->m_pWowParentProcInfo);
iRet = 1;
}
} else {
//
// this is not a Wow task, pOther must be and
// this must be pOther's parent.
//
ASSERT(pOther->IsWowTask());
iRet = -1;
}
}
if (0 == iRet)
{
switch (g_iProcSortColumnID)
{
case COL_CPU:
iRet = Compare64(pMyThis->m_CPU, pMyOther->m_CPU);
break;
case COL_CPUTIME:
iRet = Compare64(pMyThis->m_CPUTime, pMyOther->m_CPUTime);
break;
case COL_MEMUSAGE:
iRet = Compare64(pMyThis->m_MemUsage, pMyOther->m_MemUsage);
break;
case COL_MEMUSAGEDIFF:
iRet = Compare64(pMyThis->m_MemDiff, pMyOther->m_MemDiff);
break;
case COL_MEMPEAK:
iRet = Compare64(pMyThis->m_MemPeak, pMyOther->m_MemPeak);
break;
case COL_PAGEFAULTS:
iRet = Compare64(pMyThis->m_PageFaults, pMyOther->m_PageFaults);
break;
case COL_PAGEFAULTSDIFF:
iRet = Compare64(pMyThis->m_PageFaultsDiff, pMyOther->m_PageFaultsDiff);
break;
case COL_COMMITCHARGE:
iRet = Compare64(pMyThis->m_CommitCharge, pMyOther->m_CommitCharge);
break;
case COL_PAGEDPOOL:
iRet = Compare64(pMyThis->m_PagedPool, pMyOther->m_PagedPool);
break;
case COL_NONPAGEDPOOL:
iRet = Compare64(pMyThis->m_NonPagedPool, pMyOther->m_NonPagedPool);
break;
case COL_BASEPRIORITY:
iRet = Compare64(GetPriRanking(pMyThis->m_PriClass), GetPriRanking(pMyOther->m_PriClass));
break;
case COL_HANDLECOUNT:
iRet = Compare64(pMyThis->m_HandleCount, pMyOther->m_HandleCount);
break;
case COL_THREADCOUNT:
iRet = Compare64(pMyThis->m_ThreadCount, pMyOther->m_ThreadCount);
break;
case COL_PID:
iRet = Compare64(pMyThis->m_UniqueProcessId, pMyOther->m_UniqueProcessId);
break;
case COL_SESSIONID:
iRet = Compare64(pMyThis->m_SessionId, pMyOther->m_SessionId);
break;
case COL_USERNAME:
iRet = lstrcmpi( pMyThis->m_pszUserName , pMyOther->m_pszUserName );
break;
case COL_IMAGENAME:
iRet = lstrcmpi(pMyThis->m_pszImageName, pMyOther->m_pszImageName);
break;
case COL_USEROBJECTS:
iRet = Compare64(pMyThis->m_USERObjectCount, pMyOther->m_USERObjectCount);
break;
case COL_GDIOBJECTS:
iRet = Compare64(pMyThis->m_GDIObjectCount, pMyOther->m_GDIObjectCount);
break;
case COL_READOPERCOUNT:
iRet = Compare64(pMyThis->m_IoReadOperCount, pMyOther->m_IoReadOperCount);
break;
case COL_WRITEOPERCOUNT:
iRet = Compare64(pMyThis->m_IoWriteOperCount, pMyOther->m_IoWriteOperCount);
break;
case COL_OTHEROPERCOUNT:
iRet = Compare64(pMyThis->m_IoOtherOperCount, pMyOther->m_IoOtherOperCount);
break;
case COL_READXFERCOUNT:
iRet = Compare64(pMyThis->m_IoReadXferCount, pMyOther->m_IoReadXferCount);
break;
case COL_WRITEXFERCOUNT:
iRet = Compare64(pMyThis->m_IoWriteXferCount, pMyOther->m_IoWriteXferCount);
break;
case COL_OTHERXFERCOUNT:
iRet = Compare64(pMyThis->m_IoOtherXferCount, pMyOther->m_IoOtherXferCount);
break;
case COL_COMMANDLINE:
iRet = lstrcmpi(pMyThis->m_pszCommandLine, pMyOther->m_pszCommandLine);
break;
default:
ASSERT(FALSE);
iRet = 0;
break;
}
iRet *= g_iProcSortDirection;
}
// If objects look equal, compare on PID as secondary sort column
// so that items don't jump around in the listview
if (0 == iRet)
{
iRet = Compare64(pMyThis->m_UniqueProcessId, pMyOther->m_UniqueProcessId) * g_iProcSortDirection;
}
return iRet;
}
/*++ class CProcInfo::SetCPU
Method Description:
Sets the CPU percentage.
Arguments:
CPUTime - Time for this process
TotalTime - Total elapsed time, used as the denominator in calculations
Return Value:
Revision History:
19-Feb-96 DaveHart Created
--*/
void CProcInfo::SetCPU(__int64 CPUTimeDelta,
__int64 TotalTime,
BOOL fDisplayOnly)
{
// Calc CPU time based on this process's ratio of the total process time used
INT cpu = (BYTE) (((CPUTimeDelta / ((TotalTime / 1000) ?
(TotalTime / 1000) : 1)) + 5)
/ 10);
if (cpu > 99)
{
cpu = 99;
}
if (m_DisplayCPU != cpu)
{
m_fDirty_COL_CPU = TRUE;
m_DisplayCPU = (BYTE) cpu;
if ( ! fDisplayOnly )
{
m_CPU = (BYTE) cpu;
}
}
}
/*++ CProcPage::GetProcessInfo
Class Description:
Reads the process info table into a virtual alloc'd buffer, resizing
the buffer if needed
Arguments: