Skip to content

Commit

Permalink
arc: Fix tracing model unable to build.
Browse files Browse the repository at this point in the history
This handles new style of applying ids to async events.

TEST=Locally
BUG=b:150030838
BUG=b:160024571

Change-Id: I7ac4ab3241cd04201ae8c7800102bfa43c7df499
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285506
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Yury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786079}
  • Loading branch information
Yury Khmel authored and Commit Bot committed Jul 8, 2020
1 parent 8038a87 commit 93d8903
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
19 changes: 17 additions & 2 deletions chrome/browser/chromeos/arc/tracing/arc_tracing_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ constexpr char kKeyArguments[] = "args";
constexpr char kKeyDuration[] = "dur";
constexpr char kKeyCategory[] = "cat";
constexpr char kKeyId[] = "id";
constexpr char kKeyId2[] = "id2";
constexpr char kKeyLocal[] = "local";
constexpr char kKeyName[] = "name";
constexpr char kKeyPid[] = "pid";
constexpr char kKeyPhase[] = "ph";
Expand Down Expand Up @@ -90,8 +92,21 @@ void ArcTracingEvent::SetTid(int tid) {
}

std::string ArcTracingEvent::GetId() const {
return GetStringFromDictionary(GetDictionary(), kKeyId,
std::string() /* default_value */);
const base::DictionaryValue* dictionary = GetDictionary();
const base::Value* id_value =
dictionary->FindKeyOfType(kKeyId, base::Value::Type::STRING);
if (id_value)
return id_value->GetString();

const base::Value* id2_value =
dictionary->FindKeyOfType(kKeyId2, base::Value::Type::DICTIONARY);
if (id2_value) {
const base::DictionaryValue* id2_dictionary;
id2_value->GetAsDictionary(&id2_dictionary);
return GetStringFromDictionary(id2_dictionary, kKeyLocal,
std::string() /* default_value */);
}
return std::string();
}

void ArcTracingEvent::SetId(const std::string& id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,24 @@ constexpr char kTestEvent[] =
"name":"Surface::Attach",
"args":{"buffer_id":"0x7f9f5110690","app_id":"org.chromium.arc.6"},
"dur":10,"tdur":9,"tts":1216670360})";
constexpr char kTestEvent2[] =
R"({"args":{},"cat":"exo","id2":{"local":"0x2df1a3130a10"},
"name":"BufferInUse","ph":"F","pid":17518,"tid":17518,
"ts":7654346859.0,"tts":93686437})";

constexpr char kAppId[] = "app_id";
constexpr char kAppIdValue[] = "org.chromium.arc.6";
constexpr char kBufferId[] = "buffer_id";
constexpr char kBufferIdBad[] = "_buffer_id";
constexpr char kBufferIdValue[] = "0x7f9f5110690";
constexpr char kBufferIdValueBad[] = "_0x7f9f5110690";
constexpr char kBufferInUse[] = "BufferInUse";
constexpr char kDefault[] = "default";
constexpr char kExo[] = "exo";
constexpr char kExoBad[] = "_exo";
constexpr char kPhaseX = 'X';
constexpr char kPhaseF = 'F';
constexpr char kPhaseP = 'P';
constexpr char kPhaseX = 'X';
constexpr char kSurfaceAttach[] = "Surface::Attach";
constexpr char kSurfaceAttachBad[] = "_Surface::Attach";

Expand Down Expand Up @@ -367,6 +373,21 @@ TEST_F(ArcTracingModelTest, Event) {
EXPECT_EQ(kDefault, event.GetArgAsString(kBufferIdBad, kDefault));
}

TEST_F(ArcTracingModelTest, EventId2) {
const ArcTracingEvent event(base::JSONReader::Read(kTestEvent2).value());

EXPECT_EQ(17518, event.GetPid());
EXPECT_EQ(17518, event.GetTid());
EXPECT_EQ("0x2df1a3130a10", event.GetId());
EXPECT_EQ(kExo, event.GetCategory());
EXPECT_EQ(kBufferInUse, event.GetName());
EXPECT_EQ(kPhaseF, event.GetPhase());
EXPECT_EQ(7654346859UL, event.GetTimestamp());
EXPECT_EQ(0U, event.GetDuration());
EXPECT_EQ(7654346859UL, event.GetEndTimestamp());
EXPECT_NE(nullptr, event.GetDictionary());
}

TEST_F(ArcTracingModelTest, EventClassification) {
const ArcTracingEvent event(base::JSONReader::Read(kTestEvent).value());

Expand Down

0 comments on commit 93d8903

Please sign in to comment.