Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: tools/goopdump/data_dumper_osdata.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/goopdump/data_dumper_osdata.h ('k') | tools/goopdump/dump_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2008-2009 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/tools/goopdump/data_dumper_osdata.h"
17
18 #include <atltime.h>
19 #include <pdh.h>
20 #include <psapi.h>
21 #include <security.h>
22 #include "omaha/common/reg_key.h"
23 #include "omaha/common/scope_guard.h"
24 #include "omaha/common/time.h"
25 #include "omaha/goopdate/goopdate_utils.h"
26 #include "omaha/tools/goopdump/dump_log.h"
27 #include "omaha/tools/goopdump/goopdump_cmd_line_parser.h"
28
29 namespace omaha {
30
31 DataDumperOSData::DataDumperOSData() {
32 }
33
34 DataDumperOSData::~DataDumperOSData() {
35 }
36
37 HRESULT DataDumperOSData::Process(const DumpLog& dump_log,
38 const GoopdumpCmdLineArgs& args) {
39 UNREFERENCED_PARAMETER(args);
40
41 DumpHeader header(dump_log, _T("Operating System Data"));
42
43 CString os_version;
44 CString service_pack;
45 goopdate_utils::GetOSInfo(&os_version, &service_pack);
46 dump_log.WriteLine(_T("OS Version:\t%s"), os_version);
47 dump_log.WriteLine(_T("Service Pack:\t%s"), service_pack);
48
49 TCHAR computer_name[MAX_PATH] = {0};
50 ULONG computer_name_size = arraysize(computer_name);
51 ::GetComputerNameEx(ComputerNameDnsFullyQualified,
52 computer_name,
53 &computer_name_size);
54 dump_log.WriteLine(_T("Computer Name:\t%s"), computer_name);
55
56 TCHAR user_name[MAX_PATH] = {0};
57 ULONG user_name_size = arraysize(user_name);
58 ::GetUserNameEx(NameSamCompatible, user_name, &user_name_size);
59 dump_log.WriteLine(_T("User Name:\t%s"), user_name);
60
61 TCHAR user_friendly_name[MAX_PATH] = {0};
62 ULONG user_friendly_name_size = arraysize(user_friendly_name);
63 ::GetUserNameEx(NameDisplay, user_friendly_name, &user_friendly_name_size);
64 dump_log.WriteLine(_T("Friendly Name:\t%s"), user_friendly_name);
65
66 CString system_uptime;
67 if (SUCCEEDED(GetSystemUptime(&system_uptime))) {
68 dump_log.WriteLine(_T("System Uptime:\t%s"), system_uptime);
69 } else {
70 dump_log.WriteLine(_T("System Uptime:\tNot Available"));
71 }
72
73 PERFORMANCE_INFORMATION perf_info = {0};
74 perf_info.cb = sizeof(perf_info);
75 if (::GetPerformanceInfo(&perf_info, sizeof(perf_info))) {
76 dump_log.WriteLine(_T("Process Count: %d"), perf_info.ProcessCount);
77 dump_log.WriteLine(_T("Handle Count: %d"), perf_info.HandleCount);
78 dump_log.WriteLine(_T("Thread Count: %d"), perf_info.ThreadCount);
79
80 size_t page_size = perf_info.PageSize;
81 size_t mb = 1024 * 1024;
82
83 dump_log.WriteLine(_T("Commit Total(MB): %ld"),
84 perf_info.CommitTotal * page_size / mb);
85 dump_log.WriteLine(_T("Commit Limit(MB): %ld"),
86 perf_info.CommitLimit * page_size / mb);
87 dump_log.WriteLine(_T("Commit Peak(MB): %ld"),
88 perf_info.CommitPeak * page_size / mb);
89 dump_log.WriteLine(_T("Kernel Total(MB): %ld"),
90 perf_info.KernelTotal * page_size / mb);
91 dump_log.WriteLine(_T("Kernel Paged(MB): %ld"),
92 perf_info.KernelPaged * page_size / mb);
93 dump_log.WriteLine(_T("Kernel NonPaged(MB): %ld"),
94 perf_info.KernelNonpaged * page_size / mb);
95 dump_log.WriteLine(_T("Page Size (KB): %ld"),
96 perf_info.PageSize / 1024);
97 dump_log.WriteLine(_T("Physical Avail(MB): %ld"),
98 perf_info.PhysicalAvailable * page_size / mb);
99 dump_log.WriteLine(_T("Physical Total(MB): %ld"),
100 perf_info.PhysicalTotal * page_size / mb);
101 dump_log.WriteLine(_T("System Cache(MB): %ld"),
102 perf_info.SystemCache * page_size / mb);
103 } else {
104 dump_log.WriteLine(_T("Unable to Get Performance Info"));
105 }
106
107 return S_OK;
108 }
109
110 HRESULT DataDumperOSData::GetSystemUptime(CString* uptime) {
111 ASSERT1(uptime);
112
113 const TCHAR* kUptimeCounterPath = _T("\\\\.\\System\\System Up Time");
114
115 HRESULT hr = S_OK;
116
117 PDH_HQUERY perf_query = NULL;
118 PDH_STATUS status = ::PdhOpenQuery(NULL, 0, &perf_query);
119 if (status != ERROR_SUCCESS) {
120 return HRESULT_FROM_WIN32(status);
121 }
122
123 ScopeGuard guard = MakeGuard(::PdhCloseQuery, perf_query);
124
125 PDH_HCOUNTER uptime_counter = NULL;
126 status = ::PdhAddCounter(perf_query,
127 kUptimeCounterPath,
128 0,
129 &uptime_counter);
130 if (status != ERROR_SUCCESS) {
131 return HRESULT_FROM_WIN32(status);
132 }
133
134 status = ::PdhCollectQueryData(perf_query);
135 if (status != ERROR_SUCCESS) {
136 return HRESULT_FROM_WIN32(status);
137 }
138
139 PDH_FMT_COUNTERVALUE uptime_value = {0};
140 status = ::PdhGetFormattedCounterValue(uptime_counter,
141 PDH_FMT_LARGE,
142 NULL,
143 &uptime_value);
144 if (status != ERROR_SUCCESS) {
145 return HRESULT_FROM_WIN32(status);
146 }
147
148 CTimeSpan uptime_span(uptime_value.largeValue);
149 *uptime = uptime_span.Format(_T("%D days, %H hours, %M minutes, %S seconds"));
150
151 return S_OK;
152 }
153
154 } // namespace omaha
155
OLDNEW
« no previous file with comments | « tools/goopdump/data_dumper_osdata.h ('k') | tools/goopdump/dump_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698