OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/installer/setup/installer_metrics.h" | |
6 | |
7 #include "base/files/file_path.h" | |
8 #include "base/files/file_util.h" | |
9 #include "base/metrics/histogram_base.h" | |
10 #include "base/metrics/histogram_persistence.h" | |
11 #include "base/metrics/persistent_memory_allocator.h" | |
12 | |
13 namespace installer { | |
14 | |
15 void BeginPersistentHistogramStorage(const char* name) { | |
grt (UTC plus 2)
2016/02/08 18:09:19
what's the advantage of taking |name| as an arg ra
bcwhite
2016/02/09 21:08:45
Each file needs a different preference name becaus
grt (UTC plus 2)
2016/02/10 16:01:53
Will setup_main.cc eventually call this multiple t
bcwhite
2016/02/10 16:11:24
Probably not. Just seemed a better abstraction.
grt (UTC plus 2)
2016/02/10 20:28:46
Sine this file is for exclusive use by the install
bcwhite
2016/02/10 21:28:43
Done.
| |
16 base::SetPersistentHistogramMemoryAllocator( | |
17 new base::LocalPersistentMemoryAllocator(1 << 20, 0, name)); // 1 MiB | |
18 base::GetPersistentHistogramMemoryAllocator()->CreateTrackingHistograms(name); | |
19 } | |
20 | |
21 void EndPersistentHistogramStorage(const base::FilePath& target_path) { | |
grt (UTC plus 2)
2016/02/08 18:09:18
nit: indentation
bcwhite
2016/02/09 21:08:46
Done.
| |
22 // For atomicity, first write to a temporary file and then rename it. | |
23 // The ImportantFileWriter would be good for this except it supports only | |
24 // std::string for its data. | |
25 base::PersistentMemoryAllocator* allocator = | |
26 base::GetPersistentHistogramMemoryAllocator(); | |
27 allocator->UpdateTrackingHistograms(); | |
28 | |
29 base::FilePath file_path = target_path | |
30 .AppendASCII(allocator->Name()) | |
31 .AddExtension(L".pma"); | |
32 base::FilePath tmp_file_path; | |
33 base::DeleteFile(file_path, false); | |
34 | |
35 if (base::CreateTemporaryFileInDir(file_path.DirName(), &tmp_file_path)) { | |
36 base::File histograms(tmp_file_path, | |
grt (UTC plus 2)
2016/02/08 18:09:18
#include "base/files/file.h"
bcwhite
2016/02/09 21:08:45
Done.
| |
37 base::File::FLAG_OPEN | base::File::FLAG_WRITE); | |
38 if (histograms.IsValid()) { | |
39 base::PersistentMemoryAllocator* alloc = | |
grt (UTC plus 2)
2016/02/08 18:09:18
is this the same as |allocator| on line 25?
bcwhite
2016/02/09 21:08:45
Heh. That's what happens when you add code at the
| |
40 base::GetPersistentHistogramMemoryAllocator(); | |
41 int used = static_cast<int>(alloc->used()); | |
grt (UTC plus 2)
2016/02/08 18:09:19
base::checked_cast?
bcwhite
2016/02/09 21:08:45
Should be size_t.
bcwhite
2016/02/10 15:26:45
Scratch that. Write() returns int. Added comment
grt (UTC plus 2)
2016/02/10 16:01:53
File::Write takes its |size| arg as an int and ret
| |
42 if (histograms.Write(0, static_cast<const char*>(alloc->data()), | |
43 used) == used && | |
44 histograms.Flush()) { | |
45 histograms.Close(); | |
46 if (base::ReplaceFile(tmp_file_path, file_path, nullptr)) { | |
47 VLOG(1) << "Persistent histograms saved in file: " | |
48 << file_path.AsUTF8Unsafe(); | |
grt (UTC plus 2)
2016/02/08 18:09:18
.value() instead of AsUTF8Unsafe()
bcwhite
2016/02/09 21:08:45
Done.
| |
49 } | |
50 } | |
51 } | |
52 } | |
53 base::DeleteFile(tmp_file_path, false); | |
grt (UTC plus 2)
2016/02/08 18:09:19
move this up one line so that the file is only del
bcwhite
2016/02/09 21:08:45
Done.
| |
54 } | |
55 | |
56 } // namespace installer | |
OLD | NEW |