aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/md/docs/sol_profiler
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-01-08 19:23:33 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-01-08 21:48:06 +0800
commit2c974b5f3ffa0e9736000273e39cdeee4a251b94 (patch)
treea1772f93d796e3b4ba7a988194a44a3e8bcd6d31 /packages/website/md/docs/sol_profiler
parent0ac36cef288deecd36caa601c53d13517eef5ca8 (diff)
downloaddexon-0x-contracts-2c974b5f3ffa0e9736000273e39cdeee4a251b94.tar.gz
dexon-0x-contracts-2c974b5f3ffa0e9736000273e39cdeee4a251b94.tar.zst
dexon-0x-contracts-2c974b5f3ffa0e9736000273e39cdeee4a251b94.zip
Refactor out sol-cov, sol-profiler and sol-trace into their separate packages
Diffstat (limited to 'packages/website/md/docs/sol_profiler')
-rw-r--r--packages/website/md/docs/sol_profiler/installation.md17
-rw-r--r--packages/website/md/docs/sol_profiler/introduction.md1
-rw-r--r--packages/website/md/docs/sol_profiler/usage.md62
3 files changed, 80 insertions, 0 deletions
diff --git a/packages/website/md/docs/sol_profiler/installation.md b/packages/website/md/docs/sol_profiler/installation.md
new file mode 100644
index 000000000..be9a365f5
--- /dev/null
+++ b/packages/website/md/docs/sol_profiler/installation.md
@@ -0,0 +1,17 @@
+**Install**
+
+```bash
+yarn add @0x/sol-profiler
+```
+
+**Import**
+
+```javascript
+import { ProfilerSubprovider } from '@0x/sol-profiler';
+```
+
+or
+
+```javascript
+var ProfilerSubprovider = require('@0x/sol-profiler').ProfilerSubprovider;
+```
diff --git a/packages/website/md/docs/sol_profiler/introduction.md b/packages/website/md/docs/sol_profiler/introduction.md
new file mode 100644
index 000000000..bd53fb0fe
--- /dev/null
+++ b/packages/website/md/docs/sol_profiler/introduction.md
@@ -0,0 +1 @@
+Welcome to the [sol-profiler](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-profiler) documentation! Sol-profiler is a Solidity profiler tool.
diff --git a/packages/website/md/docs/sol_profiler/usage.md b/packages/website/md/docs/sol_profiler/usage.md
new file mode 100644
index 000000000..35ea140da
--- /dev/null
+++ b/packages/website/md/docs/sol_profiler/usage.md
@@ -0,0 +1,62 @@
+Sol-profiler uses transaction traces in order to figure out which lines of Solidity source code have been covered by your tests. In order for it to gather these traces, you must add the `ProfilerSubprovider` to the [ProviderEngine](https://github.com/MetaMask/provider-engine) instance you use when running your Solidity tests. If you're unfamiliar with ProviderEngine, please read the [Web3 Provider explained](https://0x.org/wiki#Web3-Provider-Explained) wiki article.
+
+The ProfilerSubprovider eavesdrops on the `eth_sendTransaction` and `eth_call` RPC calls and collects traces after each call using `debug_traceTransaction`. `eth_call`'s' don't generate traces - so we take a snapshot, re-submit it as a transaction, get the trace and then revert the snapshot.
+
+Profiler subprovider needs some info about your contracts (`srcMap`, `bytecode`). It gets that info from your project's artifacts. Some frameworks have their own artifact format. Some artifact formats don't actually contain all the neccessary data.
+
+In order to use `ProfilerSubprovider` with your favorite framework you need to pass an `artifactsAdapter` to it.
+
+### Sol-compiler
+
+If you are generating your artifacts with [@0x/sol-compiler](https://0x.org/docs/sol-compiler) you can use the `SolCompilerArtifactsAdapter` we've implemented for you.
+
+```typescript
+import { SolCompilerArtifactsAdapter } from '@0x/sol-profiler';
+const artifactsPath = 'src/artifacts';
+const contractsPath = 'src/contracts';
+const artifactsAdapter = new SolCompilerArtifactsAdapter(artifactsPath, contractsPath);
+```
+
+### Truffle
+
+If your project is using [Truffle](https://truffleframework.com/), we've written a `TruffleArtifactsAdapter`for you.
+
+```typescript
+import { TruffleArtifactAdapter } from '@0x/sol-profiler';
+const contractsPath = 'src/contracts';
+const artifactAdapter = new TruffleArtifactAdapter(contractsDir);
+```
+
+Because truffle artifacts don't have all the data we need - we actually will recompile your contracts under the hood. That's why you don't need to pass an `artifactsPath`.
+
+### Other framework/toolset
+
+You'll need to write your own artifacts adapter. It should extend `AbstractArtifactsAdapter`.
+Look at the code of the two adapters above for examples.
+
+### Usage
+
+```typescript
+import { ProfilerSubprovider } from '@0x/sol-profiler';
+import ProviderEngine = require('web3-provider-engine');
+
+const provider = new ProviderEngine();
+
+const artifactsPath = 'src/artifacts';
+const contractsPath = 'src/contracts';
+const networkId = 50;
+// Some calls might not have `from` address specified. Nevertheless - transactions need to be submitted from an address with at least some funds. defaultFromAddress is the address that will be used to submit those calls as transactions from.
+const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
+const isVerbose = true;
+const profilerSubprovider = new ProfilerSubprovider(artifactsAdapter, defaultFromAddress, isVerbose);
+
+provider.addProvider(profilerSubprovider);
+```
+
+After your test suite is complete (e.g in the Mocha global `after` hook), you'll need to call:
+
+```typescript
+await profilerSubprovider.writeProfilerAsync();
+```
+
+This will create a `profiler.json` file in a `profiler` directory. This file has an [Istanbul format](https://github.com/gotwarlost/istanbul/blob/master/profiler.json.md) - so you can use it with any of the existing Istanbul reporters.