├── .gitignore ├── CHANGES.md ├── test-doo └── espejito │ └── runner.cljs ├── test └── espejito │ ├── instrument_test.clj │ └── core_test.cljc ├── project.clj ├── README.md ├── src └── espejito │ ├── internal.cljc │ ├── core.cljc │ └── instrument.clj └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | .hgignore 11 | .hg/ 12 | /.classpath 13 | /.project 14 | /.settings 15 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # TODO and History 2 | 3 | ## TODO 4 | 5 | - [TODO] Support for measuring Java code 6 | - [TODO] Support for carrying context into child threads 7 | 8 | 9 | ## 0.2.0 / 2021-February-03 10 | 11 | - Drop support for Clojure 1.5 and 1.6 12 | - Add ClojureScript support 13 | - Add `espejito.core/wrap-measure` to wrap functions for measurement 14 | - Add `espejito.instrument` namespace (instrumentation on JVM) 15 | - `shorten-ns` (utility) 16 | - `resolve-var` (utility) 17 | - `instrument-measure` (instrument) 18 | 19 | 20 | ## 0.1.1 / 2016-October-13 21 | 22 | - Support for pluggable table printer in `espejito.core/print-table` 23 | 24 | 25 | ## 0.1.0 / 2015-June-02 26 | 27 | - Measurement API for single-threaded execution 28 | - Reporting API for metrics collection 29 | -------------------------------------------------------------------------------- /test-doo/espejito/runner.cljs: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Shantanu Kumar. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file LICENSE at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | 10 | (ns espejito.runner 11 | (:require 12 | [doo.runner :refer-macros [doo-tests]] 13 | [espejito.core-test])) 14 | 15 | 16 | (enable-console-print!) 17 | 18 | (try 19 | (doo-tests 20 | 'espejito.core-test) 21 | (catch js/Error e 22 | (.log js/Console (.-stack e)))) -------------------------------------------------------------------------------- /test/espejito/instrument_test.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Shantanu Kumar. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file LICENSE at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | 10 | (ns espejito.instrument-test 11 | (:require 12 | [clojure.test :refer [deftest is testing]] 13 | [espejito.core :as e] 14 | [espejito.instrument :as ins])) 15 | 16 | 17 | (defn baz [] (Thread/sleep 100) :baz) 18 | (defn bar [] (Thread/sleep 200) (baz) :bar) 19 | (defn foo [] (Thread/sleep 300) (bar) :foo) 20 | 21 | 22 | (deftest test-instrument 23 | ;; instrument 24 | (doseq [each ["espejito.instrument-test/foo" 25 | "espejito.instrument-test/bar" 26 | "espejito.instrument-test/baz"]] 27 | (ins/instrument-measure each)) 28 | ;; execute and report 29 | (e/report e/print-table 30 | (is (= :foo (foo))))) 31 | -------------------------------------------------------------------------------- /test/espejito/core_test.cljc: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Shantanu Kumar. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file LICENSE at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | 10 | (ns espejito.core-test 11 | (:require 12 | #?(:cljs [cljs.test :refer-macros [deftest is testing]] 13 | :clj [clojure.test :refer [deftest is testing]]) 14 | #?(:cljs [cljs.pprint :include-macros true :as pp] 15 | :clj [clojure.pprint :as pp]) 16 | #?(:cljs [espejito.core :include-macros true :as e] 17 | :clj [espejito.core :as e]) 18 | [espejito.internal :as i])) 19 | 20 | 21 | (defn sleep 22 | [millis] 23 | #?(:cljs (let [deadline (+ millis (.getTime (js/Date.)))] 24 | (while (> deadline (.getTime (js/Date.))))) 25 | :clj (Thread/sleep millis))) 26 | 27 | 28 | (defn throwable 29 | [^String msg] 30 | #?(:clj (Exception. msg) :cljs (js/Error. msg))) 31 | 32 | 33 | (defn processing 34 | [] 35 | (e/measure "outer" 36 | (sleep 100) 37 | (try 38 | (e/measure "inner" 39 | (sleep 150) 40 | (e/measure "inner-most" 41 | (sleep 50)) 42 | (throw (throwable "foo"))) 43 | (catch #?(:cljs js/Error :clj Exception) _)) 44 | (e/measure "inner-sibling" 45 | (sleep 50)))) 46 | 47 | 48 | (deftest the-test 49 | (testing "Using clojure.pprint/pprint (to show nested data)" 50 | (e/report pp/pprint 51 | (processing))) 52 | (testing "Using vanilla print-table (to show intermediate flattened data)" 53 | (e/report #(-> (i/flatten-children-report %) 54 | pp/print-table) 55 | (processing))) 56 | (testing "Using espejito print-table" 57 | (e/report e/print-table 58 | (processing)) 59 | (e/report (partial e/print-table pp/print-table 50) 60 | (processing))) 61 | (testing "Empty block using espejito print-table" 62 | (e/report e/print-table))) 63 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject espejito "0.2.0" 2 | :description "Inter-layer latency finder for single-threaded processing" 3 | :url "https://github.com/kumarshantanu/espejito" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :global-vars {*warn-on-reflection* true 7 | *assert* true 8 | *unchecked-math* :warn-on-boxed} 9 | :profiles {:provided {:dependencies [[org.clojure/clojure "1.7.0"]]} 10 | :cljs {:plugins [[lein-cljsbuild "1.1.7"] 11 | [lein-doo "0.1.10"]] 12 | :doo {:build "test"} 13 | :cljsbuild {:builds {:test {:source-paths ["src" "test" "test-doo"] 14 | :compiler {:main espejito.runner 15 | :output-dir "target/out" 16 | :output-to "target/test/core.js" 17 | :target :nodejs 18 | :optimizations :none 19 | :source-map true 20 | :pretty-print true}}}} 21 | :prep-tasks [["cljsbuild" "once"]] 22 | :hooks [leiningen.cljsbuild]} 23 | :ctn {:dependencies [[org.clojure/tools.nrepl "0.2.13"]]} 24 | :c07 {:dependencies [[org.clojure/clojure "1.7.0"]]} 25 | :c08 {:dependencies [[org.clojure/clojure "1.8.0"]]} 26 | :c09 {:dependencies [[org.clojure/clojure "1.9.0"]]} 27 | :c10 {:dependencies [[org.clojure/clojure "1.10.2"]]} 28 | :s09 {:dependencies [[org.clojure/clojure "1.10.2"] 29 | [org.clojure/clojurescript "1.9.946"]]} 30 | :s10 {:dependencies [[org.clojure/clojure "1.10.2"] 31 | [org.clojure/clojurescript "1.10.339"]]} 32 | :dln {:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}} 33 | :aliases {"clj-test" ["with-profile" "c07:c08:c09:c10" "test"] 34 | "cljs-test" ["with-profile" "cljs,s09:cljs,s10" "doo" "node" "once"]} 35 | :deploy-repositories [["releases" {:url "https://clojars.org" :creds :gpg}]]) 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # espejito 2 | 3 | [![cljdoc badge](https://cljdoc.org/badge/espejito/espejito)](https://cljdoc.org/d/espejito/espejito) 4 | 5 | A Clojure/ClojureScript library to find latency across measurement points in single-threaded call trees. 6 | 7 | Sample output: 8 | 9 | ``` 10 | | :name | :cumulative | :cumul-% | :individual | :indiv-% | :thrown? | 11 | |-----------------+-------------+----------+-------------+----------+---------------------| 12 | | outer | 357.82 ms | 100.00 % | 103.037 ms | 28.80 % | | 13 | | inner | 204.407 ms | 57.13 % | 150.723 ms | 42.12 % | java.lang.Exception | 14 | | inner-most | 53.684 ms | 15.00 % | 53.684 ms | 15.00 % | | 15 | | inner-sibling | 50.376 ms | 14.08 % | 50.376 ms | 14.08 % | | 16 | ``` 17 | 18 | ## Usage 19 | 20 | Leiningen coordinates: `[espejito "0.2.0"]` 21 | 22 | Requires Clojure 1.7 or higher, ClojureScript 1.9 or higher 23 | 24 | ### Requiring namespace 25 | ```clojure 26 | (:require [espejito.core :as e]) 27 | ``` 28 | 29 | ### Starting to monitor 30 | 31 | Wrap your outer-most layer with the following call 32 | 33 | ```clojure 34 | (e/report e/print-table 35 | ...) ; body of code 36 | ``` 37 | 38 | ### Measure at every layer 39 | 40 | ```clojure 41 | (e/measure "layer-name" 42 | ...) ; body of code to measure 43 | ``` 44 | 45 | Or 46 | 47 | ```clojure 48 | ;; f is the function to wrap with measurement 49 | (e/wrap-measure f "function-name") 50 | ``` 51 | 52 | The measure calls can be spread across several namespaces. Make sure that the layer-name is unique for every 53 | measurement point. 54 | 55 | ### Instrumentation support on the JVM 56 | 57 | The following convenience API is available on the JVM: 58 | 59 | ```clojure 60 | (require '[espejito.instrument :as ins]) 61 | 62 | ;; to instrument functions for latency measurement 63 | (doseq ["com.myapp/foo" 64 | "com.myapp/bar" 65 | "com.myapp/baz"] 66 | (ins/instrument-measure each)) 67 | ``` 68 | 69 | Then the report generated using `(e/report e/print-table ...)` looks 70 | something like the following: 71 | 72 | ``` 73 | | :name | :cumulative | :cumul-% | :individual | :indiv-% | :thrown? | 74 | |-------------------+---------------+----------+---------------+----------+----------| 75 | | com.myapp/foo | 606.254183 ms | 100.00 % | 301.916861 ms | 49.80 % | | 76 | | com.myapp/bar | 304.337322 ms | 50.20 % | 203.490408 ms | 33.57 % | | 77 | | com.myapp/baz | 100.846914 ms | 16.63 % | 100.846914 ms | 16.63 % | | 78 | ``` 79 | 80 | ## Caveats 81 | 82 | This library assumes single-threaded code path only. For new/other threads you must use separate `report` for those 83 | threads. 84 | 85 | ## License 86 | 87 | Copyright © 2015-2021 Shantanu Kumar 88 | 89 | Distributed under the Eclipse Public License either version 1.0 or (at 90 | your option) any later version. 91 | -------------------------------------------------------------------------------- /src/espejito/internal.cljc: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Shantanu Kumar. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file LICENSE at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | 10 | (ns espejito.internal) 11 | 12 | 13 | (defn expected 14 | "Throw illegal input exception citing `expectation` and what was `found` did not match. Optionally accept a predicate 15 | fn to test `found` before throwing the exception." 16 | ([expectation found] 17 | (throw (ex-info 18 | (str "Expected " expectation ", but found (" (pr-str (type found)) ") " (pr-str found)) 19 | {:found found}))) 20 | ([pred expectation found] 21 | (when-not (pred found) 22 | (expected expectation found)))) 23 | 24 | 25 | (defn percent 26 | ^double [^long numerator ^long denominator] 27 | (double (/ (* 100 numerator) denominator))) 28 | 29 | 30 | (def ^:const nanos-to-seconds 1000000000) 31 | 32 | 33 | (def ^:const nanos-to-millis 1000000) 34 | 35 | 36 | (def ^:const nanos-to-micros 1000) 37 | 38 | 39 | (defn nanos 40 | "Return duration in nanoseconds since Epoch, or since the supplied timestamp (in nanos)." 41 | (^long [] 42 | #?(:cljs (unchecked-multiply (.getTime (js/Date.)) nanos-to-millis) 43 | :clj (System/nanoTime))) 44 | (^long [^long start] 45 | (unchecked-subtract (nanos) start))) 46 | 47 | 48 | (defn human-readable-latency 49 | "Convert nano-second latency to human-readable form" 50 | [^long nanos] 51 | (cond 52 | (> nanos nanos-to-seconds) (str (double (/ nanos nanos-to-seconds)) " s") 53 | (> nanos nanos-to-millis) (str (double (/ nanos nanos-to-millis)) " ms") 54 | (> nanos nanos-to-micros) (str (double (/ nanos nanos-to-micros)) " µs") 55 | :otherwise (str nanos "ns"))) 56 | 57 | 58 | (def ^String padding (apply str (repeat 100 \space))) 59 | 60 | 61 | (defn indent-name 62 | [^long max-name-width ^long level name] 63 | (-> (str (when (pos? level) (apply str (repeat (* 2 level) \space))) name padding) 64 | (subs 0 max-name-width))) 65 | 66 | 67 | (declare collect-children-report) 68 | 69 | 70 | (defn collect-child-report 71 | [transient-collector ^long level [name ^long cumulative-latency-ns thrown? children-metrics]] 72 | (conj! transient-collector 73 | {:name name 74 | :level level 75 | :cumulative-latency-ns cumulative-latency-ns 76 | :individual-latency-ns (unchecked-subtract ^long cumulative-latency-ns 77 | (let [^long children-latency-ns (->> children-metrics 78 | (map second) 79 | (reduce unchecked-add 0))] 80 | children-latency-ns)) 81 | :thrown? thrown?}) 82 | (collect-children-report transient-collector (inc level) children-metrics)) 83 | 84 | 85 | (defn collect-children-report [transient-collector ^long level children-metrics] 86 | (doseq [each children-metrics] 87 | (collect-child-report transient-collector level each))) 88 | 89 | 90 | (defn flatten-children-report 91 | [nested-metrics] 92 | (let [result (transient [])] 93 | (collect-children-report result 0 nested-metrics) 94 | (persistent! result))) -------------------------------------------------------------------------------- /src/espejito/core.cljc: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Shantanu Kumar. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file LICENSE at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | 10 | (ns espejito.core 11 | #?(:cljs (:require-macros espejito.core)) 12 | (:require 13 | #?(:cljs [goog.string :as gstring]) 14 | #?(:cljs [goog.string.format]) 15 | #?(:cljs [cljs.pprint :include-macros true :as pp] 16 | :clj [clojure.pprint :as pp]) 17 | [espejito.internal :as i])) 18 | 19 | 20 | 21 | (def ^:dynamic *metrics* nil) 22 | 23 | 24 | (defmacro measure 25 | "Use this at layer boundaries in code. Not recommended for tight loops - may cause out-of-memory situation!" 26 | [name & body] 27 | (let [esym (gensym "ex")] 28 | `(if (some? *metrics*) 29 | (let [start# (i/nanos) 30 | children-metrics# (transient [])] 31 | (try 32 | (let [result# (binding [*metrics* children-metrics#] 33 | ~@body)] 34 | (conj! *metrics* [~name (i/nanos start#) nil 35 | (persistent! children-metrics#)]) 36 | result#) 37 | (catch ~(if (:ns &env) `js/Error `Throwable) ~esym 38 | (conj! *metrics* [~name (i/nanos start#) ~(if (:ns &env) 39 | `(if-let [ctor# (.-constructor ~esym)] 40 | (.-name ctor#) 41 | "unknown") 42 | `(.getName ^Class (class ~esym))) 43 | (persistent! children-metrics#)]) 44 | (throw ~esym)))) 45 | (do 46 | ~@body)))) 47 | 48 | 49 | (defn wrap-measure 50 | "Wrap given function such that it measures latency when invoked." 51 | [f measure-name] 52 | (fn espejito-measured [& args] 53 | (measure measure-name 54 | (apply f args)))) 55 | 56 | 57 | (defn print-table 58 | "Print the report in a tabular format. Argument table-printer is an arity-2 fn that accepts header and rows." 59 | ([nested-metrics] 60 | (print-table 50 nested-metrics)) 61 | ([^long name-column-width nested-metrics] 62 | (print-table pp/print-table name-column-width nested-metrics)) 63 | ([table-printer ^long name-column-width nested-metrics] 64 | (if-let [flat-metrics (seq (i/flatten-children-report nested-metrics))] 65 | (let [total-ns (:cumulative-latency-ns (first flat-metrics))] 66 | (->> flat-metrics 67 | (mapv (fn [{:keys [name level cumulative-latency-ns individual-latency-ns] :as m}] 68 | (assoc m 69 | :name (i/indent-name name-column-width level name) 70 | :cumulative (i/human-readable-latency cumulative-latency-ns) 71 | :cumul-% (#?(:cljs gstring/format :clj format) "%.2f %%" (i/percent cumulative-latency-ns total-ns)) 72 | :individual (i/human-readable-latency individual-latency-ns) 73 | :indiv-% (#?(:cljs gstring/format :clj format) "%.2f %%" (i/percent individual-latency-ns total-ns))))) 74 | (table-printer [:name :cumulative :cumul-% :individual :indiv-% :thrown?]))) 75 | (println "\nNo data to report!")))) 76 | 77 | 78 | (defmacro report 79 | "Use this at the outermost periphery of the code." 80 | [f & body] 81 | `(binding [*metrics* (transient [])] 82 | (try 83 | ~@body 84 | (finally 85 | (~f (persistent! *metrics*)))))) -------------------------------------------------------------------------------- /src/espejito/instrument.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Shantanu Kumar. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file LICENSE at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | 10 | (ns espejito.instrument 11 | (:require 12 | [clojure.string :as string] 13 | [espejito.core :as e] 14 | [espejito.internal :as i]) 15 | (:import 16 | [java.io FileNotFoundException])) 17 | 18 | 19 | (defn shorten-ns 20 | "Given a fully qualified var name, shorten the namespace portion for 21 | conciseness and readability and return the fully qualified short name." 22 | (^String [^String fq-var-name] 23 | (shorten-ns fq-var-name {})) 24 | (^String [^String fq-var-name {:keys [^long intact-token-count] 25 | :or {intact-token-count 2}}] 26 | (let [ns-name-pair (string/split fq-var-name #"/")] 27 | (if (= 2 (count ns-name-pair)) 28 | (let [[ns-name var-name] ns-name-pair 29 | ns-tokens (string/split ns-name #"\.") 30 | ns-tcount (count ns-tokens) 31 | ns-inits (->> ns-tokens 32 | (mapv first) 33 | (take (max (- ns-tcount intact-token-count) 0))) 34 | ns-suffix (->> ns-tokens 35 | (take-last (min ns-tcount intact-token-count))) 36 | actual-ns (->> ns-suffix 37 | (concat ns-inits) 38 | (string/join \.))] 39 | (str actual-ns "/" var-name)) 40 | fq-var-name)))) 41 | 42 | 43 | (defn resolve-var 44 | "Given a fully qualified var name, resolve the var object and return it." 45 | [^String fq-var-name] 46 | ;; ensure that var name is non-empty 47 | (when (empty? fq-var-name) 48 | (throw (ex-info "Empty var name"))) 49 | ;; ensure that var name is correctly formatted 50 | (let [first-slash-at (.indexOf fq-var-name "/") 51 | last-slash-at (.lastIndexOf fq-var-name "/")] 52 | (when-not (and (pos? first-slash-at) 53 | (< last-slash-at (unchecked-dec (.length fq-var-name))) 54 | (= last-slash-at first-slash-at)) 55 | (throw (ex-info (str "Malformed fully-qualified var name: " 56 | (pr-str fq-var-name)))))) 57 | ;; ensure that the namespace is loaded 58 | (let [[ns-name var-name] (string/split fq-var-name #"/")] 59 | (try 60 | (require (symbol ns-name)) 61 | (catch FileNotFoundException _ 62 | (when-not (= "user" ns-name) ; ignore implicit ns at the REPL 63 | (throw (ex-info (format "Cannot find ns '%s'" ns-name) {})))))) 64 | ;; find the var now 65 | (find-var (symbol fq-var-name))) 66 | 67 | 68 | (defn instrument-measure 69 | "Given a fully qualified var name, instrument the var such that upon execution it participates in Espejito latency measurement." 70 | ([var-or-varname] 71 | (instrument-measure var-or-varname {})) 72 | ([var-or-varname {:keys [name-encoder] 73 | :or {name-encoder shorten-ns} 74 | :as options}] 75 | (let [[fq-name the-var] (cond 76 | ;; already a var 77 | (var? var-or-varname) 78 | (let [m (meta var-or-varname) 79 | n (format "%s/%s" 80 | (ns-name (:ns m)) 81 | (:name m))] 82 | [n (resolve-var n)]) 83 | ;; a string 84 | (string? var-or-varname) 85 | [var-or-varname (resolve-var var-or-varname)] 86 | ;; a symbol 87 | (symbol? var-or-varname) 88 | (instrument-measure (str var-or-varname)) 89 | ;; a keyword 90 | (keyword? var-or-varname) 91 | (instrument-measure (format "%s/%s" 92 | (namespace var-or-varname) 93 | (name var-or-varname))) 94 | ;; or else 95 | :otherwise 96 | (i/expected "a var or a fully-qualified var name" 97 | var-or-varname))] 98 | (alter-var-root the-var (fn [f] 99 | (e/wrap-measure f (name-encoder fq-name))))))) 100 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 4 | 5 | 1. DEFINITIONS 6 | 7 | "Contribution" means: 8 | 9 | a) in the case of the initial Contributor, the initial code and 10 | documentation distributed under this Agreement, and 11 | 12 | b) in the case of each subsequent Contributor: 13 | 14 | i) changes to the Program, and 15 | 16 | ii) additions to the Program; 17 | 18 | where such changes and/or additions to the Program originate from and are 19 | distributed by that particular Contributor. A Contribution 'originates' from 20 | a Contributor if it was added to the Program by such Contributor itself or 21 | anyone acting on such Contributor's behalf. Contributions do not include 22 | additions to the Program which: (i) are separate modules of software 23 | distributed in conjunction with the Program under their own license 24 | agreement, and (ii) are not derivative works of the Program. 25 | 26 | "Contributor" means any person or entity that distributes the Program. 27 | 28 | "Licensed Patents" mean patent claims licensable by a Contributor which are 29 | necessarily infringed by the use or sale of its Contribution alone or when 30 | combined with the Program. 31 | 32 | "Program" means the Contributions distributed in accordance with this 33 | Agreement. 34 | 35 | "Recipient" means anyone who receives the Program under this Agreement, 36 | including all Contributors. 37 | 38 | 2. GRANT OF RIGHTS 39 | 40 | a) Subject to the terms of this Agreement, each Contributor hereby grants 41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 42 | reproduce, prepare derivative works of, publicly display, publicly perform, 43 | distribute and sublicense the Contribution of such Contributor, if any, and 44 | such derivative works, in source code and object code form. 45 | 46 | b) Subject to the terms of this Agreement, each Contributor hereby grants 47 | Recipient a non-exclusive, worldwide, royalty-free patent license under 48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 49 | transfer the Contribution of such Contributor, if any, in source code and 50 | object code form. This patent license shall apply to the combination of the 51 | Contribution and the Program if, at the time the Contribution is added by the 52 | Contributor, such addition of the Contribution causes such combination to be 53 | covered by the Licensed Patents. The patent license shall not apply to any 54 | other combinations which include the Contribution. No hardware per se is 55 | licensed hereunder. 56 | 57 | c) Recipient understands that although each Contributor grants the licenses 58 | to its Contributions set forth herein, no assurances are provided by any 59 | Contributor that the Program does not infringe the patent or other 60 | intellectual property rights of any other entity. Each Contributor disclaims 61 | any liability to Recipient for claims brought by any other entity based on 62 | infringement of intellectual property rights or otherwise. As a condition to 63 | exercising the rights and licenses granted hereunder, each Recipient hereby 64 | assumes sole responsibility to secure any other intellectual property rights 65 | needed, if any. For example, if a third party patent license is required to 66 | allow Recipient to distribute the Program, it is Recipient's responsibility 67 | to acquire that license before distributing the Program. 68 | 69 | d) Each Contributor represents that to its knowledge it has sufficient 70 | copyright rights in its Contribution, if any, to grant the copyright license 71 | set forth in this Agreement. 72 | 73 | 3. REQUIREMENTS 74 | 75 | A Contributor may choose to distribute the Program in object code form under 76 | its own license agreement, provided that: 77 | 78 | a) it complies with the terms and conditions of this Agreement; and 79 | 80 | b) its license agreement: 81 | 82 | i) effectively disclaims on behalf of all Contributors all warranties and 83 | conditions, express and implied, including warranties or conditions of title 84 | and non-infringement, and implied warranties or conditions of merchantability 85 | and fitness for a particular purpose; 86 | 87 | ii) effectively excludes on behalf of all Contributors all liability for 88 | damages, including direct, indirect, special, incidental and consequential 89 | damages, such as lost profits; 90 | 91 | iii) states that any provisions which differ from this Agreement are offered 92 | by that Contributor alone and not by any other party; and 93 | 94 | iv) states that source code for the Program is available from such 95 | Contributor, and informs licensees how to obtain it in a reasonable manner on 96 | or through a medium customarily used for software exchange. 97 | 98 | When the Program is made available in source code form: 99 | 100 | a) it must be made available under this Agreement; and 101 | 102 | b) a copy of this Agreement must be included with each copy of the Program. 103 | 104 | Contributors may not remove or alter any copyright notices contained within 105 | the Program. 106 | 107 | Each Contributor must identify itself as the originator of its Contribution, 108 | if any, in a manner that reasonably allows subsequent Recipients to identify 109 | the originator of the Contribution. 110 | 111 | 4. COMMERCIAL DISTRIBUTION 112 | 113 | Commercial distributors of software may accept certain responsibilities with 114 | respect to end users, business partners and the like. While this license is 115 | intended to facilitate the commercial use of the Program, the Contributor who 116 | includes the Program in a commercial product offering should do so in a 117 | manner which does not create potential liability for other Contributors. 118 | Therefore, if a Contributor includes the Program in a commercial product 119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend 120 | and indemnify every other Contributor ("Indemnified Contributor") against any 121 | losses, damages and costs (collectively "Losses") arising from claims, 122 | lawsuits and other legal actions brought by a third party against the 123 | Indemnified Contributor to the extent caused by the acts or omissions of such 124 | Commercial Contributor in connection with its distribution of the Program in 125 | a commercial product offering. The obligations in this section do not apply 126 | to any claims or Losses relating to any actual or alleged intellectual 127 | property infringement. In order to qualify, an Indemnified Contributor must: 128 | a) promptly notify the Commercial Contributor in writing of such claim, and 129 | b) allow the Commercial Contributor tocontrol, and cooperate with the 130 | Commercial Contributor in, the defense and any related settlement 131 | negotiations. The Indemnified Contributor may participate in any such claim 132 | at its own expense. 133 | 134 | For example, a Contributor might include the Program in a commercial product 135 | offering, Product X. That Contributor is then a Commercial Contributor. If 136 | that Commercial Contributor then makes performance claims, or offers 137 | warranties related to Product X, those performance claims and warranties are 138 | such Commercial Contributor's responsibility alone. Under this section, the 139 | Commercial Contributor would have to defend claims against the other 140 | Contributors related to those performance claims and warranties, and if a 141 | court requires any other Contributor to pay any damages as a result, the 142 | Commercial Contributor must pay those damages. 143 | 144 | 5. NO WARRANTY 145 | 146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON 147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR 149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A 150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the 151 | appropriateness of using and distributing the Program and assumes all risks 152 | associated with its exercise of rights under this Agreement , including but 153 | not limited to the risks and costs of program errors, compliance with 154 | applicable laws, damage to or loss of data, programs or equipment, and 155 | unavailability or interruption of operations. 156 | 157 | 6. DISCLAIMER OF LIABILITY 158 | 159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 166 | OF SUCH DAMAGES. 167 | 168 | 7. GENERAL 169 | 170 | If any provision of this Agreement is invalid or unenforceable under 171 | applicable law, it shall not affect the validity or enforceability of the 172 | remainder of the terms of this Agreement, and without further action by the 173 | parties hereto, such provision shall be reformed to the minimum extent 174 | necessary to make such provision valid and enforceable. 175 | 176 | If Recipient institutes patent litigation against any entity (including a 177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 178 | (excluding combinations of the Program with other software or hardware) 179 | infringes such Recipient's patent(s), then such Recipient's rights granted 180 | under Section 2(b) shall terminate as of the date such litigation is filed. 181 | 182 | All Recipient's rights under this Agreement shall terminate if it fails to 183 | comply with any of the material terms or conditions of this Agreement and 184 | does not cure such failure in a reasonable period of time after becoming 185 | aware of such noncompliance. If all Recipient's rights under this Agreement 186 | terminate, Recipient agrees to cease use and distribution of the Program as 187 | soon as reasonably practicable. However, Recipient's obligations under this 188 | Agreement and any licenses granted by Recipient relating to the Program shall 189 | continue and survive. 190 | 191 | Everyone is permitted to copy and distribute copies of this Agreement, but in 192 | order to avoid inconsistency the Agreement is copyrighted and may only be 193 | modified in the following manner. The Agreement Steward reserves the right to 194 | publish new versions (including revisions) of this Agreement from time to 195 | time. No one other than the Agreement Steward has the right to modify this 196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 197 | Eclipse Foundation may assign the responsibility to serve as the Agreement 198 | Steward to a suitable separate entity. Each new version of the Agreement will 199 | be given a distinguishing version number. The Program (including 200 | Contributions) may always be distributed subject to the version of the 201 | Agreement under which it was received. In addition, after a new version of 202 | the Agreement is published, Contributor may elect to distribute the Program 203 | (including its Contributions) under the new version. Except as expressly 204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 205 | licenses to the intellectual property of any Contributor under this 206 | Agreement, whether expressly, by implication, estoppel or otherwise. All 207 | rights in the Program not expressly granted under this Agreement are 208 | reserved. 209 | 210 | This Agreement is governed by the laws of the State of New York and the 211 | intellectual property laws of the United States of America. No party to this 212 | Agreement will bring a legal action under this Agreement more than one year 213 | after the cause of action arose. Each party waives its rights to a jury trial 214 | in any resulting litigation. 215 | --------------------------------------------------------------------------------