forked from xapi-project/xen-api
-
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.
Merge branch 'private/edvint/instrument-locks0'
- Loading branch information
Showing
29 changed files
with
788 additions
and
212 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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(* based on bechamel example code *) | ||
open Bechamel | ||
open Toolkit | ||
|
||
let instances = Instance.[monotonic_clock; minor_allocated; major_allocated] | ||
|
||
let benchmark tests = | ||
(* stabilize:true would be the default but it measures GC stabilization time as part of the function | ||
runtime, leading to about 10x as much time measured than without. | ||
It is also confusing for flamegraphs because the GC will show up much more frequently than in reality | ||
due to the thousands of repeated calls. | ||
*) | ||
let cfg = | ||
Benchmark.cfg | ||
~quota:Time.(second 5.0) | ||
~start:10 ~stabilize:false ~compaction:false () | ||
in | ||
Benchmark.all cfg instances tests | ||
|
||
let analyze raw_results = | ||
let ols = | ||
Analyze.ols ~r_square:true ~bootstrap:0 ~predictors:[|Measure.run|] | ||
in | ||
let results = | ||
List.map (fun instance -> Analyze.all ols instance raw_results) instances | ||
in | ||
(Analyze.merge ols instances results, raw_results) | ||
|
||
let () = | ||
List.iter (fun i -> Bechamel_notty.Unit.add i (Measure.unit i)) instances | ||
|
||
let img (window, results) = | ||
Bechamel_notty.Multiple.image_of_ols_results ~rect:window | ||
~predictor:Measure.run results | ||
|
||
open Notty_unix | ||
|
||
let cli tests = | ||
Format.printf "@,Running benchmarks@." ; | ||
let results, _ = tests |> benchmark |> analyze in | ||
|
||
let window = | ||
match winsize Unix.stdout with | ||
| Some (w, h) -> | ||
{Bechamel_notty.w; h} | ||
| None -> | ||
{Bechamel_notty.w= 80; h= 1} | ||
in | ||
img (window, results) |> eol |> output_image |
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,50 @@ | ||
open Bechamel | ||
|
||
let bench_tracing = true | ||
|
||
let test name allocate execute = | ||
let test_mutex m = execute m ignore in | ||
Test.make_with_resource ~name | ||
Test.multiple (* TODO: Test.uniq segfaults here, bechamel bug *) | ||
~allocate ~free:ignore (Staged.stage test_mutex) | ||
|
||
let mutex_lock_unlock m f = Mutex.lock m ; f () ; Mutex.unlock m | ||
|
||
let tracing_benchmarks () = | ||
let () = Suite_init.harness_init () in | ||
let __context = Test_common.make_test_database () in | ||
let observer = | ||
Xapi_observer.create ~__context ~name_label:"test" ~name_description:"" | ||
~hosts:[] ~attributes:[] ~endpoints:["bugtool"] ~components:["xapi"] | ||
~enabled:true | ||
in | ||
let host = !Xapi_globs.localhost_ref in | ||
let () = Xapi_observer.register ~__context ~self:observer ~host in | ||
let open Locking_helpers in | ||
let named_trace_execute m f = | ||
Context.with_tracing __context "bench" @@ fun __context -> | ||
Named_mutex.execute m f | ||
in | ||
test "NamedMutex.execute (tracing)" | ||
(fun () -> Named_mutex.create "test") | ||
named_trace_execute | ||
|
||
let benchmarks = | ||
let open Locking_helpers in | ||
let named_execute m f = Named_mutex.execute m f in | ||
Test.make_grouped ~name:"Mutex" | ||
([ | ||
test "Mutex.lock/unlock" Mutex.create mutex_lock_unlock | ||
; test "Mutex.execute" Mutex.create | ||
Xapi_stdext_threads.Threadext.Mutex.execute | ||
; test "NamedMutex.execute" | ||
(fun () -> Named_mutex.create "test") | ||
named_execute | ||
] | ||
@ if bench_tracing then [tracing_benchmarks ()] else [] | ||
) | ||
|
||
let () = | ||
Gc.compact () ; | ||
Memtrace.trace_if_requested () ; | ||
Bechamel_simple_cli.cli benchmarks |
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,6 @@ | ||
(executable | ||
(name bench_named_mutex) | ||
(modes exe) | ||
(optional) | ||
(libraries bechamel xapi_internal bechamel-notty notty.unix xapi-stdext-threads tests_common memtrace) | ||
) |
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.