forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In subsequent CLs this class will be used from low-level code where it doesn't make sense to take a dependency StackSamplerImpl. TBR=gab@chromium.org Bug: 988579 Change-Id: I0b04a42c0a4c79157aefaccca8092cf3bdc89eaa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738669 Commit-Queue: Mike Wittman <wittman@chromium.org> Reviewed-by: Charlie Andrews <charliea@chromium.org> Reviewed-by: oysteine <oysteine@chromium.org> Cr-Commit-Position: refs/heads/master@{#684761}
- Loading branch information
Mike Wittman
authored and
Commit Bot
committed
Aug 7, 2019
1 parent
ba0abd8
commit a46a488
Showing
13 changed files
with
120 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/profiler/stack_buffer.h" | ||
|
||
namespace base { | ||
|
||
constexpr size_t StackBuffer::kPlatformStackAlignment; | ||
|
||
StackBuffer::StackBuffer(size_t buffer_size) | ||
: buffer_(new uint8_t[buffer_size + kPlatformStackAlignment - 1]), | ||
size_(buffer_size) {} | ||
|
||
StackBuffer::~StackBuffer() = default; | ||
|
||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_PROFILER_STACK_BUFFER_H_ | ||
#define BASE_PROFILER_STACK_BUFFER_H_ | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <memory> | ||
|
||
#include "base/base_export.h" | ||
#include "base/macros.h" | ||
|
||
namespace base { | ||
|
||
// This class contains a buffer for stack copies that can be shared across | ||
// multiple instances of StackSampler. | ||
class BASE_EXPORT StackBuffer { | ||
public: | ||
// The expected alignment of the stack on the current platform. Windows and | ||
// System V AMD64 ABIs on x86, x64, and ARM require the stack to be aligned | ||
// to twice the pointer size. Excepted from this requirement is code setting | ||
// up the stack during function calls (between pushing the return address | ||
// and the end of the function prologue). The profiler will sometimes | ||
// encounter this exceptional case for leaf frames. | ||
static constexpr size_t kPlatformStackAlignment = 2 * sizeof(uintptr_t); | ||
|
||
StackBuffer(size_t buffer_size); | ||
~StackBuffer(); | ||
|
||
// Returns a kPlatformStackAlignment-aligned pointer to the stack buffer. | ||
uintptr_t* buffer() const { | ||
// Return the first address in the buffer aligned to | ||
// kPlatformStackAlignment. The buffer is guaranteed to have enough space | ||
// for size() bytes beyond this value. | ||
return reinterpret_cast<uintptr_t*>( | ||
(reinterpret_cast<uintptr_t>(buffer_.get()) + kPlatformStackAlignment - | ||
1) & | ||
~(kPlatformStackAlignment - 1)); | ||
} | ||
|
||
size_t size() const { return size_; } | ||
|
||
private: | ||
// The buffer to store the stack. | ||
const std::unique_ptr<uint8_t[]> buffer_; | ||
|
||
// The size of the requested buffer allocation. The actual allocation is | ||
// larger to accommodate alignment requirements. | ||
const size_t size_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(StackBuffer); | ||
}; | ||
|
||
} // namespace base | ||
|
||
#endif // BASE_PROFILER_STACK_BUFFER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.