17d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui/* 27d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * Copyright (C) 2015 The Android Open Source Project 37d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * 47d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * Licensed under the Apache License, Version 2.0 (the "License"); 57d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * you may not use this file except in compliance with the License. 67d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * You may obtain a copy of the License at 77d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * 87d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * http://www.apache.org/licenses/LICENSE-2.0 97d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * 107d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * Unless required by applicable law or agreed to in writing, software 117d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * distributed under the License is distributed on an "AS IS" BASIS, 127d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * See the License for the specific language governing permissions and 147d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui * limitations under the License. 157d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui */ 167d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui 177d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cuistatic void CheckMmapRecordDataEqual(const MmapRecord& r1, const MmapRecord& r2) { 18190a848fb2d4f502372b2528c55ca1f520e90609Yabin Cui ASSERT_EQ(0, memcmp(r1.data, r2.data, sizeof(*r1.data))); 19190a848fb2d4f502372b2528c55ca1f520e90609Yabin Cui ASSERT_STREQ(r1.filename, r2.filename); 207d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui} 217d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui 227d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cuistatic void CheckCommRecordDataEqual(const CommRecord& r1, const CommRecord& r2) { 23190a848fb2d4f502372b2528c55ca1f520e90609Yabin Cui ASSERT_EQ(0, memcmp(r1.data, r2.data, sizeof(*r1.data))); 24190a848fb2d4f502372b2528c55ca1f520e90609Yabin Cui ASSERT_STREQ(r1.comm, r2.comm); 257d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui} 267d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui 278f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cuistatic void CheckBuildIdRecordDataEqual(const BuildIdRecord& r1, const BuildIdRecord& r2) { 288f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cui ASSERT_EQ(r1.pid, r2.pid); 298f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cui ASSERT_EQ(r1.build_id, r2.build_id); 30190a848fb2d4f502372b2528c55ca1f520e90609Yabin Cui ASSERT_STREQ(r1.filename, r2.filename); 318f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cui} 328f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cui 332597ef042881f834d1bc414930f144a405dd13caYabin Cuistatic void CheckSampleRecordDataEqual(const SampleRecord& r1, const SampleRecord& r2) { 342597ef042881f834d1bc414930f144a405dd13caYabin Cui ASSERT_EQ(r1.sample_type, r2.sample_type); 352597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_IP) { 362597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.ip_data.ip, r2.ip_data.ip); 372597ef042881f834d1bc414930f144a405dd13caYabin Cui } 382597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_TID) { 392597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.tid_data.pid, r2.tid_data.pid); 402597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.tid_data.tid, r2.tid_data.tid); 412597ef042881f834d1bc414930f144a405dd13caYabin Cui } 422597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_TIME) { 432597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.time_data.time, r2.time_data.time); 442597ef042881f834d1bc414930f144a405dd13caYabin Cui } 452597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_ID) { 462597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.id_data.id, r2.id_data.id); 472597ef042881f834d1bc414930f144a405dd13caYabin Cui } 482597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_CPU) { 492597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.cpu_data.cpu, r2.cpu_data.cpu); 502597ef042881f834d1bc414930f144a405dd13caYabin Cui } 512597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_PERIOD) { 522597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.period_data.period, r2.period_data.period); 532597ef042881f834d1bc414930f144a405dd13caYabin Cui } 542597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.sample_type & PERF_SAMPLE_CALLCHAIN) { 552597ef042881f834d1bc414930f144a405dd13caYabin Cui ASSERT_EQ(r1.callchain_data.ip_nr, r2.callchain_data.ip_nr); 562597ef042881f834d1bc414930f144a405dd13caYabin Cui for (size_t i = 0; i < r1.callchain_data.ip_nr; ++i) { 572597ef042881f834d1bc414930f144a405dd13caYabin Cui EXPECT_EQ(r1.callchain_data.ips[i], r2.callchain_data.ips[i]); 582597ef042881f834d1bc414930f144a405dd13caYabin Cui } 592597ef042881f834d1bc414930f144a405dd13caYabin Cui } 602597ef042881f834d1bc414930f144a405dd13caYabin Cui} 612597ef042881f834d1bc414930f144a405dd13caYabin Cui 627d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cuistatic void CheckRecordEqual(const Record& r1, const Record& r2) { 63b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui ASSERT_EQ(r1.type(), r2.type()); 64b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui ASSERT_EQ(r1.misc(), r2.misc()); 65b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui ASSERT_EQ(r1.size(), r2.size()); 662597ef042881f834d1bc414930f144a405dd13caYabin Cui if (r1.type() == PERF_RECORD_SAMPLE) { 672597ef042881f834d1bc414930f144a405dd13caYabin Cui CheckSampleRecordDataEqual(static_cast<const SampleRecord&>(r1), 682597ef042881f834d1bc414930f144a405dd13caYabin Cui static_cast<const SampleRecord&>(r2)); 692597ef042881f834d1bc414930f144a405dd13caYabin Cui return; 702597ef042881f834d1bc414930f144a405dd13caYabin Cui } 717d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui ASSERT_EQ(0, memcmp(&r1.sample_id, &r2.sample_id, sizeof(r1.sample_id))); 72b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui if (r1.type() == PERF_RECORD_MMAP) { 737d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui CheckMmapRecordDataEqual(static_cast<const MmapRecord&>(r1), static_cast<const MmapRecord&>(r2)); 74b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui } else if (r1.type() == PERF_RECORD_COMM) { 757d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui CheckCommRecordDataEqual(static_cast<const CommRecord&>(r1), static_cast<const CommRecord&>(r2)); 76b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui } else if (r1.type() == PERF_RECORD_BUILD_ID) { 778f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cui CheckBuildIdRecordDataEqual(static_cast<const BuildIdRecord&>(r1), 788f6225147c5b6cb2159a7f5cb0dab952ee0759dfYabin Cui static_cast<const BuildIdRecord&>(r2)); 797d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui } 807d59bb49fb47fbc82ef5c77d7aebf7174fd996e1Yabin Cui} 81