tools/profiler/shared-libraries.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/profiler/shared-libraries.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef SHARED_LIBRARIES_H_
    1.11 +#define SHARED_LIBRARIES_H_
    1.12 +
    1.13 +#ifndef MOZ_ENABLE_PROFILER_SPS
    1.14 +#error This header does not have a useful implementation on your platform!
    1.15 +#endif
    1.16 +
    1.17 +#include <algorithm>
    1.18 +#include <vector>
    1.19 +#include <string>
    1.20 +#include <stdlib.h>
    1.21 +#include <stdint.h>
    1.22 +#include <nsID.h>
    1.23 +
    1.24 +class SharedLibrary {
    1.25 +public:
    1.26 +
    1.27 +  SharedLibrary(uintptr_t aStart,
    1.28 +                uintptr_t aEnd,
    1.29 +                uintptr_t aOffset,
    1.30 +                const std::string& aBreakpadId,
    1.31 +                const std::string& aName)
    1.32 +    : mStart(aStart)
    1.33 +    , mEnd(aEnd)
    1.34 +    , mOffset(aOffset)
    1.35 +    , mBreakpadId(aBreakpadId)
    1.36 +    , mName(aName)
    1.37 +  {}
    1.38 +
    1.39 +  SharedLibrary(const SharedLibrary& aEntry)
    1.40 +    : mStart(aEntry.mStart)
    1.41 +    , mEnd(aEntry.mEnd)
    1.42 +    , mOffset(aEntry.mOffset)
    1.43 +    , mBreakpadId(aEntry.mBreakpadId)
    1.44 +    , mName(aEntry.mName)
    1.45 +  {}
    1.46 +
    1.47 +  SharedLibrary& operator=(const SharedLibrary& aEntry)
    1.48 +  {
    1.49 +    // Gracefully handle self assignment
    1.50 +    if (this == &aEntry) return *this;
    1.51 +
    1.52 +    mStart = aEntry.mStart;
    1.53 +    mEnd = aEntry.mEnd;
    1.54 +    mOffset = aEntry.mOffset;
    1.55 +    mBreakpadId = aEntry.mBreakpadId;
    1.56 +    mName = aEntry.mName;
    1.57 +    return *this;
    1.58 +  }
    1.59 +
    1.60 +  bool operator==(const SharedLibrary& other) const
    1.61 +  {
    1.62 +    return (mStart == other.mStart) &&
    1.63 +           (mEnd == other.mEnd) &&
    1.64 +           (mOffset == other.mOffset) &&
    1.65 +           (mName == other.mName) &&
    1.66 +           (mBreakpadId == other.mBreakpadId);
    1.67 +  }
    1.68 +
    1.69 +  uintptr_t GetStart() const { return mStart; }
    1.70 +  uintptr_t GetEnd() const { return mEnd; }
    1.71 +  uintptr_t GetOffset() const { return mOffset; }
    1.72 +  const std::string &GetBreakpadId() const { return mBreakpadId; }
    1.73 +  const std::string &GetName() const { return mName; }
    1.74 +
    1.75 +private:
    1.76 +  SharedLibrary() {}
    1.77 +
    1.78 +  uintptr_t mStart;
    1.79 +  uintptr_t mEnd;
    1.80 +  uintptr_t mOffset;
    1.81 +  std::string mBreakpadId;
    1.82 +  std::string mName;
    1.83 +};
    1.84 +
    1.85 +static bool
    1.86 +CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
    1.87 +{
    1.88 +  return first.GetStart() < second.GetStart();
    1.89 +}
    1.90 +
    1.91 +class SharedLibraryInfo {
    1.92 +public:
    1.93 +  static SharedLibraryInfo GetInfoForSelf();
    1.94 +  SharedLibraryInfo() {}
    1.95 +
    1.96 +  void AddSharedLibrary(SharedLibrary entry)
    1.97 +  {
    1.98 +    mEntries.push_back(entry);
    1.99 +  }
   1.100 +
   1.101 +  const SharedLibrary& GetEntry(size_t i) const
   1.102 +  {
   1.103 +    return mEntries[i];
   1.104 +  }
   1.105 +
   1.106 +  // Removes items in the range [first, last)
   1.107 +  // i.e. element at the "last" index is not removed
   1.108 +  void RemoveEntries(size_t first, size_t last)
   1.109 +  {
   1.110 +    mEntries.erase(mEntries.begin() + first, mEntries.begin() + last);
   1.111 +  }
   1.112 +
   1.113 +  bool Contains(const SharedLibrary& searchItem) const
   1.114 +  {
   1.115 +    return (mEntries.end() !=
   1.116 +              std::find(mEntries.begin(), mEntries.end(), searchItem));
   1.117 +  }
   1.118 +
   1.119 +  size_t GetSize() const
   1.120 +  {
   1.121 +    return mEntries.size();
   1.122 +  }
   1.123 +
   1.124 +  void SortByAddress()
   1.125 +  {
   1.126 +    std::sort(mEntries.begin(), mEntries.end(), CompareAddresses);
   1.127 +  }
   1.128 +
   1.129 +  void Clear()
   1.130 +  {
   1.131 +    mEntries.clear();
   1.132 +  }
   1.133 +
   1.134 +private:
   1.135 +  std::vector<SharedLibrary> mEntries;
   1.136 +};
   1.137 +
   1.138 +#endif

mercurial