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

Side by Side Diff: tools/gn/import_manager.cc

Issue 2424233002: [gn] Add trace entries for loading and blocking on imports (Closed)
Patch Set: Created 4 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 | « no previous file | tools/gn/trace.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/import_manager.h" 5 #include "tools/gn/import_manager.h"
6 6
7 #include "tools/gn/err.h" 7 #include "tools/gn/err.h"
8 #include "tools/gn/parse_tree.h" 8 #include "tools/gn/parse_tree.h"
9 #include "tools/gn/scheduler.h" 9 #include "tools/gn/scheduler.h"
10 #include "tools/gn/scope_per_file_provider.h" 10 #include "tools/gn/scope_per_file_provider.h"
11 #include "tools/gn/trace.h"
11 12
12 namespace { 13 namespace {
13 14
14 // Returns a newly-allocated scope on success, null on failure. 15 // Returns a newly-allocated scope on success, null on failure.
15 std::unique_ptr<Scope> UncachedImport(const Settings* settings, 16 std::unique_ptr<Scope> UncachedImport(const Settings* settings,
16 const SourceFile& file, 17 const SourceFile& file,
17 const ParseNode* node_for_err, 18 const ParseNode* node_for_err,
18 Err* err) { 19 Err* err) {
20 ScopedTrace load_trace(TraceItem::TRACE_IMPORT_LOAD, file.value());
21
19 const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile( 22 const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile(
20 node_for_err->GetRange(), settings->build_settings(), file, err); 23 node_for_err->GetRange(), settings->build_settings(), file, err);
21 if (!node) 24 if (!node)
22 return nullptr; 25 return nullptr;
23 26
24 std::unique_ptr<Scope> scope(new Scope(settings->base_config())); 27 std::unique_ptr<Scope> scope(new Scope(settings->base_config()));
25 scope->set_source_dir(file.GetDir()); 28 scope->set_source_dir(file.GetDir());
26 29
27 // Don't allow ScopePerFileProvider to provide target-related variables. 30 // Don't allow ScopePerFileProvider to provide target-related variables.
28 // These will be relative to the imported file, which is probably not what 31 // These will be relative to the imported file, which is probably not what
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 info_ptr.reset(new ImportInfo); 83 info_ptr.reset(new ImportInfo);
81 84
82 // Promote the ImportInfo to outside of the imports lock. 85 // Promote the ImportInfo to outside of the imports lock.
83 import_info = info_ptr.get(); 86 import_info = info_ptr.get();
84 } 87 }
85 88
86 // Now use the per-import-file lock to block this thread if another thread 89 // Now use the per-import-file lock to block this thread if another thread
87 // is already processing the import. 90 // is already processing the import.
88 const Scope* import_scope = nullptr; 91 const Scope* import_scope = nullptr;
89 { 92 {
93 base::TimeTicks import_block_begin = base::TimeTicks::Now();
90 base::AutoLock lock(import_info->load_lock); 94 base::AutoLock lock(import_info->load_lock);
91 95
92 if (!import_info->scope) { 96 if (!import_info->scope) {
93 // Only load if the import hasn't already failed. 97 // Only load if the import hasn't already failed.
94 if (!import_info->load_result.has_error()) { 98 if (!import_info->load_result.has_error()) {
95 import_info->scope = UncachedImport( 99 import_info->scope = UncachedImport(
96 scope->settings(), file, node_for_err, &import_info->load_result); 100 scope->settings(), file, node_for_err, &import_info->load_result);
97 } 101 }
98 if (import_info->load_result.has_error()) { 102 if (import_info->load_result.has_error()) {
99 *err = import_info->load_result; 103 *err = import_info->load_result;
100 return false; 104 return false;
101 } 105 }
106 } else {
107 // Add trace if this thread was blocked for a long period of time and did
108 // not load the import itself.
109 base::TimeTicks import_block_end = base::TimeTicks::Now();
110 constexpr auto kImportBlockTraceThreshold =
111 base::TimeDelta::FromMilliseconds(20);
112 if (TracingEnabled() &&
113 import_block_end - import_block_begin > kImportBlockTraceThreshold) {
114 auto import_block_trace =
115 new TraceItem(TraceItem::TRACE_IMPORT_BLOCK, file.value(),
116 base::PlatformThread::CurrentId());
117 import_block_trace->set_begin(import_block_begin);
118 import_block_trace->set_end(import_block_end);
119 AddTrace(import_block_trace);
120 }
102 } 121 }
103 122
104 // Promote the now-read-only scope to outside the load lock. 123 // Promote the now-read-only scope to outside the load lock.
105 import_scope = import_info->scope.get(); 124 import_scope = import_info->scope.get();
106 } 125 }
107 126
108 Scope::MergeOptions options; 127 Scope::MergeOptions options;
109 options.skip_private_vars = true; 128 options.skip_private_vars = true;
110 options.mark_dest_used = true; // Don't require all imported values be used. 129 options.mark_dest_used = true; // Don't require all imported values be used.
111 return import_scope->NonRecursiveMergeTo(scope, options, node_for_err, 130 return import_scope->NonRecursiveMergeTo(scope, options, node_for_err,
112 "import", err); 131 "import", err);
113 } 132 }
114 133
115 std::vector<SourceFile> ImportManager::GetImportedFiles() const { 134 std::vector<SourceFile> ImportManager::GetImportedFiles() const {
116 std::vector<SourceFile> imported_files; 135 std::vector<SourceFile> imported_files;
117 imported_files.resize(imports_.size()); 136 imported_files.resize(imports_.size());
118 std::transform(imports_.begin(), imports_.end(), imported_files.begin(), 137 std::transform(imports_.begin(), imports_.end(), imported_files.begin(),
119 [](const ImportMap::value_type& val) { return val.first; }); 138 [](const ImportMap::value_type& val) { return val.first; });
120 return imported_files; 139 return imported_files;
121 } 140 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/trace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698