Skip to content

Instantly share code, notes, and snippets.

@KodrAus
KodrAus / Profile Rust on Linux.md
Last active Sep 13, 2020
Profiling Rust Applications
View Profile Rust on Linux.md

Profiling performance

Using perf:

$ perf record -g binary
$ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg

NOTE: See @GabrielMajeri's comments below about the -g option.

@KodrAus
KodrAus / tracing_log.rs
Last active Jun 29, 2020
Converting between `tracing` key values and `log` key values
View tracing_log.rs
use std::fmt;
use log::kv::{self, Source, value::{self, Fill}};
use tracing::{Value, Field, field::{self, Visit}};
#[doc(hidden)]
pub struct LogField<'kvs>(&'kvs Field, &'kvs dyn Value);
impl fmt::Debug for LogField<'_> {
@KodrAus
KodrAus / find_msbuild.rs
Created Apr 11, 2020
Find `msbuild` using `vswhere`
View find_msbuild.rs
use std::path::PathBuf;
use std::process::Command;
use std::str;
let mut msbuild = PathBuf::from("msbuild");
let check_msbuild = Command::new(msbuild)
.arg("--version")
.output()
.is_ok();
View maybe_downcast.rs
#![feature(unsize)]
use std::{
any::TypeId,
marker::Unsize,
fmt,
};
enum Dyn<'v, T: ?Sized, TStatic: ?Sized>
{
@KodrAus
KodrAus / PureDI.cs
Last active Jan 20, 2020 — forked from davidfowl/PureDI.cs
DI under the hood. This is what DI containers automate for you
View PureDI.cs
using System;
using System.Threading;
namespace PureDI
{
class Program
{
static void Main(string[] args)
{
// Create the singletons once
@KodrAus
KodrAus / examples.md
Last active Jul 23, 2019
Finding my examples
View examples.md
@KodrAus
KodrAus / Dump DotNet JIT ASM.md
Last active Feb 11, 2019
Debugging .NET JIT Output
View Dump DotNet JIT ASM.md

See this issue in Kestrel.

This is what I do from my OSX environment.

Build coreclr checked

$ ./build.sh -x64 -checked -skiptests
@KodrAus
KodrAus / Replace Concrete impl with Blanket.md
Created Jan 25, 2019
Using cargo features to replace a set of concrete impls with a blanket one
View Replace Concrete impl with Blanket.md

Using cargo features to replace a set of concrete trait impls with a blanket one

There's subtlety involved in doing this so I've just dumped this out from another document in case I ever need to remember what they were in the future.

value::Visit

The Visit trait can be treated like a lightweight subset of serde::Serialize that can interoperate with serde, without necessarily depending on it. It can't be implemented manually:

/// A type that can be converted into a borrowed value.
View maybe_initialized.rs
union MaybeInitialized<T> {
initialized: T,
uninitialized: (),
}
@KodrAus
KodrAus / properties.rs
Last active Jun 11, 2018
Properties Macro
View properties.rs
/*!
This example demonstrates a potential macro for capturing log properties.
The macro uses a syntax that's _similar_ to struct literals. The idea is to support
extensions to the way properties are captured using attributes.
There's a bit of a misalignment between how formatting is communicated in the log
message and the contextual properties, but they are a bit different. Args are slurped
up into the message using the formatting API whereas properties are exposed as data.
You can’t perform that action at this time.