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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/trace.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/import_manager.cc
diff --git a/tools/gn/import_manager.cc b/tools/gn/import_manager.cc
index 01c88b5a68c85dd1bce16a19c78d09d9ba6be4e1..0213c3367a41c5b6208cc6f62a52b7eae7c07f39 100644
--- a/tools/gn/import_manager.cc
+++ b/tools/gn/import_manager.cc
@@ -8,6 +8,7 @@
#include "tools/gn/parse_tree.h"
#include "tools/gn/scheduler.h"
#include "tools/gn/scope_per_file_provider.h"
+#include "tools/gn/trace.h"
namespace {
@@ -16,6 +17,8 @@ std::unique_ptr<Scope> UncachedImport(const Settings* settings,
const SourceFile& file,
const ParseNode* node_for_err,
Err* err) {
+ ScopedTrace load_trace(TraceItem::TRACE_IMPORT_LOAD, file.value());
+
const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile(
node_for_err->GetRange(), settings->build_settings(), file, err);
if (!node)
@@ -87,6 +90,7 @@ bool ImportManager::DoImport(const SourceFile& file,
// is already processing the import.
const Scope* import_scope = nullptr;
{
+ base::TimeTicks import_block_begin = base::TimeTicks::Now();
base::AutoLock lock(import_info->load_lock);
if (!import_info->scope) {
@@ -99,6 +103,21 @@ bool ImportManager::DoImport(const SourceFile& file,
*err = import_info->load_result;
return false;
}
+ } else {
+ // Add trace if this thread was blocked for a long period of time and did
+ // not load the import itself.
+ base::TimeTicks import_block_end = base::TimeTicks::Now();
+ constexpr auto kImportBlockTraceThreshold =
+ base::TimeDelta::FromMilliseconds(20);
+ if (TracingEnabled() &&
+ import_block_end - import_block_begin > kImportBlockTraceThreshold) {
+ auto import_block_trace =
+ new TraceItem(TraceItem::TRACE_IMPORT_BLOCK, file.value(),
+ base::PlatformThread::CurrentId());
+ import_block_trace->set_begin(import_block_begin);
+ import_block_trace->set_end(import_block_end);
+ AddTrace(import_block_trace);
+ }
}
// Promote the now-read-only scope to outside the load lock.
« 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