From b1a309ac1f08df9864ba2c364225a6bb172fd003 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 9 Nov 2016 15:17:38 -0800 Subject: [PATCH] init: warn slow action Slow action that takes longer than 50ms will be warned to user Test: grep init log Bug: 32712851 Change-Id: I3a6a881a8dee1807270343b511a47c76dd230392 --- init/action.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/init/action.cpp b/init/action.cpp index ed88f6d89..a12f2253c 100644 --- a/init/action.cpp +++ b/init/action.cpp @@ -118,14 +118,16 @@ void Action::ExecuteCommand(const Command& command) const { Timer t; int result = command.InvokeFunc(); - // TODO: this should probably be changed to "if (failed || took a long time)"... - if (android::base::GetMinimumLogSeverity() <= android::base::DEBUG) { + double duration_ms = t.duration() * 1000; + // Any action longer than 50ms will be warned to user as slow operation + if (duration_ms > 50.0 || + android::base::GetMinimumLogSeverity() <= android::base::DEBUG) { std::string trigger_name = BuildTriggersString(); std::string cmd_str = command.BuildCommandString(); std::string source = command.BuildSourceString(); LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << source - << " returned " << result << " took " << t.duration() << "s"; + << " returned " << result << " took " << duration_ms << "ms."; } }