perfmonger 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb47ad299c6b0e503298b6fd345357760f6db238
4
- data.tar.gz: bc212e88228a080c65dfedbb8c96437130d03838
3
+ metadata.gz: 0b02aaea69043dcf1560fd042e2af5f571c88e06
4
+ data.tar.gz: 07081ebc86aa30f921b360cc0c2d82fd958d3c7f
5
5
  SHA512:
6
- metadata.gz: 9a4f21ab77b86679b78a9ca8628bc6bfbecec598ab2001397a6bb22aaa78cb4aa2cb7aa8de787e858da05666232161c59e53d980a6952355f083bd337350d84f
7
- data.tar.gz: d5ac7fadddd9ae96b9da5d4036081fff64f7737db49259ac7ec406cc11491211662b001479c01039c674b0423ce3f6346cf8234e268860362baa4789bed61521
6
+ metadata.gz: 3d4c1d36d69a8d010574985ef3ca8e1760c715b9eb079d87cc4eab5de9adf6a05373a01d351e5286e8000f7fe90148e2af7ac3036abc9eab3bc9a0c329bd18d0
7
+ data.tar.gz: 98347d85d24cdbd38ee6cf39cf1a6961a957a56da0d4c17700a2a8dfeb93c2e9438c9953f9bcd5233644249c2f659f1f6c4e4ec9c785bc3cb3835051efa04f98
data/NEWS CHANGED
@@ -1,3 +1,14 @@
1
+ ## XXXX-XX-XX: PerfMonger 0.9.0
2
+ * ...
3
+
4
+ ## 2016-11-22: PerfMonger 0.8.0
5
+ * New features
6
+ * [record] subcommand:
7
+ * Implemented "session" for preventing double start
8
+ * Add --background and --kill option for running perfmonger in background (useful for scripting)
9
+ * [summary] subcommand:
10
+ * Add --disk-only option to filter results of not interesting disks
11
+
1
12
  ## 2016-10-02: PerfMonger 0.7.1 released
2
13
 
3
14
  * Bug fix
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ task :cross_build_core do
14
14
  puts "Buildling binaries for each platform"
15
15
  Dir.chdir("./core") do
16
16
  sh "./build.sh"
17
+ sh "make"
17
18
  end
18
19
  end
19
20
 
data/core/Makefile CHANGED
@@ -1,23 +1,51 @@
1
+ # DO NOT EDIT MANUALLY
2
+ # generated by build.sh
1
3
 
2
- GOSRC := \
3
- subsystem/perfmonger.go \
4
- subsystem/perfmonger_linux.go \
5
- subsystem/stat.go \
6
- subsystem/usage.go
4
+ GOSRC := subsystem/perfmonger_darwin.go subsystem/perfmonger.go subsystem/perfmonger_linux.go subsystem/perfmonger_linux_test.go subsystem/stat.go subsystem/stat_test.go subsystem/usage.go subsystem/usage_test.go
7
5
 
8
- .PHONY: all clean
6
+ .PHONY: all build clean
9
7
 
10
- all: perfmonger-recorder perfmonger-player perfmonger-summarizer
8
+ all: build
11
9
 
12
- clean:
13
- rm -f perfmonger-recorder perfmonger-player perfmonger-summarizer
14
10
 
15
- perfmonger-recorder: perfmonger-recorder.go $(GOSRC)
16
- go build $<
11
+ ../lib/exec/perfmonger-recorder_linux_386: perfmonger-recorder.go $(GOSRC)
12
+ go build -o $@ perfmonger-recorder.go
13
+
14
+
15
+ ../lib/exec/perfmonger-player_linux_386: perfmonger-player.go $(GOSRC)
16
+ go build -o $@ perfmonger-player.go
17
+
18
+
19
+ ../lib/exec/perfmonger-summarizer_linux_386: perfmonger-summarizer.go $(GOSRC)
20
+ go build -o $@ perfmonger-summarizer.go
21
+
22
+
23
+ ../lib/exec/perfmonger-recorder_linux_amd64: perfmonger-recorder.go $(GOSRC)
24
+ go build -o $@ perfmonger-recorder.go
25
+
26
+
27
+ ../lib/exec/perfmonger-player_linux_amd64: perfmonger-player.go $(GOSRC)
28
+ go build -o $@ perfmonger-player.go
29
+
17
30
 
