├── .allstar
└── binary_artifacts.yaml
├── .gitattributes
├── .gitignore
├── AUTHORS
├── CONTRIBUTING
├── CONTRIBUTORS
├── CompatibilityManifest.man
├── DelayedCreateProcess
├── DelayedCreateProcess.cpp
└── make.bat
├── DummyChrome
├── DummyChrome.cpp
├── DummyChrome.sln
├── DummyChrome.vcxproj
├── DummyChrome.vcxproj.filters
├── ReadMe.md
├── dllmain.cpp
├── stdafx.cpp
└── stdafx.h
├── ETWEventDemo
├── ETWEventDemo.cpp
├── ETWEventDemo.sln
├── ETWEventDemo.vcxproj
├── ETWEventDemo.vcxproj.filters
├── ReadMe.txt
├── stdafx.cpp
├── stdafx.h
└── targetver.h
├── ETWInsights
├── ETWInsights.sln
├── ETWInsights.vcxproj
├── ETWInsights.vcxproj.filters
├── README.md
├── base
│ ├── base.h
│ ├── base.vcxproj
│ ├── base.vcxproj.filters
│ ├── binary_search.h
│ ├── child_process.cc
│ ├── child_process.h
│ ├── command_line.cc
│ ├── command_line.h
│ ├── error_string.cc
│ ├── error_string.h
│ ├── file.cc
│ ├── file.h
│ ├── history.h
│ ├── logging.cc
│ ├── logging.h
│ ├── numeric_conversions.cc
│ ├── numeric_conversions.h
│ ├── string_utils.cc
│ ├── string_utils.h
│ └── types.h
├── etw_reader
│ ├── etw_reader.cc
│ ├── etw_reader.h
│ ├── etw_reader.vcxproj
│ ├── etw_reader.vcxproj.filters
│ ├── generate_history_from_trace.cc
│ ├── generate_history_from_trace.h
│ ├── stack.h
│ ├── system_history.cc
│ ├── system_history.h
│ └── thread_history.h
└── flame_graph
│ ├── clean_stack.cc
│ ├── clean_stack.h
│ ├── flame_graph.cc
│ ├── flame_graph.h
│ ├── flame_graph.vcxproj
│ ├── flame_graph.vcxproj.filters
│ └── main.cc
├── ETWProviders
├── ETWProviders.cpp
├── ETWProviders.rc
├── ETWProviders.sln
├── ETWProviders.vcxproj
├── ETWProviders.vcxproj.filters
├── ReadMe.txt
├── dllmain.cpp
├── etwprof.cpp
├── etwproviders.man
├── resource.h
├── stdafx.cpp
├── stdafx.h
└── targetver.h
├── EventEmitter
├── EventEmitter.cpp
├── EventEmitter.h
├── EventEmitter.ico
├── EventEmitter.rc
├── EventEmitter.sln
├── EventEmitter.vcxproj
├── EventEmitter.vcxproj.filters
├── ReadMe.txt
├── Resource.h
├── small.ico
├── stdafx.cpp
├── stdafx.h
└── targetver.h
├── LICENSE
├── LabScripts
├── ETWPMCDemo
│ ├── .gitignore
│ ├── ConditionalCount
│ │ ├── ConditionalCount.cpp
│ │ ├── ConditionalCount.sln
│ │ ├── ConditionalCount.vcxproj
│ │ ├── ConditionalCount.vcxproj.filters
│ │ ├── OtherFile.cpp
│ │ └── ReadMe.txt
│ ├── etwpmc_parser.py
│ └── etwpmc_record.bat
├── GPUTracing
│ ├── GPUUsageByProcess.wpaProfile
│ ├── GPUUsageDetails.wpaProfile
│ ├── ReadMe.txt
│ ├── start_tracing.bat
│ └── stop_tracing.bat
└── GeneralTracing
│ ├── .gitignore
│ ├── CPUDetailsByProcess.wpaProfile
│ ├── CPUSummaryByProcess.wpaProfile
│ ├── CreateExporterConfig.py
│ ├── GPUDetailsByProcess.wpaProfile
│ ├── GPUSummaryByProcess.wpaProfile
│ ├── PrivateWorkingSetSummaryByProcess.wpaProfile
│ ├── ReadMe.txt
│ ├── SummarizeData.py
│ ├── set_vars.bat
│ ├── start_tracing.bat
│ └── stop_tracing.bat
├── PowerMon
├── PowerMon.cpp
├── PowerMon.sln
├── PowerMon.vcxproj
├── PowerMon.vcxproj.filters
├── PowerStatus.cpp
├── PowerStatus.h
├── stdafx.cpp
├── stdafx.h
└── targetver.h
├── README
├── RetrieveSymbols
├── ReadMe.txt
├── RetrieveSymbols.cpp
├── RetrieveSymbols.sln
├── RetrieveSymbols.vcxproj
└── RetrieveSymbols.vcxproj.filters
├── SignBinaries.bat
├── TraceProcessors
├── CPUSummary
│ ├── App.config
│ ├── CPUSummary.cs
│ ├── CPUSummary.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── HeapSnapshotCompare
│ ├── App.config
│ ├── HeapSnapshotCompare.cs
│ ├── HeapSnapshotCompare.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── IdentifyChromeProcesses
│ ├── App.config
│ ├── IdentifyChromeProcesses.cs
│ ├── IdentifyChromeProcesses.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── IdleWakeups
│ ├── IdleWakeups.cs
│ ├── IdleWakeups.csproj
│ └── IdleWakeups.sln
├── TraceProcessors.sln
└── VideoConfCPUCounters
│ ├── App.config
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── VideoConfCPUCounters.cs
│ ├── VideoConfCPUCounters.csproj
│ ├── etwpmc_record.bat
│ └── packages.config
├── UIforETW
├── About.h
├── CPUFrequency.cpp
├── CPUFrequency.h
├── ChildProcess.cpp
├── ChildProcess.h
├── DirectoryMonitor.cpp
├── DirectoryMonitor.h
├── KeyLoggerThread.cpp
├── KeyLoggerThread.h
├── PowerStatus.cpp
├── PowerStatus.h
├── ProcessChecks.cpp
├── ReadMe.md
├── Resource.h
├── Settings.cpp
├── Settings.h
├── SpinALot32.asm
├── SpinALot64.asm
├── StackWalkFlags.txt
├── StrictRules.ruleset
├── Support.cpp
├── TraceLoggingSupport.cpp
├── TraceLoggingSupport.h
├── UIforETW.cpp
├── UIforETW.h
├── UIforETW.rc
├── UIforETW.sln
├── UIforETW.vcxproj
├── UIforETW.vcxproj.filters
├── UIforETWDlg.cpp
├── UIforETWDlg.h
├── Utility.cpp
├── Utility.h
├── Version.h
├── VersionChecker.cpp
├── VersionChecker.h
├── VersionCopy.h
├── WorkingSet.cpp
├── WorkingSet.h
├── build_static.bat
├── res
│ ├── UIforETW.ico
│ └── UIforETW.rc2
├── stdafx.cpp
├── stdafx.h
└── targetver.h
├── bin
├── .gitignore
├── CPUByCommandLine.py
├── CPUUsageByCommandLine.wpaProfile
├── CPUUsageByProcess.wpaProfile
├── ETWPackSymbols.py
├── ETWTimeBuild2005.bat
├── ETWTimeBuild2010.bat
├── ExportCPUUsageSampled.wpaProfile
├── FindRandomasciiProfilePresets.py
├── HeapAnalysis.wpaProfile
├── HeapSnapshot.wpaProfile
├── IdentifyChromeProcesses.py
├── Python.sln
├── StripChromeSymbols.py
├── TestIdentifyChromeProcesses.bat
├── TransientProcessTree.wpaProfile
├── UserMarks.wpaProfile
├── VirtualFreeStacks.py
├── XperfProcessParentage.py
├── XperfProcessParentage.wpaProfile
├── bin.pyproj
├── chrome_events_win.man
├── chrome_regions_of_interest.xml
├── etw_cpuusage_longterm.bat
├── etw_gdi_longterm.bat
├── etw_handles_longterm.bat
├── etw_processes_longterm.bat
├── etwcirc.bat
├── etwcommonsettings.bat
├── etwheap.bat
├── etwheapsnapshot.bat
├── etwpmc_parser.py
├── etwpmc_record.bat
├── etwproviders.man
├── etwrecord.bat
├── etwregister.bat
├── etwsamplefast.bat
├── etwsamplenormal.bat
├── etwsampleslow.bat
├── metatrace.bat
├── readme.txt
├── startup10.wpaProfile
├── summarize_timer_intervals.py
├── timer_intervals.wpaProfile
├── trace_timer_intervals.bat
└── xperf_to_collapsedstacks.py
├── excludecopy.txt
├── include
└── ETWProviders
│ └── etwprof.h
├── make_zip_file.py
├── package_etw.bat
├── rename_to_version.py
├── third_party
├── .gitignore
├── dbghelp.dll
├── license.txt
├── pdbcopy.exe
├── redist.txt
├── symsrv.dll
└── x64
│ ├── dbghelp.dll
│ ├── redist.txt
│ └── symsrv.dll
└── vs-chromium-project.txt
/.allstar/binary_artifacts.yaml:
--------------------------------------------------------------------------------
1 | # Ignore reason: These signed files all come from a Microsoft SDK and are needed for UIforETW's functionality.
2 | ignorePaths:
3 | - third_party/dbghelp.dll
4 | - third_party/pdbcopy.exe
5 | - third_party/symsrv.dll
6 | - third_party/x64/dbghelp.dll
7 | - third_party/x64/symsrv.dll
8 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.bak
2 | *.aps
3 | # wpaexporter drops these
4 | *.csv
5 | *.etl
6 | *.obj
7 | *.exe
8 | *.exp
9 | *.ilk
10 | *.opensdf
11 | *.pyc
12 | *.sdf
13 | *.suo
14 | *.svg
15 | *.pdb
16 | *.user
17 | *.launchSettings.json
18 | # New Visual Studio 2015 intellisense DB files
19 | # http://blogs.msdn.com/b/vcblog/archive/2015/11/11/new-improved-and-faster-database-engine.aspx
20 | *.VC.db
21 | symsrv.yes
22 | pmc_counters_test.txt
23 |
24 | # Binaries that are built instead of committed as of commit ea32da8
25 | bin/DummyChrome.dll
26 | bin/ETWProviders.dll
27 | bin/ETWProviders64.dll
28 | bin/ETWProvidersARM64.dll
29 | lib/*
30 |
31 | # GPUView likes to drop these files when run.
32 | FuncStats.txt
33 | GuidStats.txt
34 | Log.txt
35 | present.txt
36 | *.lastcodeanalysissucceeded
37 |
38 | *Generated*
39 |
40 | # VS 2015 drops these
41 | *.VC.opendb
42 | .vs/
43 |
44 | # Temporary flamegraph files
45 | flamegraph.txt
46 |
47 | #Created by package_etw.bat
48 | etwpackage/
49 | etwpackage*.zip
50 | etwsymbols*.zip
51 | sourceindex.txt
52 |
53 | # Avoid shipping nuget files and others in /obj/ directories.
54 | obj/
55 |
56 | Debug/
57 | Release/
58 | *DoNotShip/
59 | ipch/
60 |
61 | # Recommended changes for working with nuget packages
62 |
63 | # Ignore NuGet Packages
64 | *.nupkg
65 |
66 | # The packages folder can be ignored because of Package Restore
67 | **/[Pp]ackages/*
68 |
69 | # except build/, which is used as an MSBuild target.
70 | !**/[Pp]ackages/build/
71 |
72 | # Uncomment if necessary however generally it will be regenerated when needed
73 | #!**/[Pp]ackages/repositories.config
74 |
75 | # NuGet v3's project.json files produces more ignorable files
76 | *.nuget.props
77 | *.nuget.targets
78 |
79 | # Ignore other intermediate files that NuGet might create. project.lock.json is used in conjunction
80 | # with project.json (NuGet v3); project.assets.json is used in conjunction with the PackageReference
81 | # format (NuGet v4 and .NET Core).
82 | project.lock.json
83 | project.assets.json
84 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | # This is the official list of The UIforETW Project Authors
2 | # for copyright purposes.
3 | # This file is distinct from the CONTRIBUTORS files.
4 | # See the latter for an explanation.
5 |
6 | # Names should be added to this file as
7 | # Name or Organization
8 | # Email addresses for individuals are tracked elsewhere to avoid spam.
9 |
10 | Google Inc.
11 | Kristof Mattei
12 | Alexander Riccio
13 | Bradley Grainger
14 | Michael Winterberg
15 | Suresh Kumar Ponnusamy
16 |
--------------------------------------------------------------------------------
/CONTRIBUTING:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/UIforETW/26f61a73bb07f951dd4cae411464774d0dae6cc8/CONTRIBUTING
--------------------------------------------------------------------------------
/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This is the official list of people who can contribute
2 | # (and who have contributed) code to the UIforETW project
3 | # repository.
4 | # The AUTHORS file lists the copyright holders; this file
5 | # lists people. For example, Google employees are listed here
6 | # but not in AUTHORS, because Google holds the copyright.
7 | #
8 |
9 | Google Inc.
10 | Bruce Dawson
11 | Georges Khalil
12 |
13 | Kristof Mattei
14 | Alexander Riccio
15 | Bradley Grainger
16 | Michael Winterberg
17 | Suresh Kumar Ponnusamy
18 | Chris Davis
--------------------------------------------------------------------------------
/CompatibilityManifest.man:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/DelayedCreateProcess/DelayedCreateProcess.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2019 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 |
20 | int main(int argc, char* argv[])
21 | {
22 | if (argc < 2) {
23 | printf("This program creates a process in a suspended state, prints its PID"
24 | " so that heap tracing can be enabled, and resumes the thread after a"
25 | " brief delay. This helps etwheapsnapshot.bat trace a process from"
26 | " birth. Only the PID is printed to stdout (for easy capture from a"
27 | " batch file) - the rest is printed to stderr.\n");
28 | printf("Usage: %s proc_name.exe [delay_ms]\n", argv[0]);
29 | return 0;
30 | }
31 |
32 | const char* name = argv[1];
33 | STARTUPINFOA startup_info = {sizeof(startup_info)};
34 | PROCESS_INFORMATION process_info = {};
35 | LARGE_INTEGER start;
36 | QueryPerformanceCounter(&start);
37 | BOOL result = CreateProcessA(name, nullptr, nullptr, nullptr, FALSE,
38 | CREATE_SUSPENDED, nullptr, nullptr, &startup_info,
39 | &process_info);
40 |
41 | if (!result) {
42 | fprintf(stderr, "CreateProcess failed.\n");
43 | return -1;
44 | }
45 |
46 | // Print the process ID to stdout for consumption by a batch file.
47 | printf("%d\n", process_info.dwProcessId);
48 | // Print the process to stderr so that the output can be seen.
49 | fprintf(stderr, "PID is %d.\n", process_info.dwProcessId);
50 |
51 | DWORD delay = 10000;
52 | if (argc >= 3)
53 | delay = atoi(argv[2]);
54 | fprintf(stderr, "Waiting %1.3f s before letting the process run.\n", delay / 1e3);
55 | Sleep(delay);
56 | // Resume the main thread, thus starting the process.
57 | ResumeThread(process_info.hThread);
58 | fprintf(stderr, "Process is now running.\n");
59 |
60 | // When this process is destroyed all its handles to the new process will be
61 | // cleaned up, so no cleanup is necessary.
62 | }
63 |
--------------------------------------------------------------------------------
/DelayedCreateProcess/make.bat:
--------------------------------------------------------------------------------
1 | cl %~dp0DelayedCreateProcess.cpp /link /out:%~dp0..\bin\DelayedCreateProcess.exe
2 |
--------------------------------------------------------------------------------
/DummyChrome/DummyChrome.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "stdafx.h"
18 |
19 |
20 |
--------------------------------------------------------------------------------
/DummyChrome/DummyChrome.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DummyChrome", "DummyChrome.vcxproj", "{ECC4778A-713B-4B02-AAFD-DD09DE29C248}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {ECC4778A-713B-4B02-AAFD-DD09DE29C248}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {ECC4778A-713B-4B02-AAFD-DD09DE29C248}.Debug|Win32.Build.0 = Debug|Win32
16 | {ECC4778A-713B-4B02-AAFD-DD09DE29C248}.Release|Win32.ActiveCfg = Release|Win32
17 | {ECC4778A-713B-4B02-AAFD-DD09DE29C248}.Release|Win32.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/DummyChrome/DummyChrome.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 | Source Files
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | Resource Files
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/DummyChrome/ReadMe.md:
--------------------------------------------------------------------------------
1 | This project exists solely to compile in Chrome's ETW manifest so that DummyChrome.dll can be used to register Chrome's ETW providers.
2 | This is much simpler than tracking down where Chrome is installed, especially during the early days when not all versions of Chrome have ETW providers.
3 |
--------------------------------------------------------------------------------
/DummyChrome/dllmain.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "stdafx.h"
18 |
19 | BOOL APIENTRY DllMain( HMODULE hModule,
20 | DWORD ul_reason_for_call,
21 | LPVOID lpReserved
22 | )
23 | {
24 | switch (ul_reason_for_call)
25 | {
26 | case DLL_PROCESS_ATTACH:
27 | case DLL_THREAD_ATTACH:
28 | case DLL_THREAD_DETACH:
29 | case DLL_PROCESS_DETACH:
30 | break;
31 | }
32 | return TRUE;
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/DummyChrome/stdafx.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 |
18 | #include "stdafx.h"
19 |
--------------------------------------------------------------------------------
/DummyChrome/stdafx.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
20 | // Windows Header Files:
21 | #include
22 |
--------------------------------------------------------------------------------
/ETWEventDemo/ETWEventDemo.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "stdafx.h"
18 | #include
19 | #include "ETWProviders\etwprof.h"
20 |
21 | /*
22 | This demonstrates how to use ETWProviders*.dll to emit custom ETW events.
23 | These events will be recorded by UIforETW, and the default WPA startup
24 | profile configured by UIforETW will display them in the Generic Events
25 | section.
26 |
27 | See this blog post for an early mention of these providers.
28 |
29 | https://randomascii.wordpress.com/2011/08/18/xperf-basics-recording-a-trace/
30 | */
31 |
32 | // Pause for a short period of time with the CPU idle.
33 | __declspec(noinline) void IdleDelay()
34 | {
35 | Sleep(10);
36 | }
37 |
38 | // Pause for a short period of time with the CPU busy.
39 | __declspec(noinline) void BusyDelay()
40 | {
41 | DWORD startTick = GetTickCount();
42 |
43 | for (;;)
44 | {
45 | DWORD elapsed = GetTickCount() - startTick;
46 | if (elapsed > 10)
47 | break;
48 | }
49 | }
50 |
51 | int _tmain(int argc, _TCHAR* argv[])
52 | {
53 | printf("Emitting custom ETW events that can be recorded with etwrecord.bat\n");
54 | CETWScope timer("main");
55 | for (int i = 0; i < 40; ++i)
56 | {
57 | ETWMarkPrintf("This is loop %d", i);
58 | ETWRenderFrameMark();
59 | // Simulating code that does something.
60 | IdleDelay();
61 | BusyDelay();
62 | }
63 |
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/ETWEventDemo/ETWEventDemo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ETWEventDemo", "ETWEventDemo.vcxproj", "{2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Debug|x64 = Debug|x64
12 | Release|Win32 = Release|Win32
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Debug|Win32.ActiveCfg = Debug|Win32
17 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Debug|Win32.Build.0 = Debug|Win32
18 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Debug|x64.ActiveCfg = Debug|x64
19 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Debug|x64.Build.0 = Debug|x64
20 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Release|Win32.ActiveCfg = Release|Win32
21 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Release|Win32.Build.0 = Release|Win32
22 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Release|x64.ActiveCfg = Release|x64
23 | {2AA7F923-CF20-4BAE-9C01-1FAE9CAF842F}.Release|x64.Build.0 = Release|x64
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/ETWEventDemo/ETWEventDemo.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 |
--------------------------------------------------------------------------------
/ETWEventDemo/ReadMe.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/UIforETW/26f61a73bb07f951dd4cae411464774d0dae6cc8/ETWEventDemo/ReadMe.txt
--------------------------------------------------------------------------------
/ETWEventDemo/stdafx.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "stdafx.h"
18 |
--------------------------------------------------------------------------------
/ETWEventDemo/stdafx.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include "targetver.h"
20 |
21 | #include
22 | #include
23 |
--------------------------------------------------------------------------------
/ETWEventDemo/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Including SDKDDKVer.h defines the highest available Windows platform.
4 |
5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7 |
8 | #include
9 |
--------------------------------------------------------------------------------
/ETWInsights/ETWInsights.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "base\base.vcxproj", "{637388CA-E6E9-4D38-8DC9-CC2FE937DE24}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "etw_reader", "etw_reader\etw_reader.vcxproj", "{E1FCFE0C-B8CB-4516-9F46-54C1F73A9601}"
9 | ProjectSection(ProjectDependencies) = postProject
10 | {637388CA-E6E9-4D38-8DC9-CC2FE937DE24} = {637388CA-E6E9-4D38-8DC9-CC2FE937DE24}
11 | EndProjectSection
12 | EndProject
13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flame_graph", "flame_graph\flame_graph.vcxproj", "{EE253535-588A-4ABC-A65E-8DE45E240D7F}"
14 | ProjectSection(ProjectDependencies) = postProject
15 | {E1FCFE0C-B8CB-4516-9F46-54C1F73A9601} = {E1FCFE0C-B8CB-4516-9F46-54C1F73A9601}
16 | {637388CA-E6E9-4D38-8DC9-CC2FE937DE24} = {637388CA-E6E9-4D38-8DC9-CC2FE937DE24}
17 | EndProjectSection
18 | EndProject
19 | Global
20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
21 | Debug|Win32 = Debug|Win32
22 | Release|Win32 = Release|Win32
23 | EndGlobalSection
24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
25 | {637388CA-E6E9-4D38-8DC9-CC2FE937DE24}.Debug|Win32.ActiveCfg = Debug|Win32
26 | {637388CA-E6E9-4D38-8DC9-CC2FE937DE24}.Debug|Win32.Build.0 = Debug|Win32
27 | {637388CA-E6E9-4D38-8DC9-CC2FE937DE24}.Release|Win32.ActiveCfg = Release|Win32
28 | {637388CA-E6E9-4D38-8DC9-CC2FE937DE24}.Release|Win32.Build.0 = Release|Win32
29 | {E1FCFE0C-B8CB-4516-9F46-54C1F73A9601}.Debug|Win32.ActiveCfg = Debug|Win32
30 | {E1FCFE0C-B8CB-4516-9F46-54C1F73A9601}.Debug|Win32.Build.0 = Debug|Win32
31 | {E1FCFE0C-B8CB-4516-9F46-54C1F73A9601}.Release|Win32.ActiveCfg = Release|Win32
32 | {E1FCFE0C-B8CB-4516-9F46-54C1F73A9601}.Release|Win32.Build.0 = Release|Win32
33 | {EE253535-588A-4ABC-A65E-8DE45E240D7F}.Debug|Win32.ActiveCfg = Debug|Win32
34 | {EE253535-588A-4ABC-A65E-8DE45E240D7F}.Debug|Win32.Build.0 = Debug|Win32
35 | {EE253535-588A-4ABC-A65E-8DE45E240D7F}.Release|Win32.ActiveCfg = Release|Win32
36 | {EE253535-588A-4ABC-A65E-8DE45E240D7F}.Release|Win32.Build.0 = Release|Win32
37 | EndGlobalSection
38 | GlobalSection(SolutionProperties) = preSolution
39 | HideSolutionNode = FALSE
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/ETWInsights/ETWInsights.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ETWInsights/README.md:
--------------------------------------------------------------------------------
1 | # ETWInsights
2 |
3 | ## flame_graph
4 |
5 | flame_graph is a command-line tool to generate a
6 | [flame graph](http://www.brendangregg.com/flamegraphs.html) from an ETW trace.
7 |
8 | Usage: `flame_graph.exe --trace [options]`
9 |
10 | Options:
11 |
12 | - `--process_name`: Only include stacks from processes with the specified name.
13 | - `--tid`: Only include stacks from the specified thread.
14 | - `--start_ts`: Only include stacks that occurred after the specified timestamp.
15 | - `--end_ts`: Only include stacks that occurred before the specified timestamp.
16 | - `--out`: Output file path. Default: .flamegraph.txt
17 |
18 | Timestamps are a number of microseconds elapsed since the beginning of the
19 | trace.
20 |
21 | `flame_graph.exe` produces a text file that tells how much time was spent in
22 | each call stack. To convert this text file to a nice-looking SVG report, use
23 | this [perl script](https://github.com/brendangregg/FlameGraph/blob/master/flamegraph.pl).
24 |
--------------------------------------------------------------------------------
/ETWInsights/base/base.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | // Macro to disable the copy constructor and assignment operator.
20 | // Must be placed with the private declarations of a class.
21 | #define DISALLOW_COPY_AND_ASSIGN(ClassType) \
22 | ClassType(const ClassType&); \
23 | void operator=(const ClassType&)
24 |
--------------------------------------------------------------------------------
/ETWInsights/base/base.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 | Header Files
41 |
42 |
43 | Header Files
44 |
45 |
46 | Header Files
47 |
48 |
49 | Header Files
50 |
51 |
52 |
53 |
54 | Source Files
55 |
56 |
57 | Source Files
58 |
59 |
60 | Source Files
61 |
62 |
63 | Source Files
64 |
65 |
66 | Source Files
67 |
68 |
69 | Source Files
70 |
71 |
72 | Source Files
73 |
74 |
75 |
--------------------------------------------------------------------------------
/ETWInsights/base/binary_search.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | namespace base {
23 |
24 | // Finds the last element of a vector that compares smaller or equal to |val|.
25 | // @param vec the vector in which to search.
26 | // @param val the value used for comparison.
27 | // @param comparator the comparison function or function object.
28 | // @returns an iterator to the last element of |vec| that is smaller or equal
29 | // to |val|, of .end() if none exists.
30 | template
33 | auto FindSmallerOrEqual(container_type& vec,
34 | comparison_value_type& val,
35 | comparator_type comparator) -> decltype(vec.begin()) {
36 | auto it = std::upper_bound(vec.begin(), vec.end(), val, comparator);
37 | if (it == vec.begin())
38 | return vec.end();
39 |
40 | --it;
41 |
42 | return it;
43 | }
44 |
45 | } // namespace base
46 |
--------------------------------------------------------------------------------
/ETWInsights/base/child_process.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #define WIN32_LEAN_AND_MEAN
20 | #include
21 |
22 | #include
23 | #include
24 |
25 | #include "base/base.h"
26 |
27 | namespace base {
28 |
29 | // This class encapsulates running a child process and writing its output to a
30 | // file. Typical usage is:
31 | // ChildProcess child();
32 | // child.SetOutputPath(L"output.txt");
33 | // child.Run(L"exename.exe -arg value");
34 | // child.WaitForCompletion();
35 | // Run returns immediately. The destructor, GetExitCode(), and
36 | // WaitForCompletion() will all wait for the process to exit.
37 |
38 | class ChildProcess {
39 | public:
40 | ChildProcess();
41 | // This waits for the child process to terminate.
42 | ~ChildProcess();
43 |
44 | // Sets the path to which output will be written.
45 | void SetOutputPath(const std::wstring& output_path) {
46 | output_path_ = output_path;
47 | }
48 |
49 | // Returns true if the process started. This function returns
50 | // immediately without waiting for process completion.
51 | _Pre_satisfies_(!(this->hProcess_)) bool Run(const std::wstring& command);
52 |
53 | // This can be called even if the process doesn't start, but it will return
54 | // zero. If the process is still running it will wait until the process
55 | // returns and then get the exit code.
56 | DWORD GetExitCode();
57 |
58 | // Waits for the process to complete its execution. This is called by the
59 | // destructor so calling it is strictly optional.
60 | void WaitForCompletion();
61 |
62 | private:
63 | // Process, thread, and event handles have an uninitialized state of zero.
64 | // Files have an uninitialized state of INVALID_HANDLE_VALUE. Yay Windows!
65 | HANDLE hProcess_ = 0;
66 |
67 | // Output handles for the child process.
68 | HANDLE hStdOutput_ = INVALID_HANDLE_VALUE;
69 | HANDLE hStdError_ = INVALID_HANDLE_VALUE;
70 | HANDLE hStdInput_ = INVALID_HANDLE_VALUE;
71 |
72 | // Output path.
73 | std::wstring output_path_;
74 |
75 | DISALLOW_COPY_AND_ASSIGN(ChildProcess);
76 | };
77 |
78 | } // namespace base
79 |
--------------------------------------------------------------------------------
/ETWInsights/base/command_line.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "base/command_line.h"
18 |
19 | #include "base/string_utils.h"
20 |
21 | namespace base {
22 |
23 | namespace {
24 |
25 | const wchar_t kSwitchNamePrefix[] = L"--";
26 | const size_t kSwitchNamePrefixLength =
27 | (sizeof(kSwitchNamePrefix) / sizeof(wchar_t)) - 1;
28 |
29 | void ParseCommandLine(
30 | int argc,
31 | wchar_t* argv[],
32 | std::unordered_map* switches) {
33 | std::wstring current_switch_name;
34 | for (int i = 0; i < argc; ++i) {
35 | std::wstring token(argv[i]);
36 | // Check if this is a switch name.
37 | if (base::WStringBeginsWith(token, kSwitchNamePrefix)) {
38 | // Add the previous switch name to the switch map.
39 | if (!current_switch_name.empty())
40 | switches->insert({current_switch_name, std::wstring()});
41 |
42 | // Keep track of the name of the current switch.
43 | current_switch_name = token.substr(kSwitchNamePrefixLength);
44 | } else if (!current_switch_name.empty()) {
45 | // This a switch value. Add it to the switch map with its name.
46 | switches->insert({current_switch_name, token});
47 | current_switch_name.clear();
48 | }
49 | }
50 |
51 | // If necessary, add the last switch name to the map.
52 | if (!current_switch_name.empty())
53 | switches->insert({current_switch_name, std::wstring()});
54 | }
55 |
56 | } // namespace
57 |
58 | CommandLine::CommandLine(int argc, wchar_t* argv[]) {
59 | ParseCommandLine(argc, argv, &switches_);
60 | }
61 |
62 | bool CommandLine::HasSwitch(const std::wstring& switch_name) const {
63 | return switches_.find(switch_name) != switches_.end();
64 | }
65 |
66 | std::wstring CommandLine::GetSwitchValue(
67 | const std::wstring& switch_name) const {
68 | auto look = switches_.find(switch_name);
69 | if (look == switches_.end())
70 | return std::wstring();
71 |
72 | return look->second;
73 | }
74 |
75 | } // namespace base
76 |
--------------------------------------------------------------------------------
/ETWInsights/base/command_line.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | #include "base/base.h"
23 |
24 | namespace base {
25 |
26 | class CommandLine {
27 | public:
28 | // Constructs a command line from an argument list.
29 | // @param argc Number of arguments.
30 | // @param argv Arguments.
31 | CommandLine(int argc, wchar_t* argv[]);
32 |
33 | // @param switch_name Name of a switch.
34 | // @returns true if the command line contains the given switch.
35 | bool HasSwitch(const std::wstring& switch_name) const;
36 |
37 | // @param switch_name Name of a switch.
38 | // @returns the value associated with the switch, or an empty string if no
39 | // value was specified for the switch in the command line.
40 | std::wstring GetSwitchValue(const std::wstring& switch_name) const;
41 |
42 | // @returns the number of command-line switches.
43 | size_t GetNumSwitches() const {
44 | return switches_.size();
45 | }
46 |
47 | private:
48 | // Map Switch Name -> Switch Value.
49 | std::unordered_map switches_;
50 |
51 | DISALLOW_COPY_AND_ASSIGN(CommandLine);
52 | };
53 |
54 | } // namespace base
55 |
--------------------------------------------------------------------------------
/ETWInsights/base/error_string.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "base/error_string.h"
18 |
19 | #include
20 | #include
21 |
22 | #include "base/string_utils.h"
23 |
24 | namespace base {
25 |
26 | std::string GetWindowsErrorString(DWORD error) {
27 | LPWSTR error_desc_buffer = NULL;
28 | LPWSTR error_str_buffer = NULL;
29 |
30 | ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
31 | FORMAT_MESSAGE_IGNORE_INSERTS,
32 | NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
33 | (LPTSTR)&error_desc_buffer, 0, NULL);
34 |
35 | error_str_buffer = (LPWSTR)LocalAlloc(
36 | LMEM_ZEROINIT,
37 | (lstrlen((LPCTSTR)error_desc_buffer) + 40) * sizeof(TCHAR));
38 | ::StringCchPrintf((LPTSTR)error_str_buffer,
39 | LocalSize(error_str_buffer) / sizeof(TCHAR),
40 | TEXT("%d - %s"), error, error_desc_buffer);
41 |
42 | std::wstring error_str(error_str_buffer);
43 |
44 | ::LocalFree(error_desc_buffer);
45 | ::LocalFree(error_str_buffer);
46 |
47 | return WStringToString(error_str);
48 | }
49 |
50 | std::string GetLastWindowsErrorString() {
51 | return GetWindowsErrorString(::GetLastError());
52 | }
53 |
54 | } // namespace base
55 |
--------------------------------------------------------------------------------
/ETWInsights/base/error_string.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #define WIN32_LEAN_AND_MEAN
20 | #include // NOLINT
21 |
22 | #include
23 |
24 | namespace base {
25 |
26 | // @param error A Windows error code.
27 | // @returns The error message for the provided error code.
28 | std::string GetWindowsErrorString(DWORD error);
29 |
30 | // @returns The error message for the last Windows error.
31 | std::string GetLastWindowsErrorString();
32 |
33 | } // namespace base
34 |
--------------------------------------------------------------------------------
/ETWInsights/base/file.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "base/file.h"
18 |
19 | #define WIN32_LEAN_AND_MEAN
20 | #include
21 |
22 | namespace base {
23 |
24 | std::wstring DirName(const std::wstring& path) {
25 | auto pos = path.rfind(L'\\');
26 | if (pos == std::wstring::npos)
27 | return std::wstring();
28 | return path.substr(0, pos);
29 | }
30 |
31 | std::wstring BaseName(const std::wstring& path) {
32 | size_t last_backslash = path.find_last_of(L"\\");
33 | if (last_backslash == std::wstring::npos)
34 | return path;
35 | return path.substr(last_backslash + 1);
36 | }
37 |
38 | bool FilePathExists(const std::wstring& path) {
39 | HANDLE handle = ::CreateFileW(path.c_str(), // file to open
40 | GENERIC_READ, // open for reading
41 | FILE_SHARE_READ, // share for reading
42 | NULL, // default security
43 | OPEN_EXISTING, // existing file only
44 | FILE_ATTRIBUTE_NORMAL, // normal file
45 | NULL); // no attr. template
46 | if (handle == INVALID_HANDLE_VALUE)
47 | return false;
48 | ::CloseHandle(handle);
49 | return true;
50 | }
51 |
52 | } // namespace base
53 |
--------------------------------------------------------------------------------
/ETWInsights/base/file.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace base {
22 |
23 | // @param path a file path.
24 | // @returns everything that comes before the last backslash in |path|. Empty if
25 | // |path| doesn't contain a backslash.
26 | std::wstring DirName(const std::wstring& path);
27 |
28 | // @param path a file path.
29 | // @returns the last path component of the provided file path.
30 | std::wstring BaseName(const std::wstring& path);
31 |
32 | // @param path a file path.
33 | // @returns true if the file path exists, false otherwise.
34 | bool FilePathExists(const std::wstring& path);
35 |
36 | } // namespace base
37 |
--------------------------------------------------------------------------------
/ETWInsights/base/logging.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include "base/logging.h"
20 |
21 | namespace base {
22 |
23 | LogMessage::~LogMessage() {
24 | // TODO(etienneb): Implements a clever logging dispatch.
25 | switch (severity_) {
26 | case LOG_INFO:
27 | std::cout << stream_.str();
28 | break;
29 | case LOG_WARNING:
30 | std::cerr << "WARNING(" << file_ << ":" << line_ << "): " << stream_.str()
31 | << std::endl;
32 | break;
33 | case LOG_ERROR:
34 | std::cerr << "ERROR(" << file_ << ":" << line_ << "): " << stream_.str()
35 | << std::endl;
36 | break;
37 | case LOG_FATAL:
38 | std::cerr << "FATAL(" << file_ << ":" << line_ << "): " << stream_.str()
39 | << std::endl;
40 | exit(-1); // TODO(etienneb): Do we really want this?
41 | break;
42 | }
43 | }
44 |
45 | } // namespace base
46 |
--------------------------------------------------------------------------------
/ETWInsights/base/logging.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | #include "base/base.h"
23 |
24 | namespace base {
25 |
26 | enum LogSeverity { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL };
27 |
28 | class LogMessage {
29 | public:
30 | LogMessage(LogSeverity severity, const char* file, int line)
31 | : severity_(severity), file_(file), line_(line) {}
32 |
33 | ~LogMessage();
34 |
35 | std::ostream& stream() { return stream_; }
36 |
37 | private:
38 | std::ostringstream stream_;
39 | LogSeverity severity_;
40 | const char* file_;
41 | const int line_;
42 |
43 | DISALLOW_COPY_AND_ASSIGN(LogMessage);
44 | };
45 |
46 | #define LOG(severity) \
47 | base::LogMessage(base::LOG_##severity, __FILE__, __LINE__).stream()
48 |
49 | #ifndef NDEBUG
50 | #define DCHECK(cond) \
51 | if (!(cond)) \
52 | LOG(FATAL) << "'" << #cond << "' failed.\n"
53 | #else
54 | #define DCHECK(cond) (void)(cond);
55 | #endif
56 |
57 | #define DCHECK_EQ(a, b) DCHECK((a) == (b))
58 | #define DCHECK_NE(a, b) DCHECK((a) != (b))
59 | #define DCHECK_LT(a, b) DCHECK((a) < (b))
60 | #define DCHECK_LE(a, b) DCHECK((a) <= (b))
61 | #define DCHECK_GT(a, b) DCHECK((a) > (b))
62 | #define DCHECK_GE(a, b) DCHECK((a) >= (b))
63 |
64 | } // namespace base
65 |
--------------------------------------------------------------------------------
/ETWInsights/base/numeric_conversions.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "base/numeric_conversions.h"
18 |
19 | #include
20 |
21 | #include "base/logging.h"
22 |
23 | namespace base {
24 |
25 | bool StrToULong(const std::string& str, uint64_t* ulong) {
26 | DCHECK(ulong);
27 | try {
28 | *ulong = std::stoull(str);
29 | return true;
30 | } catch (std::invalid_argument&) {
31 | return false;
32 | }
33 | }
34 |
35 | bool StrToULong(const std::wstring& str, uint64_t* ulong) {
36 | DCHECK(ulong);
37 | try {
38 | *ulong = std::stoull(str);
39 | return true;
40 | } catch (std::invalid_argument&) {
41 | return false;
42 | }
43 | }
44 |
45 | bool StrToULongHex(const std::string& str, uint64_t* ulong) {
46 | DCHECK(ulong);
47 | try {
48 | size_t pos = 0;
49 | *ulong = std::stoull(str, &pos, 16);
50 | return true;
51 | } catch (std::invalid_argument&) {
52 | return false;
53 | }
54 | }
55 |
56 | } // namespace base
57 |
--------------------------------------------------------------------------------
/ETWInsights/base/numeric_conversions.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | namespace base {
23 |
24 | // @param str a string to convert to unsigned long.
25 | // @param ulong the result of the conversion.
26 | // @returns true if the conversion was successful, false otherwise.
27 | bool StrToULong(const std::string& str, uint64_t* ulong);
28 | bool StrToULong(const std::wstring& str, uint64_t* ulong);
29 | bool StrToULongHex(const std::string& str, uint64_t* ulong);
30 |
31 | } // namespace base
32 |
--------------------------------------------------------------------------------
/ETWInsights/base/string_utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | namespace base {
23 |
24 | // Convert between ASCII and Unicode strings.
25 | std::wstring StringToWString(const std::string& string);
26 | std::string WStringToString(const std::wstring& string);
27 |
28 | // Returns true if |str| contains |substr| at position |pos|.
29 | bool SubstrAtPos(const std::string& str, const std::string& substr, size_t pos);
30 | bool WSubstrAtPos(const std::wstring& str,
31 | const std::wstring& substr,
32 | size_t pos);
33 |
34 | // Returns true if |str| begins with |starting|, or false otherwise.
35 | bool StringBeginsWith(const std::string& str, const std::string& starting);
36 | bool WStringBeginsWith(const std::wstring& str, const std::wstring& starting);
37 |
38 | // Returns true if |str| ends with |ending|, or false otherwise.
39 | bool StringEndsWith(const std::string& str, const std::string& ending);
40 | bool WStringEndsWith(const std::wstring& str, const std::wstring& ending);
41 |
42 | // Escape the C special characters with a backslash.
43 | // @param str the string to be escaped.
44 | // @returns a string escaped copy of |str|.
45 | std::string StringEscapeSpecialCharacter(const std::string& str);
46 |
47 | // Splits |str| at each occurrence of |separator|.
48 | std::vector SplitString(const std::string& str,
49 | const std::string& separator);
50 | std::vector SplitWString(const std::wstring& str,
51 | const std::wstring& separator);
52 |
53 | // Removes spaces at the beginning and end of |str|.
54 | std::string Trim(const std::string& str);
55 | std::wstring TrimW(const std::wstring& str);
56 |
57 | // Replaces all occurrences of |search| in |str| by |replace|.
58 | void ReplaceAll(const std::string& search,
59 | const std::string& replace,
60 | std::string* str);
61 | void ReplaceAllW(const std::wstring& search,
62 | const std::wstring& replace,
63 | std::wstring* str);
64 |
65 | } // namespace base
66 |
--------------------------------------------------------------------------------
/ETWInsights/base/types.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 | #include
22 |
23 | namespace base {
24 |
25 | typedef uint64_t Timestamp;
26 | typedef uint64_t Pid;
27 | typedef uint64_t Tid;
28 |
29 | const Timestamp kInvalidTimestamp = static_cast(-1);
30 | const Pid kInvalidPid = static_cast(-1);
31 | const Tid kInvalidTid = static_cast(-1);
32 |
33 | } // namespace base
34 |
--------------------------------------------------------------------------------
/ETWInsights/etw_reader/etw_reader.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ETWInsights/etw_reader/generate_history_from_trace.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | #include "etw_reader/system_history.h"
22 |
23 | namespace etw_insights {
24 |
25 | // Traverses the event of an ETW trace to fill a system history.
26 | // @param trace_path Path to a .etl trace file.
27 | // @param system_history The system history to fill.
28 | // @returns true if the history was filled successfully, false otherwise.
29 | bool GenerateHistoryFromTrace(const std::wstring& trace_path,
30 | SystemHistory* system_history);
31 |
32 | } // namespace etw_insights
33 |
--------------------------------------------------------------------------------
/ETWInsights/etw_reader/stack.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | namespace etw_insights {
23 |
24 | typedef std::vector Stack;
25 |
26 | } // namespace etw_insights
27 |
--------------------------------------------------------------------------------
/ETWInsights/etw_reader/system_history.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #include "etw_reader/system_history.h"
18 |
19 | namespace etw_insights {
20 |
21 | SystemHistory::SystemHistory()
22 | : first_event_ts_(0),
23 | last_event_ts_(base::kInvalidTimestamp),
24 | first_non_empty_paint_ts_(base::kInvalidTimestamp) {}
25 |
26 | ThreadHistory& SystemHistory::GetThread(base::Tid tid) {
27 | auto look = threads_.find(tid);
28 | if (look != threads_.end())
29 | return look->second;
30 | threads_[tid] = ThreadHistory(tid);
31 | return threads_[tid];
32 | }
33 |
34 | void SystemHistory::SetProcessName(base::Pid process_id,
35 | const std::string& process_name) {
36 | process_names_[process_id] = process_name;
37 | }
38 |
39 | const std::string& SystemHistory::GetProcessName(base::Pid process_id) const {
40 | auto look = process_names_.find(process_id);
41 | if (look == process_names_.end())
42 | return empty_string_;
43 | return look->second;
44 | }
45 |
46 | } // namespace etw_insights
47 |
--------------------------------------------------------------------------------
/ETWInsights/etw_reader/system_history.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | #include "base/base.h"
22 | #include "base/types.h"
23 | #include "etw_reader/thread_history.h"
24 |
25 | namespace etw_insights {
26 |
27 | // Contains the history of a system for the duration of a trace.
28 | class SystemHistory {
29 | public:
30 | typedef std::unordered_map ThreadHistoryMap;
31 |
32 | SystemHistory();
33 |
34 | ThreadHistory& GetThread(base::Tid tid);
35 |
36 | void set_first_event_ts(base::Timestamp ts) { first_event_ts_ = ts; }
37 | base::Timestamp first_event_ts() const { return first_event_ts_; }
38 |
39 | void set_last_event_ts(base::Timestamp ts) { last_event_ts_ = ts; }
40 | base::Timestamp last_event_ts() const { return last_event_ts_; }
41 |
42 | void set_first_non_empty_paint_ts(base::Timestamp ts) {
43 | first_non_empty_paint_ts_ = ts;
44 | }
45 | base::Timestamp first_non_empty_paint_ts() const {
46 | return first_non_empty_paint_ts_;
47 | }
48 |
49 | void SetProcessName(base::Pid process_id, const std::string& process_name);
50 | const std::string& GetProcessName(base::Pid process_id) const;
51 |
52 | ThreadHistoryMap::const_iterator threads_begin() const {
53 | return threads_.begin();
54 | }
55 | ThreadHistoryMap::const_iterator threads_end() const {
56 | return threads_.end();
57 | }
58 |
59 | private:
60 | // Empty string.
61 | std::string empty_string_;
62 |
63 | // Timestamp of the first event.
64 | base::Timestamp first_event_ts_;
65 |
66 | // Timestamp of the last event.
67 | base::Timestamp last_event_ts_;
68 |
69 | // Timestamp of the first non empty paint, in Chrome.
70 | base::Timestamp first_non_empty_paint_ts_;
71 |
72 | // History of each thread.
73 | ThreadHistoryMap threads_;
74 |
75 | // Process names (Process ID -> Process Name).
76 | std::unordered_map process_names_;
77 |
78 | DISALLOW_COPY_AND_ASSIGN(SystemHistory);
79 | };
80 |
81 | } // namespace etw_insights
82 |
--------------------------------------------------------------------------------
/ETWInsights/etw_reader/thread_history.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include "base/history.h"
20 | #include "base/types.h"
21 | #include "etw_reader/stack.h"
22 |
23 | namespace etw_insights {
24 |
25 | // Contains the history of a thread for the duration of a trace.
26 | class ThreadHistory {
27 | public:
28 | ThreadHistory()
29 | : tid_(base::kInvalidTid),
30 | start_ts_(base::kInvalidTimestamp),
31 | end_ts_(base::kInvalidTimestamp),
32 | parent_process_id_(base::kInvalidPid) {}
33 | ThreadHistory(base::Tid tid)
34 | : tid_(tid),
35 | start_ts_(base::kInvalidTimestamp),
36 | end_ts_(base::kInvalidTimestamp),
37 | parent_process_id_(base::kInvalidPid) {}
38 |
39 | base::Tid tid() const { return tid_; }
40 |
41 | void set_start_ts(base::Timestamp ts) { start_ts_ = ts; }
42 | base::Timestamp start_ts() const { return start_ts_; }
43 |
44 | void set_end_ts(base::Timestamp ts) { end_ts_ = ts; }
45 | base::Timestamp end_ts() const { return end_ts_; }
46 |
47 | void set_parent_process_id(base::Pid parent_process_id) {
48 | parent_process_id_ = parent_process_id;
49 | }
50 | base::Timestamp parent_process_id() const { return parent_process_id_; }
51 |
52 | typedef base::History StackHistory;
53 | StackHistory& Stacks() { return stacks_; }
54 | const StackHistory& Stacks() const { return stacks_; }
55 |
56 | private:
57 | // Thread id.
58 | base::Tid tid_;
59 |
60 | // Start timestamp.
61 | base::Timestamp start_ts_;
62 |
63 | // End timestamp.
64 | base::Timestamp end_ts_;
65 |
66 | // Parent process.
67 | base::Pid parent_process_id_;
68 |
69 | // Stack history.
70 | StackHistory stacks_;
71 | };
72 |
73 | } // namespace etw_insights
74 |
--------------------------------------------------------------------------------
/ETWInsights/flame_graph/clean_stack.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include "etw_reader/stack.h"
20 |
21 | #include
22 |
23 | namespace etw_insights {
24 |
25 | // Cleans a call stack.
26 | // - Tall call stacks are truncated.
27 | // - Frames related to page faults are replaced by [Page Fault].
28 | // - Uninteresting frames are removed.
29 | Stack CleanStack(const Stack& stack);
30 |
31 | } // namespace etw_insights
32 |
--------------------------------------------------------------------------------
/ETWInsights/flame_graph/flame_graph.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 Google Inc. All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include