Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1623 from OpenBazaar/profile
Browse files Browse the repository at this point in the history
Add profiling option to mobile Node
  • Loading branch information
cpacia authored Jul 31, 2019
2 parents 3da783d + 547913e commit 9d5e4e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mobile/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ type NodeConfig struct {

// The coin to use
CoinType wallet.CoinType

// Run the pprof profiler on port 6060
Profile bool
}
14 changes: 13 additions & 1 deletion mobile/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -53,6 +54,7 @@ import (
"github.com/natefinch/lumberjack"
"github.com/op/go-logging"
"github.com/tyler-smith/go-bip39"
_ "net/http/pprof"
)

var log = logging.MustGetLogger("mobile")
Expand All @@ -75,14 +77,15 @@ var (
)

// NewNode create the configuration file for a new node
func NewNode(repoPath string, authenticationToken string, testnet bool, userAgent string, walletTrustedPeer string, password string, mnemonic string) *Node {
func NewNode(repoPath string, authenticationToken string, testnet bool, userAgent string, walletTrustedPeer string, password string, mnemonic string, profile bool) *Node {
// Node config
nodeconfig := &NodeConfig{
RepoPath: repoPath,
AuthenticationToken: authenticationToken,
Testnet: testnet,
UserAgent: userAgent,
WalletTrustedPeer: walletTrustedPeer,
Profile: profile,
}

// Use Mobile struct to carry config data
Expand Down Expand Up @@ -339,6 +342,15 @@ func (n *Node) startIPFSNode(repoPath string, config *ipfscore.BuildCfg) (*ipfsc

// Start start openbazaard (OpenBazaar daemon)
func (n *Node) Start() error {
if n.config.Profile {
go func() {
listenAddr := net.JoinHostPort("", "6060")
profileRedirect := http.RedirectHandler("/debug/pprof",
http.StatusSeeOther)
http.Handle("/", profileRedirect)
log.Errorf("%v", http.ListenAndServe(listenAddr, nil))
}()
}
nd, ctx, err := n.startIPFSNode(n.config.RepoPath, n.ipfsConfig)
if err != nil {
return err
Expand Down

0 comments on commit 9d5e4e3

Please sign in to comment.