18
- perfmonger-player: perfmonger-player.go $(GOSRC)
19
- go build $<
31
+ ../lib/exec/perfmonger-summarizer_linux_amd64: perfmonger-summarizer.go $(GOSRC)
32
+ go build -o $@ perfmonger-summarizer.go
20
33
 
21
- perfmonger-summarizer: perfmonger-summarizer.go $(GOSRC)
22
- go build $<
34
+
35
+ ../lib/exec/perfmonger-recorder_darwin_amd64: perfmonger-recorder.go $(GOSRC)
36
+ go build -o $@ perfmonger-recorder.go
37
+
38
+
39
+ ../lib/exec/perfmonger-player_darwin_amd64: perfmonger-player.go $(GOSRC)
40
+ go build -o $@ perfmonger-player.go
41
+
42
+
43
+ ../lib/exec/perfmonger-summarizer_darwin_amd64: perfmonger-summarizer.go $(GOSRC)
44
+ go build -o $@ perfmonger-summarizer.go
45
+
46
+
47
+ build: ../lib/exec/perfmonger-recorder_linux_386 ../lib/exec/perfmonger-player_linux_386 ../lib/exec/perfmonger-summarizer_linux_386 ../lib/exec/perfmonger-recorder_linux_amd64 ../lib/exec/perfmonger-player_linux_amd64 ../lib/exec/perfmonger-summarizer_linux_amd64 ../lib/exec/perfmonger-recorder_darwin_amd64 ../lib/exec/perfmonger-player_darwin_amd64 ../lib/exec/perfmonger-summarizer_darwin_amd64
48
+
49
+ clean:
50
+ rm -f ../lib/exec/perfmonger-recorder_linux_386 ../lib/exec/perfmonger-player_linux_386 ../lib/exec/perfmonger-summarizer_linux_386 ../lib/exec/perfmonger-recorder_linux_amd64 ../lib/exec/perfmonger-player_linux_amd64 ../lib/exec/perfmonger-summarizer_linux_amd64 ../lib/exec/perfmonger-recorder_darwin_amd64 ../lib/exec/perfmonger-player_darwin_amd64 ../lib/exec/perfmonger-summarizer_darwin_amd64
23
51
 
data/core/build.sh CHANGED
@@ -31,18 +31,54 @@ else
31
31
  TARGET=("linux 386" "linux amd64" "darwin amd64")
32
32
  fi
33
33
 
