2014-04-07 12:29:07 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#include "ProfileEntry.h"
|
2015-06-30 12:03:45 -07:00
|
|
|
#include "ThreadProfile.h"
|
2014-04-07 12:29:07 -07:00
|
|
|
|
|
|
|
// Make sure we can initialize our ThreadProfile
|
|
|
|
TEST(ThreadProfile, Initialization) {
|
2014-12-11 06:41:00 -08:00
|
|
|
PseudoStack* stack = PseudoStack::create();
|
2014-04-07 12:29:07 -07:00
|
|
|
Thread::tid_t tid = 1000;
|
2014-10-06 11:12:52 -07:00
|
|
|
ThreadInfo info("testThread", tid, true, stack, nullptr);
|
2015-06-17 22:05:42 -07:00
|
|
|
mozilla::RefPtr<ProfileBuffer> pb = new ProfileBuffer(10);
|
2015-01-30 11:49:32 -08:00
|
|
|
ThreadProfile tp(&info, pb);
|
2014-04-07 12:29:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we can record one tag and read it
|
|
|
|
TEST(ThreadProfile, InsertOneTag) {
|
2014-12-11 06:41:00 -08:00
|
|
|
PseudoStack* stack = PseudoStack::create();
|
2014-04-07 12:29:07 -07:00
|
|
|
Thread::tid_t tid = 1000;
|
2014-10-06 11:12:52 -07:00
|
|
|
ThreadInfo info("testThread", tid, true, stack, nullptr);
|
2015-06-17 22:05:42 -07:00
|
|
|
mozilla::RefPtr<ProfileBuffer> pb = new ProfileBuffer(10);
|
2015-06-16 19:28:00 -07:00
|
|
|
pb->addTag(ProfileEntry('t', 123.1));
|
2015-01-30 11:49:32 -08:00
|
|
|
ASSERT_TRUE(pb->mEntries != nullptr);
|
|
|
|
ASSERT_TRUE(pb->mEntries[pb->mReadPos].mTagName == 't');
|
2015-06-16 19:28:00 -07:00
|
|
|
ASSERT_TRUE(pb->mEntries[pb->mReadPos].mTagDouble == 123.1);
|
2014-04-07 12:29:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if we can insert some tags
|
|
|
|
TEST(ThreadProfile, InsertTagsNoWrap) {
|
2014-12-11 06:41:00 -08:00
|
|
|
PseudoStack* stack = PseudoStack::create();
|
2014-04-07 12:29:07 -07:00
|
|
|
Thread::tid_t tid = 1000;
|
2014-10-06 11:12:52 -07:00
|
|
|
ThreadInfo info("testThread", tid, true, stack, nullptr);
|
2015-06-17 22:05:42 -07:00
|
|
|
mozilla::RefPtr<ProfileBuffer> pb = new ProfileBuffer(100);
|
2014-04-07 12:29:07 -07:00
|
|
|
int test_size = 50;
|
|
|
|
for (int i = 0; i < test_size; i++) {
|
2015-01-30 11:49:32 -08:00
|
|
|
pb->addTag(ProfileEntry('t', i));
|
2014-04-07 12:29:07 -07:00
|
|
|
}
|
2015-01-30 11:49:32 -08:00
|
|
|
ASSERT_TRUE(pb->mEntries != nullptr);
|
|
|
|
int readPos = pb->mReadPos;
|
|
|
|
while (readPos != pb->mWritePos) {
|
|
|
|
ASSERT_TRUE(pb->mEntries[readPos].mTagName == 't');
|
|
|
|
ASSERT_TRUE(pb->mEntries[readPos].mTagInt == readPos);
|
|
|
|
readPos = (readPos + 1) % pb->mEntrySize;
|
2014-04-07 12:29:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if wrapping works as it should in the basic case
|
|
|
|
TEST(ThreadProfile, InsertTagsWrap) {
|
2014-12-11 06:41:00 -08:00
|
|
|
PseudoStack* stack = PseudoStack::create();
|
2014-04-07 12:29:07 -07:00
|
|
|
Thread::tid_t tid = 1000;
|
|
|
|
// we can fit only 24 tags in this buffer because of the empty slot
|
|
|
|
int tags = 24;
|
|
|
|
int buffer_size = tags + 1;
|
2014-10-06 11:12:52 -07:00
|
|
|
ThreadInfo info("testThread", tid, true, stack, nullptr);
|
2015-06-17 22:05:42 -07:00
|
|
|
mozilla::RefPtr<ProfileBuffer> pb = new ProfileBuffer(buffer_size);
|
2014-04-07 12:29:07 -07:00
|
|
|
int test_size = 43;
|
|
|
|
for (int i = 0; i < test_size; i++) {
|
2015-01-30 11:49:32 -08:00
|
|
|
pb->addTag(ProfileEntry('t', i));
|
2014-04-07 12:29:07 -07:00
|
|
|
}
|
2015-01-30 11:49:32 -08:00
|
|
|
ASSERT_TRUE(pb->mEntries != nullptr);
|
|
|
|
int readPos = pb->mReadPos;
|
2014-04-07 12:29:07 -07:00
|
|
|
int ctr = 0;
|
2015-01-30 11:49:32 -08:00
|
|
|
while (readPos != pb->mWritePos) {
|
|
|
|
ASSERT_TRUE(pb->mEntries[readPos].mTagName == 't');
|
2014-04-07 12:29:07 -07:00
|
|
|
// the first few tags were discarded when we wrapped
|
2015-01-30 11:49:32 -08:00
|
|
|
ASSERT_TRUE(pb->mEntries[readPos].mTagInt == ctr + (test_size - tags));
|
2014-04-07 12:29:07 -07:00
|
|
|
ctr++;
|
2015-01-30 11:49:32 -08:00
|
|
|
readPos = (readPos + 1) % pb->mEntrySize;
|
2014-04-07 12:29:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|