-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Heapsize calculations #31
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
14f76e0
Added HeapSizeOf impls to all types
Michael-F-Bryan 2fc0325
Manually implemented HeapSizeOf for FileName
Michael-F-Bryan 16a8837
Mentioned the feature flag in the codespan docs
Michael-F-Bryan 60d1559
Hid more heapsize stuff behind a feature flag
Michael-F-Bryan f825718
Augmented the travis build matrix to also test feature flags
Michael-F-Bryan 1e53292
Silly typos
Michael-F-Bryan be736c1
Added heapsize derives to the codespan-reporting crate
Michael-F-Bryan 6cad023
Updated travis.yml
Michael-F-Bryan 5b144fb
Consistent indentation
Michael-F-Bryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
language: rust | ||
cache: cargo | ||
|
||
rust: | ||
- stable | ||
- beta | ||
- nightly | ||
- stable | ||
- beta | ||
- nightly | ||
|
||
env: | ||
- CARGO_FEATURES="" | ||
REPORTING_CARGO_FEATURES="" | ||
- CARGO_FEATURES="memory_usage" | ||
REPORTING_CARGO_FEATURES="memory_usage" | ||
- CARGO_FEATURES="serialization" | ||
REPORTING_CARGO_FEATURES="" | ||
|
||
matrix: | ||
allow_failures: | ||
- rust: nightly | ||
fast_finish: true | ||
|
||
script: | ||
- set -ex | ||
# We manually build/test each crate and pass in any necessary feature flags | ||
# to work around rust-lang/cargo#4942 | ||
|
||
# codespan | ||
- cargo build --manifest-path=codespan/Cargo.toml --verbose --no-default-features --features="$CARGO_FEATURES" | ||
- cargo test --manifest-path=codespan/Cargo.toml --verbose --no-default-features --features="$CARGO_FEATURES" | ||
# codespan-lsp | ||
- cargo build --manifest-path=codespan-lsp/Cargo.toml --verbose | ||
- cargo test --manifest-path=codespan-lsp/Cargo.toml --verbose | ||
# codespan-reporting | ||
- cargo build --manifest-path=codespan-reporting/Cargo.toml --verbose --no-default-features --features="$REPORTING_CARGO_FEATURES" | ||
- cargo test --manifest-path=codespan-reporting/Cargo.toml --verbose --no-default-features --features="$REPORTING_CARGO_FEATURES" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ use std::borrow::Cow; | |
use std::path::{Path, PathBuf}; | ||
use std::{fmt, io}; | ||
|
||
#[cfg(feature = "memory_usage")] | ||
use heapsize::{self, HeapSizeOf}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be cfg-ed out with a feature flag! |
||
use index::{ByteIndex, ByteOffset, ColumnIndex, LineIndex, LineOffset, RawIndex, RawOffset}; | ||
use span::ByteSpan; | ||
|
||
|
@@ -59,6 +61,28 @@ impl fmt::Display for FileName { | |
} | ||
} | ||
|
||
#[cfg(feature = "memory_usage")] | ||
impl HeapSizeOf for FileName { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too! |
||
fn heap_size_of_children(&self) -> usize { | ||
match *self { | ||
FileName::Virtual(ref s) => s.heap_size_of_children(), | ||
FileName::Real(ref path) => { | ||
// Reliably finding the amount of memory used by a `PathBuf` is | ||
// annoying due to its os-specific nature. We use an | ||
// approximation by converting to a string and getting the | ||
// raw heap size for the string's buffer, falling back to 0 | ||
// otherwise. Ideally this should be in the `heapsize` crate. | ||
// | ||
// This *should* be safe because a `PathBuf` will allocate its | ||
// buffer using jemalloc. | ||
path.to_str() | ||
.map(|s| unsafe { heapsize::heap_size_of(s.as_ptr()) }) | ||
.unwrap_or(0) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Fail, PartialEq)] | ||
pub enum LineIndexError { | ||
#[fail(display = "Line out of bounds - given: {:?}, max: {:?}", given, max)] | ||
|
@@ -92,6 +116,7 @@ pub enum SpanError { | |
|
||
#[derive(Debug)] | ||
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] | ||
#[cfg_attr(feature = "memory_usage", derive(HeapSizeOf))] | ||
/// Some source code | ||
pub struct FileMap<S = String> { | ||
/// The name of the file that the source came from | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could we use consistent indentation here (sorry 😅 )