Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions bin/memprof
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ require 'optparse'
require 'restclient'
require 'term/ansicolor'

MEMPROF_URL = "https://memprof.com/upload"

MEMPROF_BANNER = <<-EOF
Memprof Uploader
http://www.memprof.com
======================

EOF
Expand All @@ -25,6 +22,7 @@ class MemprofUploader
opts.on("-p", "--pid <pid>", Integer, "PID of the process to dump (required)") {|arg| @pid = arg }
opts.on("-n", "--name <name>", "Name for your dump (required)") {|arg| @name = arg }
opts.on("-k", "--key <key>", "Memprof.com API key (required)") {|arg| @key = arg }
opts.on("-u", "--url <url>", "Memprof.com application URL (default https://memprof.com)") {|arg| @url = arg }
opts.on("-d", "--[no-]delete", "Delete dump file after uploading (default true)") {|arg| @delete_dump = arg }
opts.on("-s", "--seconds <seconds>",
Integer, "Seconds to wait for the dump (default 300)") {|arg| @secs = arg }
Expand Down Expand Up @@ -61,10 +59,19 @@ class MemprofUploader
end
end

# Make this default to https://memprof.com if the user didn't pass custom application URL.
@url ||= "https://memprof.com"

unless @url =~ /^https?:\/\/(([a-z0-9\-]+\.)+[a-z]{2,4}|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(:\d+)?(\/.*)?$/i
fail_with("#{@url} does not look like a correct URL")
end

@upload_url = "#{@url}/upload"

# Make this default to true if the user didn't pass any preference.
@delete_dump = true if @delete_dump.nil?

# Make this default to 60 if the user didn't pass the number of seconds.
# Make this default to 300 if the user didn't pass the number of seconds.
@secs ||= 300

if @file
Expand Down Expand Up @@ -142,8 +149,8 @@ class MemprofUploader

file = File.open(filename, "r")

puts "\nUploading to memprof.com..."
response = RestClient.post(MEMPROF_URL, :upload => file, :name => name, :key => key)
puts "\nUploading to #{@url}..."
response = RestClient.post(@upload_url, :upload => file, :name => name, :key => key)

puts "Response from server:"
p response.to_s
Expand Down Expand Up @@ -173,4 +180,4 @@ class MemprofUploader

end

MemprofUploader.new(ARGV).run!
MemprofUploader.new(ARGV).run!