Mastering Process Explorer Metrics: IT Admins' Essential Toolkit: Day 4

TechSavvyProductions
171 followers
8 Video Views·Nov 19, 2024
We will look at Process Explorer Metrics, understand these values, and how to apply them to analyzing and troubleshooting applications. Why context delta is such an important metric to use in analyzing processes. This video series is a comprehensive study using powerful tools to lift the hood of the Windows Operating System and allow the tech to understand and troubleshoot applications and services. We will dive into the powerful features of Process Explorer and in doing so learn more about processes, process states, and a better understanding of how programs run in RAM and the page file
You want to make sure that you go to my YouTube channel and watch Part 1, Part 2, and then Part 3 before you begin Part 4.
When you download debugging tools for Windows, you get a lot of modules that you can install or not install.
One of those is Debugging Symbols.
Symbols and symbol files store a variety of data that are not required when you're running normal Windows,
but are very helpful when you're debugging.
So let me show you how to configure symbols for Process Explorer and Process Monitor.
In Process Explorer, we're going to go to the menus option where it says options.
It'll drop down and you'll see the ability to configure symbols.
Now the debug help.dll should be there already.
That's going to be the DLL that Process Explorer and Process Monitor are going to leverage to use debug.
But I want you to just put in, you'll see the text on the screen, on the slide,
and you'll see that also in the notes, you can copy and paste that into the symbols path.
You say OK, and it will use the Microsoft public server for symbols when it needs them.
One benefit right away we get in adding a symbol path is we get a lot more information in our threads tab.
Also, Process Monitor will be showing us a lot more information with that configured.
Let's continue our look at memory.
Go with me to Windows Settings and launch your Windows Settings.
We're going to go to Update and Security, and we're going to go to Windows Security.
I'm going to show you a number of new built-in memory protection features,
App and Browser Control, and slide down till we get to Exploit Protection.
Make sure that all of these memory protection features are on in your Windows 10.
We're going to look at Control Flow Guard since it impacts many of our metrics in Process Explorer.
But all of these should be on.
These various exploit protection features are documented on this page,
and I'll put a link at the bottom to the URL.
But it shows you how to use all kinds of management device tools,
SSCM, MDM, Microsoft Intune, Group Policy, PowerShell.
So it gives you a lot of ability to turn them on, enable them, and to validate that they're there.
But it covers all of the different types of exploit protections that are built into Windows.
Make sure they're on and that you have checked this page out.
Windows 10 and Server all have physical memory limits based on the editions.
Windows 10 Enterprise and Pro have about a 6TB limit on x64.
For our Server editions, it's 24TB.
Let's do a quick review of memory limits as it pertains to processes.
I'm going to show you some of the limits of memory,
and I'm going to use the VMAP64.
This is part of System Internals Tools.
I'm going to right-mouse-click and run it with administrative rights.
Say yes.
And I'm going to go over here to Process Explorer, and I'm going to look at the process ID.
Here's Chrome, and it's the parent process for Chrome, and it's 3484.
So I'm going to go back to VMAP,
and I'm going to look at launching this Chrome, this 3484 process.
Here we see the commit from this process.
So this process has launched and communicated to the operating system and said,
I need you to guarantee at either through the page file or RAM, 489MB of memory.
And that's the commit amount.
Now that's made up of primarily private bytes and working sets.
So private bytes below, which is paged, and the working set, which is in memory.
So let's take a look at normal behavior and abnormal behavior.
I've got Corel AfterShot on.
I've got it up and running, so you can see it in my virtual map,
and I'm going to go ahead and open that up.
And this graphical tool, if I continue to open up pictures in it,
it should, that commit limit should grow.
As I close those pictures out, the commit level should decrease.
Where memory leakage and memory problems come in
is where there is a mistake in the code that was written
or there's poorly written code to where memory is continually requested,
but it is not relinquished when it should appropriately.
So right now you can see I've got 1.8 gigs, 1.7 gigs requested by Corel,
this graphical program.
If I open up five pictures, it should go up.
That's normal.
But when I close out all those pictures,
the committed amount should go back down to this value.
If it doesn't, you've got memory leakage.
Now all of the problems that we've talked about,
memory leakage, we're going to look at handle leakage,
all of these are problems with antiprocess.
Sometimes, as we've mentioned, they can be code mistakes.
They can be just plain lousy code.
All of these are common.
In fact, they're more common on the desktop applications
than they are on the server.
But more often we see them on the server than the desktop.
The reason is we reboot our desktops more often.
So everything goes back to a fresh commit amount from all of our processes
and leakage by leakage and handle leakage and all those other issues
by the end of the day is fixed when we reboot our desktop.
Well, our servers don't reboot that often.
So they are usually the more common of the devices
that we see these problems in.
Now, Process Explorer provides a couple ways to look at this.
One, you can look at handle count.
You can check your handle count under process performance.
Also, under process memory, we can check the GDI objects, user objects,
and those are another ways to keep tabs on that.
Often in data centers, they schedule a reboot, say at midnight,
for a lot of servers just to avoid this same problem on the server side.
All right, let's look at memory limits using my video editor.
You can see my current commit is about 19 gigs.
In other words, all my processes and all my operating systems
have communicated to the memory manager and said this is what we need.
And so it knows between RAM and the page file, this is what we want, 19 gigs.
You can see my limit.
My page file can grow up to a certain point.
That plus RAM gives me my current limit of 50 gigs.
And the reason that's so large is because this is a video editor.
You can see my peak is 20 gigs sometime during the power on.
It requested up to 20 gigs.
Now, I'm going to launch my virtual machine.
I'll just compare it.
This is a little Windows 10 box with 2 gigs of memory.
You can see my current commit is about 1.5 gigs.
My limit, that would be my RAM plus my maximum page file, is about 2.7.
And I've peaked at about 2 gigs.
These are very important.
Remember, you can have memory exhaustion even with plenty of physical memory available.
This is very important.
Let's do some demos showing you the limits of memory.
Next, we're going to go to System Internals
and we're going to use a tool that Mark Russinovich has written.
It's called Test Limit.
It does all kinds of things to do nasty things to your PC.
One, we're going to look at minus M, which is leak memory in specified megabytes.
This is going to constantly tell Process, Test Limit,
it's going to talk to the operating system and say,
I want more commit memory.
And the operating system is going to respond
by taking that request for a commit limit and push it in the page file.
Now, that's what minus M is going to do.
And it's going to quickly grow the page file
and it's going to overwhelm the resources.
But you will see a herculean effort by the operating system to stay stable.
It's going to blow up, but it's going to try.
Now, I'm going to run Test Limit 64 minus M and one megabyte.
Now, let's come over and take a look at our memory.
And so right now you can see I've got 1.39 gigs of commit from everything,
the operating system, all the processes.
And that's what I'm guaranteeing between the page file and RAM,
I can handle that.
And I've got a limit up to about three gigs a limit.
Now, when I run this utility, it's going to slam this page file.
So let's go over and run it.
And here we go.
And you can see already we went from 1.3 to eight gigabytes.
And you can see we have plenty of physical memory.
Notice we are not having a problem with RAM.
But over here you can see already putting all kinds of pressure
on the memory manager.
The page file is too small and it's trying to expand it
to try to meet the needs of this current commit.
And it won't stop.
As soon as it gives it more, it asks for more.
So it's really interesting.
It's going to blow up here in just a minute.
And it will blow up the machine right here.
And there we go.
It blew up.
So our next demonstration of a memory problem will be using Test Limit.
This time we're going to force it into the working set,
not the page file directly.
So it's going to go in RAM.
And it's going to force RAM to go this extremely low level.
We'll see a lot of page fault deltas as a memory manager in desperation
tries to pull it out of a working set and put it into the page file.
Page file will grow to this enormous value.
And eventually it will blow up.
So let's take a look.
Now normally this is happening very fast.
If you watch, my available memory went to really low.
I'm paging out of my working set into the page file at a very high rate.
You can see my page file going.
My current limit is going clear up to max.
And we're quickly getting to out of resource memory exhaustion.
And this is because we're just constantly pushing memory
or asking that memory go into RAM.
And of course it pages it out, puts it in the page file.
And then the page file becomes exhausted.
So this will also go.
Now this is doing it very quickly.
In a real life scenario, this is happening very slowly
over the course of 24 hours, 48 hours, 72 hours.
So it doesn't have this dramatic effect.
We're doing it really fast because you don't want to sit here for 72 hours.
And watch this.
This is going to blow up here in just a minute.
You can take a look at test limit 64 here in Process Explorer
and see its private bytes value.
To my surprise, the virtual machine did survive
almost five minutes running at this extreme memory pressure.
I've blown up this box probably 10 times already doing the same thing.
So for some reason it was resilient.
Let's look at our understanding of page files.
So what is saved in a page file?
If I had a number of windows open and I had,
maybe in the very beginning when I launched the PC,
I had Notepad with this text in it.
And I hadn't used it for a while.
The memory manager would eventually look at this document
and it would make a decision should it page it to the page file.
Now what it would never do is take notepad.exe,
the actual file that runs Notepad,
and save that in the page file because it knows it's on the hard drive.
The only thing it would page to the page file
is a small amount of text inside Notepad.
So how does Windows set your page file size?
Well, it's pretty complex.
Minimum page file size varies based on your page file usage history.
The amount of RAM divided by 8,
and it only considers a maximum of 32 gigabytes.
And, very important, the crash dump setting you have chosen.
Maximum page file size is 3 times RAM,
or up to 4 GB, whichever is larger.
This is limited to the volume size divided by 8.
However, it can grow to 1 GB of free space on the volume
if required for your crash dump settings.
So it's very important to understand your crash dump settings.
You do that in System, Advanced Settings,
under Advanced tab, and then under Startup and Recovery.
Windows provides a variety of crash dump options.
So under where you see number 4 is you can pull that menu down
and you can choose a variety of crash dump settings.
On a desktop, this is not as critical.
On a server, this is very critical.
This also impacts your page file size.
So remember when I said in the lecture 3
that I would never call the page file virtual memory?
Well, you can see this is very confusing
because here we are looking at the page file
and Microsoft calls it virtual memory.
In the GUI, Microsoft hides the place that you would change
the setting for your page file way down.
You really have to be determined to get to there.
So I've opened up Control Panel.
I'm going to go to System.
I'm going to go to Advanced System.
And then I'm going to go to under where it says Performance,
go to Settings, and then go under the tab where it says Advanced.
And here, this is the first time I get to see my page file settings.
And you can see mine.
I've got two page files.
One's on an NVMe SSD and another one is on another SSD I have in here.
I'll talk about two page files in a minute.
One of the biggest misconceptions is setting the correct page file size.
So first of all, page file size depends on the system crash dump settings
and the peak usage or expected usage of the system commit charge.
Both considerations are unique to each system.
This is really true for servers, even systems that are identical.
This means that the page file size is also unique to each system
and cannot be generalized.
I am saying this word for word out of Microsoft's documentation,
and I put it on the slide so you can take a look.
So after reading Mark's input on this,
he says page file size should be when all applications are running
at what you feel is maximum.
Number two, if it's a server-based application,
have it running full tilt, all users on the application.
Stress the server or PC to what would be the maximum applications,
demands, etc.
Look at your current commit value.
Set the page file to double this value.
That's proper page file size.
So here's a couple little tidbits you didn't know about page file.
64-bit Windows can have page files that are up to 16 terabytes in size.
For all versions of Windows, it supports up to 16 page files,
but each page file has to be on a separate volume.
A couple considerations if you put, especially on servers,
multiple page files across multiple disks.
Remember, the page file that responds first is the one that's used,
so always using the fastest disks is most important.
Remember, only modified data that doesn't already exist on the disk
is ever put into a page file.
Often I want to understand better how an application works,
so I want to show you how I leverage Process Explorer in one example.
We could do this many different ways,
but I'll give you one example of how I leverage Process Explorer
and its features to better understand an application.
I'm going to use Chrome as an example.
You can see I have chrome.exe that's my parent for the browser,
and then I've got a ton of child processes.
What is this all about?
Now obviously I can go to select columns,
and I can choose a lot of metrics to analyze each process.
One of my favorites is the command line,
so I chose the command line, and I added that,
and I look at the parent process,
and I look at the switches and arguments that launch it,
and I can see it's definitely launching a profile, number two,
and that makes sense because I have a number of Chrome shortcuts
that launch under different credentials, so that makes sense.
I see the second, the child process, has to do with crash handling,
which makes sense, that is a very important part of Chrome.
The next one I'm not sure of, but the one below,
based on my switches and arguments, I can see this has to do with GPU,
and Chrome does support a GPU if you have it installed.
So obviously my curiosity is why so many child processes,
and why did Chrome choose this option of so many child processes?
Now the rest of the child processes seem more repetitive,
they seem to be pulling information based on some numerical value,
so I'm not quite sure why that is.
So you can see right now I have eight tabs open in Chrome.
Let me start turning those off,
and let's see if they are related to a child process.
So I'm going to kill that one, I'm going to end that tab,
and I see a red process, that means it's terminating.
I'm going to choose another tab, terminate it,
I can see a red process, so I can see right away that tabs,
every tab I open in Chrome is put in a separate child process.
That makes sense, that gives it stability and isolation.
So that sounds reasonable, and notice I'm killing more tabs,
and I see more red Chrome processes being terminated.
So I'm going to keep this up, and I'm going to go down just one tab,
so there I am.
You can see it takes a while for these processes to go.
I still have a lot of child processes there.
So now I'm going to turn my attention to my extensions,
and I'm going to use a tool called Extensity
that allows me to turn off the various Chrome,
third-party Chrome extensions that I have on my browser.
Start turning these off, and again we see a lot more red
showing up over here in my Chrome child processes,
and I'm going to go ahead and keep turning off Chrome extensions,
and you can see I'm shrinking in child processes.
So that tells me right away that Chrome is putting a lot of these
Chrome extensions into a separate, every Chrome extension
is put into their own child process.
That makes sense, isolation, separation, and stability in the Chrome browser.
Now I only have one tab open, and you can still see
I have quite a few Chrome child processes.
I'm going to exit the entire browser out,
and I want you to see how long it takes for Chrome to go away.
All right, I've closed out Chrome.
We can be sitting here for a long time.
You notice, according to Process Explorer,
Chrome is still running.
It is not running on my desktop.
I have asked Chrome to exit, and you can see
I'm ticking off the seconds, and Chrome has not went away.
This is very interesting in application behavior.
Process Explorer opens up and allows us to see
a whole new category, Processes,
with the introduction of Windows 8, 8.1, and Windows 10.
The teal color, if you'll notice in the color selection,
is called Immersive Processes.
Now these have had many names.
They were, in Windows 8, they were called Metro Apps.
Then they changed to Modern Apps.
Then they were also, in Process Explorer,
they're identified as Immersive Processes,
and they're also today called UWP,
Universal Windows Platform.
With all those confusing names, let's dive in and take a look at them.
Developing applications for Windows
is a very important foundational philosophy.
The most common way of developing applications
was using the Win32 system.
So Win32 APIs has been predominantly
the way that most application developers
have built and developed programs for Windows.
There's also the .NET Frameworks,
which is very popular for business applications.
There's also two not as well-known,
the Windows Presentation Foundation and the Windows Forum,
where everything is really moving to
is browser-based or cloud-based application.
Look at Office 365 as an example.
And then last but not least is the new framework
for applications shown to us in Windows 8.
They were called Metro Apps.
Then there was some kind of legal wrangling,
and then they were changed to Modern Apps.
Process Explorer shows us this whole framework of new apps
as Immersive Processes.
And I'm going to kind of stick with that term.
They're also known as Universal Windows Platform.
Now Microsoft is pushing this very heavily, as we'll see.
In the old days when you were writing desktop applications,
you were using C or C++
if you were developing Win32.
.NET used C Sharp and Visual Basic.
But under the Metro, first of all,
they built what's called the Windows Runtime APIs.
Notice they put a huge chunk of code
between the operating system or the kernel
and these applications.
That's going to be the major drawback
for these immersive-style apps.
But you can use XML, you can use C, C++, C Sharp.
So a lot of the same development tools
that we use to develop the old-style desktop apps,
you can still use to develop these new immersive processes.
With immersive processes,
the biggest change is the Universal Windows Platform,
or what is also known as Windows Runtime.
It was also labeled Windows RT.
So you'll see all of those very confusing terms
applied to this thick module
that lifts the applications further away
from the operating system or the kernel itself.
This has been one of the complaints
of application developers,
is they're basically sandboxed further and further
from the operating system.
Now Microsoft is moving its own internal applications
to immersive or to the Universal Windows Platform.
Every new version of Windows,
more and more of the internal applications
are moving this way.
So whether developers go this way or not,
Microsoft, so the Edge browser
is now totally in immersive process.
Cortana, Search, the Windows settings,
all of your new Windows settings,
Explorer, all of these new internal applications
are moving to the Universal Windows Platform.
Microsoft has been working very hard
to convince developers to move to the immersive architecture.
They have not done this well.
This has not been successful,
even though they're developing
their own internal apps in this direction.
They have not coaxed or convinced application developers
to move this direction.
Although Microsoft likes to talk about
how many apps it has in its app store,
if you've ever been in there, it's pretty sad.
Now, whether all of this is good or bad,
I'm not here to wrangle that out.
We'll let the developers make that decision,
but let's understand the foundation service process
that really makes up the runtime environment
for these applications.
When we open up Process Explorer,
we go to services.exe.
Remember, this is the very, very important
critical system process
that really launches all of our services.
Under svchost here,
and you'll see this is where
all of our immersive processes show up
as child to svchost.exe.
This is a very important service.
It's the foundational service
for all of the immersive apps.
If we open up the properties of that svchost,
we'll see that under services,
you'll see broker infrastructure service,
DCOM launch.
We'll see power,
the main power management system service.
We'll see system events broker.
All of these services lay the foundation
that run the immersive apps.
Immersive apps are treated significantly different
than the old-style Win32 applications
that you and I are more comfortable with.
One of the differences is the immersive applications
reside in an app container
that provides greater security,
and also they're subject to the process
lifecycle management.
This allows them to be suspended from the CPU.
They're actually running,
they're in memory,
but they're suspended
so they don't take CPU time,
they don't drain the battery,
and they can be resumed and suspended
upon your interaction with that app.
This is all controlled by the runtime broker service,
and we'll see that as we look at Process Explorer.
So the process lifecycle management,
the PLM,
basically here you have an app that's not running,
then it's activated,
and as long as it's running in,
if it's running in the foreground,
it will be allowed to run and use CPU time.
If it's moved to the background,
it then immediately like a timer goes on.
And if you've got it into the background,
after a certain period of time,
it will then go into the suspended mode.
And then if you bring it forefront,
it will then be reactivated,
and it will actually use CPU time again.
This drastically improves battery life
if you're on a mobile device,
and it also provides greater security
because we're in an app container.
We're kind of like in a virtualization box.
So this brings us to a new interesting,
the process lifecycle management
also introduces a new file
called the swapfile.sys.
So all immersive apps,
just immersive app,
will, when they're in that suspended process
or the memory manager feels like
there's modified pages
that need to go out to the disk,
it will not send them to the page file.
Instead, immersive apps
will use the swapfile.sys.
So they will be written to the swapfile.sys.
So swapfile.sys is currently used
for suspend remove of immersive apps,
page files out of RAM,
modified pages moved out of RAM
into the swapfile.sys.
So if you look in the C drive here
in the same location, the root of C,
where my pagefile.sys is,
is also the swapfile.sys.
One handles immersive apps,
the other one handles everything else.
The swapfile.sys and the regular page file
have different usage patterns
and different requirements
with regards to space reservation,
dynamic growth, read and write policies.
So they're very different.
Measuring the impact of processes
on the CPU is really important.
So I want to go over some of those metrics
to clear up some of the potential confusion.
So in Process Explorer,
you can choose the CPU cycles metric.
That is the total number of kernel mode
and user mode CPU cycles
consumed by the process
since the process was launched.
What about CPU cycles delta?
Remember, delta is always related
to the update cycle of Process Explorer,
which is one second.
So this simply means how many CPU cycles
user mode and kernel mode in one second.
I'm going to leave the, on context switches,
I'm going to leave the total description up here
because this is the total technical description
of context switch.
But basically, remember, context switch
is when the threads go from waiting to running.
They're executed.
Whenever threads are executed,
that is a context switch.
Context switch delta, again, it's a delta.
So it's based on the update display time.
The default for Process Explorer is one second.
So that means threads were executed
from running to waiting in one second.
So that would be context switch delta.
When I am looking for the most accurate measure
of CPU usage by a process,
this is my favorite metric.
Process Explorer allows us to look
at some elements of the security
of the operating system.
In its color selection,
it will denote, if you check it,
packed images or a violet color
that will indicate packed images.
Process Explorer uses a heuristic
to identify program files
that may contain executable code
in compressed form or encrypted form
or both.
Malware uses this technique
to evaluate anti-malware
and then unpacks itself in memory and executes.
This sometimes produces false positives,
so just be aware of that.
Process Explorer also inspects
for valid digital signatures
on executables in the process and DLLs.
So under options,
we can check for verify signature image
and that will verify all executable files
in the process and every DLL.
So if I go ahead and enable
inspect digital signatures
and I select Chrome,
and of course it will show me
chrome.exe, is it valid?
Does it have a valid signature?
But if you go into the lower pane,
you show the lower pane,
it will actually also inspect those also.
So I'm going to go up to options
and I'm going to verify signature.
Go ahead and turn that on
and notice it puts a column
and it will begin to show
the verified signatures
for all of the executables
that launch the process.
But I want to know that all the files
in that process are good.
So I'm going to come down here to,
let's go to Chrome,
and I'm going to go show lower pane
and I can see that the DLLs
are now being verified.
So all the DLLs are being verified
that they have digital signatures.
One of the most fantastic features
of Process Explorer
and some of the system internal tools
was Mark was able to negotiate with Google
who owns Virustotal.com
to actually allow Microsoft's tools
to use the APIs
and incorporate Virustotal.com
into the tools.
With this integration,
Virustotal inspects items
with over 70 antivirus scanners
and URL domain blacklist services
in addition to a myriad of tools.
So once you go to options
and you check Virustotal.com,
every item in the process
that's an executable and DLL
will be submitted with a SHA1 hash
of that image.
It doesn't send the file itself,
it sends a hash to Virustotal.com.
It will run the 70 scanners upon it
and then send the results
to Process Explorer.
This will also check your DLLs.
When you see your results in the column,
the zero means it did not get
a positive hit on those scanners.
So here you can see at the very top
zero slash 69.
So there were 69 scanners
ran against that hash.
There were zero hits,
positive hits.
That's pretty much a clean executable.
Here I show a positive, false positive
where I've looked at my DLLs
and I've got one of 70.
So I had one positive hit
on that hash for that DLL
run against 70 scanners.
That usually doesn't raise flags
when it's one against 70.
Where we start looking seriously
is when it's three or four or five.
Five positive hits,
you better go take a look at it.
One of the right mouse click features
in Process Explorer is Search Online.
You can take a process
and the executable
that launches that process
and say, search online
and see if you can find more information
about this executable.
Be aware, this has blossomed
a whole series of websites
that you cannot trust
with their information.
So be very careful
with online searches of executables.
Microsoft Mechanics
www.microsoft.com