34
- set -xe
34
+ set -e
35
+
36
+ GO_FILES=$(ls subsystem/*.go)
37
+
38
+ cat <<EOF > Makefile
39
+ # DO NOT EDIT MANUALLY
40
+ # generated by build.sh
41
+
42
+ GOSRC := $(echo ${GO_FILES})
43
+
44
+ .PHONY: all build clean
45
+
46
+ all: build
47
+
48
+ EOF
49
+
50
+ TARGETS=()
35
51
 
36
52
  for idx in $(seq 0 $((${#TARGET[@]}-1))); do
37
53
  set -- ${TARGET[$idx]}
38
54
  export GOOS=$1
39
55
  export GOARCH=$2
40
56
 
41
- go build -o ../lib/exec/perfmonger-recorder_${GOOS}_${GOARCH} \
42
- perfmonger-recorder.go
43
- go build -o ../lib/exec/perfmonger-player_${GOOS}_${GOARCH} \
44
- perfmonger-player.go
45
- go build -o ../lib/exec/perfmonger-summarizer_${GOOS}_${GOARCH} \
46
- perfmonger-summarizer.go
57
+ for subcmd in recorder player summarizer; do
58
+ TARGETS+=(../lib/exec/perfmonger-${subcmd}_${GOOS}_${GOARCH})
59
+
60
+ cat <<EOF >> Makefile
61
+
62
+ ../lib/exec/perfmonger-${subcmd}_${GOOS}_${GOARCH}: perfmonger-${subcmd}.go \$(GOSRC)
63
+ go build -o \$@ perfmonger-$subcmd.go
64
+
65
+ EOF
66
+ done
67
+
68
+ # go build -o ../lib/exec/perfmonger-recorder_${GOOS}_${GOARCH} \
69
+ # perfmonger-recorder.go &
70
+ # go build -o ../lib/exec/perfmonger-player_${GOOS}_${GOARCH} \
71
+ # perfmonger-player.go &
72
+ # go build -o ../lib/exec/perfmonger-summarizer_${GOOS}_${GOARCH} \
73
+ # perfmonger-summarizer.go &
74
+
47
75
  done
48
76
 
77
+ cat <<EOF >> Makefile
78
+
79
+ build: ${TARGETS[*]}
80
+
81
+ clean:
82
+ rm -f ${TARGETS[*]}
83
+
84
+ EOF
@@ -27,8 +27,7 @@ func showCpuStat(buffer *bytes.Buffer, prev_rec *ss.StatRecord, cur_rec *ss.Stat
27
27
  func showDiskStat(buffer *bytes.Buffer, prev_rec *ss.StatRecord, cur_rec *ss.StatRecord) error {
28
28
  dusage, err := ss.GetDiskUsage(
29
29
  prev_rec.Time, prev_rec.Disk,
30
- cur_rec.Time, cur_rec.Disk,
31
- )
30
+ cur_rec.Time, cur_rec.Disk)
32
31
  if err != nil {
33
32
  return err
34
33
  }
@@ -8,10 +8,15 @@ import (
8
8
  "flag"
9
9
  "fmt"
10
10
  "io"
11
+ "io/ioutil"
11
12
  "os"
12
13
  "os/exec"
13
14
  "os/signal"
15
+ "os/user"
16
+ "path"
17
+ "strconv"
14
18
  "strings"
19
+ "syscall"
15
20
  "time"
16
21
 
17
22
  "golang.org/x/crypto/ssh/terminal"
@@ -111,6 +116,55 @@ func main() {
111
116
  var out *bufio.Writer
112
117
  var err error
113
118
 
119
+ // Find existing session, or create new one
120
+ user, err := user.Current()
121
+ if err != nil {
122
+ panic(err)
123
+ }
124
+ session_file := path.Join(os.TempDir(),
125
+ fmt.Sprintf("perfmonger-%s-session.pid", user.Username))
126
+
127
+ lockfile := path.Join(os.TempDir(), ".perfmonger.lock")
128
+
129
+ // make lock file if not exists
130
+ session_exists := false
131
+
132
+ if _, err := os.Stat(lockfile); err != nil {
133
+ ioutil.WriteFile(lockfile, []byte(""), 0644)
134
+ }
135
+ fd, _ := syscall.Open("lock", syscall.O_RDONLY, 0000)
136
+ defer syscall.Close(fd)
137
+ syscall.Flock(fd, syscall.LOCK_EX)
138
+
139
+ if _, err := os.Stat(session_file); err == nil {
140
+ pidstr, err := ioutil.ReadFile(session_file)
141
+ pid, err := strconv.Atoi(string(pidstr))
142
+ if err != nil {
143
+ goto MakeNewSession
144
+ }
145
+
146
+ proc, err := os.FindProcess(pid)
147
+ err = proc.Signal(syscall.Signal(0))
148
+
149
+ if err == nil {
150
+ session_exists = true
151
+ goto Unlock
152
+ }
153
+ }
154
+ MakeNewSession:
155
+ err = ioutil.WriteFile(session_file, []byte(strconv.Itoa(os.Getpid())), 0644)
156
+ if err != nil {
157
+ panic(err)
158
+ }
159
+
160
+ Unlock:
161
+ syscall.Flock(fd, syscall.LOCK_UN)
162
+
163
+ if session_exists {
164
+ fmt.Fprintf(os.Stderr, "[ERROR] another perfmonger is already running.\n")
165
+ return
166
+ }
167
+
114
168
  parseArgs()
115
169
 
116
170
  hostname, _ := os.Hostname()
@@ -9,24 +9,31 @@ import (
9
9
  "fmt"
10
10
  "io"
11
11
  "os"
12
+ "regexp"
12
13
  "sort"
13
14
 
14
15
  ss "github.com/hayamiz/perfmonger/core/subsystem"
15
16
  )
16
17
 
17
18
  type SummaryOption struct {
18
- logfile string
19
- title string
20
- json bool
19
+ logfile string
20
+ title string
21
+ json bool
22
+ disk_only string
23
+ disk_only_regex *regexp.Regexp
21
24
  }
22
25
 
23
26
  var option SummaryOption
24
27
 
25
28
  func parseArgs() {
29
+ var err error
30
+
26
31
  flag.BoolVar(&option.json, "json",
27
32
  false, "Show summary in JSON")
28
33
  flag.StringVar(&option.title, "title",
29
34
  "", "Title of summary")
35
+ flag.StringVar(&option.disk_only, "disk-only",
36
+ "", "Select disk devices by regex")
30
37
 
31
38
  flag.Parse()
32
39
 
@@ -34,6 +41,11 @@ func parseArgs() {
34
41
  os.Exit(1)
35
42
  }
36
43
 
44
+ option.disk_only_regex, err = regexp.Compile(option.disk_only)
45
+ if err != nil {
46
+ panic(err)
47
+ }
48
+
37
49
  option.logfile = flag.Args()[0]
38
50
  }
39
51
 
@@ -99,9 +111,10 @@ func main() {
99
111
  }
100
112
 
101
113
  if fst_record.Disk != nil && lst_record.Disk != nil {
102
- disk_usage, err = ss.GetDiskUsage(
114
+ disk_usage, err = ss.GetDiskUsage1(
103
115
  fst_record.Time, fst_record.Disk,
104
- lst_record.Time, lst_record.Disk)
116
+ lst_record.Time, lst_record.Disk,
117
+ option.disk_only_regex)
105
118
  }
106
119
 
107
120
  if fst_record.Disk != nil && lst_record.Disk != nil {
@@ -5,6 +5,7 @@ import (
5
5
  "encoding/json"
6
6
  "errors"
7
7
  "fmt"
8
+ "regexp"
8
9
  "sort"
9
10
  "time"
10
11
  )
@@ -199,6 +200,11 @@ func avgDelta(v int64, w int64, interval float64) float64 {
199
200
  }
200
201
 
201
202
  func GetDiskUsage(t1 time.Time, d1 *DiskStat, t2 time.Time, d2 *DiskStat) (*DiskUsage, error) {
203
+ return GetDiskUsage1(t1, d1, t2, d2, nil)
204
+ }
205
+
206
+ func GetDiskUsage1(t1 time.Time, d1 *DiskStat, t2 time.Time, d2 *DiskStat,
207
+ filter *regexp.Regexp) (*DiskUsage, error) {
202
208
  interval := t2.Sub(t1)
203
209
  itv := interval.Seconds()
204
210
 
@@ -219,6 +225,11 @@ func GetDiskUsage(t1 time.Time, d1 *DiskStat, t2 time.Time, d2 *DiskStat) (*Disk
219
225
 
220
226
  for _, entry1 := range d1.Entries {
221
227
  name := entry1.Name
228
+ if filter != nil {
229
+ if !filter.MatchString(name) {
230
+ continue
231
+ }
232
+ }
222
233
  var entry2 *DiskStatEntry = nil
223
234
  for _, e := range d2.Entries {
224
235
  if e.Name == entry1.Name {
@@ -24,6 +24,7 @@ EOS
24
24
  @output_type = 'pdf'
25
25
  @output_prefix = ''
26
26
  @save_gpfiles = false
27
+ @disk_only_regex = nil
27
28
  end
28
29
 
29
30
  def parse_args(argv)
@@ -72,6 +73,9 @@ EOS
72
73
  @save_gpfiles = true
73
74
  end
74
75
 
76
+ @parser.on('--disk-only REGEX', "Select disk devices that matches REGEX") do |regex|
77
+ @disk_only_regex = Regexp.compile(regex)
78
+ end
75
79
 
76
80
  @parser.parse!(argv)
77
81
 
@@ -143,6 +147,12 @@ EOS
143
147
  start_time ||= time
144
148
  devices ||= diskinfo["devices"]
145
149
 
150
+ if @disk_only_regex
151
+ devices = devices.select do |devname|
152
+ devname =~ @disk_only_regex
153
+ end
154
+ end
155
+
146
156
  datafile.puts([time - start_time,
147
157
  devices.map{|device|
148
158
  [diskinfo[device]["riops"], diskinfo[device]["wiops"],
@@ -2,6 +2,7 @@ require 'optparse'
2
2
  require 'tempfile'
3
3
  require 'tmpdir'
4
4
  require 'json'
5
+ require 'etc'
5
6
 
6
7
  module PerfMonger
7
8
  module Command
@@ -16,15 +17,24 @@ class RecordCommand < BaseCommand
16
17
  def run(argv)
17
18
  @argv, @option = PerfMonger::Command::RecordOption.parse(argv)
18
19
 
19
- exec_record_cmd()
20
+ if @option.kill
21
+ session_file = File.expand_path(sprintf("perfmonger-%s-session.pid", Etc.getlogin),
22
+ Dir.tmpdir)
23
+ Process.kill(:INT, File.read(session_file).to_i)
24
+ else
25
+ exec_record_cmd()
26
+ end
20
27
  end
21
28
 
22
29
  private
23
30
  def exec_record_cmd()
24
31
  cmd = @option.make_command
25
32
 
26
- $stdout.puts("[recording to #{@option.logfile}]")
27
-
33
+ if @option.background
34
+ Process.daemon(true)
35
+ else
36
+ $stdout.puts("[recording to #{@option.logfile}]")
37
+ end
28
38
  Process.exec(*cmd)
29
39
  end
30
40
  end
@@ -9,6 +9,8 @@ class RecordOption
9
9
  attr_reader :report_cpu
10
10
  attr_reader :no_disk
11
11
  attr_reader :logfile
12
+ attr_reader :background
13
+ attr_reader :kill
12
14
 
13
15
  attr_reader :parser
14
16
  attr_accessor :record_bin
@@ -83,6 +85,8 @@ class RecordOption
83
85
  @no_disk = false
84
86
  @devices = []
85
87
  @logfile = "perfmonger.pgr"
88
+ @background = false
89
+ @kill = false
86
90
 
87
91
  @parser = OptionParser.new
88
92
 
@@ -120,6 +124,14 @@ class RecordOption
120
124
  @logfile = file
121
125
  end
122
126
 
127
+ @parser.on('--background', 'Run in background') do
128
+ @background = true
129
+ end
130
+
131
+ @parser.on('--kill', 'Stop currently running perfmonger-reocrd') do
132
+ @kill = true
133
+ end
134
+
123
135
  @parser.on('-v', '--verbose') do
124
136
  @verbose = true
125
137
  end
@@ -18,6 +18,7 @@ EOS
18
18
 
19
19
  @json = false
20
20
  @pager = nil
21
+ @disk_only_regex = nil
21
22
 
22
23
  @parser.on('--json', "Output summary in JSON") do
23
24
  @json = true
@@ -37,6 +38,10 @@ EOS
37
38
  @pager = pager
38
39
  end
39
40
  end
41
+
42
+ @parser.on('--disk-only REGEX', "Select disk devices that matches REGEX") do |regex|
43
+ @disk_only_regex = regex
44
+ end
40
45
  end
41
46
 
42
47
  def parse_args(argv)
@@ -74,6 +79,11 @@ EOS
74
79
  cmd << "-json"
75
80
  end
76
81
 
82
+ if @disk_only_regex
83
+ cmd << "-disk-only"
84
+ cmd << @disk_only_regex
85
+ end
86
+
77
87
  cmd << "-title"
78
88
  cmd << summary_title
79
89
 
@@ -1,3 +1,3 @@
1
1
  module PerfMonger
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
data/perfmonger.gemspec CHANGED
@@ -22,7 +22,9 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "guard-rspec"
23
23
  s.add_development_dependency "aruba"
24
24
 
25
- s.files = `git ls-files`.split("\n")
25
+ s.files = `git ls-files`.split("\n").select do |file|
26
+ ! (file =~ /^dbg\//)
27
+ end
26
28
  s.files += Dir.glob("lib/exec/*")
27
29
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
30
  s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
@@ -34,7 +36,7 @@ Gem::Specification.new do |s|
34
36
  Thank you for installing perfmonger.
35
37
  Try to start performance monitoring with:
36
38
 
37
- perfmonger record
39
+ perfmonger live
38
40
 
39
41
  Enjoy.
40
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfmonger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuto HAYAMIZU
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-02 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -195,7 +195,7 @@ post_install_message: |2+
195
195
  Thank you for installing perfmonger.
196
196
  Try to start performance monitoring with:
197
197
 
198
- perfmonger record
198
+ perfmonger live
199
199
 
200
200
  Enjoy.
201
201
 
@@ -216,19 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  version: '0'
217
217
  requirements: []
218
218
  rubyforge_project:
219
- rubygems_version: 2.4.5.1
219
+ rubygems_version: 2.5.1
220
220
  signing_key:
221
221
  specification_version: 4
222
222
  summary: yet anothor performance measurement/monitoring tool
223
- test_files:
224
- - spec/data/busy100.pgr
225
- - spec/fingerprint_spec.rb
226
- - spec/live_spec.rb
227
- - spec/perfmonger_spec.rb
228
- - spec/play_spec.rb
229
- - spec/plot_spec.rb
230
- - spec/record_spec.rb
231
- - spec/spec_helper.rb
232
- - spec/stat_spec.rb
233
- - spec/summary_spec.rb
234
- - spec/support/aruba.rb
223
+ test_files: []