perfmonger 0.8.0 → 0.8.1

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: 0b02aaea69043dcf1560fd042e2af5f571c88e06
4
- data.tar.gz: 07081ebc86aa30f921b360cc0c2d82fd958d3c7f
3
+ metadata.gz: 2473ae93c9047e6068b972263656d9565cdc0d01
4
+ data.tar.gz: 834719a3b8b0b1a063b8e278b9743337de831ca0
5
5
  SHA512:
6
- metadata.gz: 3d4c1d36d69a8d010574985ef3ca8e1760c715b9eb079d87cc4eab5de9adf6a05373a01d351e5286e8000f7fe90148e2af7ac3036abc9eab3bc9a0c329bd18d0
7
- data.tar.gz: 98347d85d24cdbd38ee6cf39cf1a6961a957a56da0d4c17700a2a8dfeb93c2e9438c9953f9bcd5233644249c2f659f1f6c4e4ec9c785bc3cb3835051efa04f98
6
+ metadata.gz: c164cd5d9d02768c1d64272340994977d44992d60dcf6e00c080b2dac5f638f2a1ce11d7bc4e00d745c1018e4312e23812c4b2b352cea9c6a87d77d0928c6faf
7
+ data.tar.gz: 3d44cf43be8f8e963f4531e992ff1abd996235c0c0fc9cfe46ae1d3127aa55fed869efcfaf6c8c12fb27ee2877961044d5c3b422f54ab154163e3efaae55307e
data/NEWS CHANGED
@@ -1,6 +1,15 @@
1
1
  ## XXXX-XX-XX: PerfMonger 0.9.0
2
2
  * ...
3
3
 
4
+ ## 2016-11-22: PerfMonger 0.8.1
5
+ * New features
6
+ * [record] subcommand:
7
+ * Add --status to check currently running session
8
+ * Bug fixes
9
+ * [record] subcommand:
10
+ * Open correct lock file for session management
11
+ * Error handling in --kill processing (no session, already dead session PID)
12
+
4
13
  ## 2016-11-22: PerfMonger 0.8.0
5
14
  * New features
6
15
  * [record] subcommand:
data/bin/perfmonger CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  require 'perfmonger'
5
5
 
6
- PerfMonger::CLI::Runner.new.run(ARGV)
6
+ exit(PerfMonger::CLI::Runner.new.run(ARGV))
@@ -132,8 +132,7 @@ func main() {
132
132
  if _, err := os.Stat(lockfile); err != nil {
133
133
  ioutil.WriteFile(lockfile, []byte(""), 0644)
134
134
  }
135
- fd, _ := syscall.Open("lock", syscall.O_RDONLY, 0000)
136
- defer syscall.Close(fd)
135
+ fd, _ := syscall.Open(lockfile, syscall.O_RDONLY, 0000)
137
136
  syscall.Flock(fd, syscall.LOCK_EX)
138
137
 
139
138
  if _, err := os.Stat(session_file); err == nil {
@@ -143,6 +142,7 @@ func main() {
143
142
  goto MakeNewSession
144
143
  }
145
144
 
145
+ // check if PID in session file is valid
146
146
  proc, err := os.FindProcess(pid)
147
147
  err = proc.Signal(syscall.Signal(0))
148
148
 
@@ -156,9 +156,11 @@ MakeNewSession:
156
156
  if err != nil {
157
157
  panic(err)
158
158
  }
159
+ defer os.Remove(session_file)
159
160
 
160
161
  Unlock:
161
162
  syscall.Flock(fd, syscall.LOCK_UN)
163
+ syscall.Close(fd)
162
164
 
163
165
  if session_exists {
164
166
  fmt.Fprintf(os.Stderr, "[ERROR] another perfmonger is already running.\n")
Binary file
@@ -8,6 +8,8 @@ module PerfMonger
8
8
  module Command
9
9
 
10
10
  class RecordCommand < BaseCommand
11
+ LOCKFILE = File.expand_path(".perfmonger.lock", Dir.tmpdir())
12
+
11
13
  register_command 'record', 'Record system performance information'
12
14
 
13
15
  def initialize
@@ -17,13 +19,78 @@ class RecordCommand < BaseCommand
17
19
  def run(argv)
18
20
  @argv, @option = PerfMonger::Command::RecordOption.parse(argv)
19
21
 
22
+ session_file = File.expand_path(sprintf("perfmonger-%s-session.pid", Etc.getlogin),
23
+ Dir.tmpdir)
24
+ begin
25
+ session_pid = File.read(session_file).to_i
26
+ rescue Errno::ENOENT
27
+ # No session file
28
+ session_pid = nil
29
+ end
30
+
20
31
  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()
32
+ unless session_pid
33
+ # There is nothing to be killed
34
+ return true
35
+ end
36
+
37
+ begin
38
+ Process.kill(:INT, session_pid)
39
+ rescue Errno::ESRCH
40
+ # Session file has invalid (already dead) PID
41
+ File.open(LOCKFILE, "w") do |f|
42
+ f.flock(File::LOCK_EX)
43
+ FileUtils.rm(session_file)
44
+ f.flock(File::LOCK_UN)
45
+ end
46
+ end
47
+ return true
26
48
  end
49
+
50
+ if @option.status
51
+ unless session_pid
52
+ puts "[ERROR] No perfmonger-recorder is running."
53
+ return false
54
+ end
55
+
56
+ begin
57
+ # check if session_pid is valid
58
+ gid = Process.getpgid(session_pid)
59
+
60
+ cmdline = File.read("/proc/#{session_pid}/cmdline").split("\0")
61
+ exe = cmdline.shift
62
+ args = cmdline
63
+ start_time = File::Stat.new("/proc/#{session_pid}").mtime
64
+ elapsed_time = Time.now - start_time
65
+
66
+ puts <<EOS
67
+ ==== perfmonger record is running (PID: #{session_pid}) ====
68
+
69
+ * Running executable: #{exe}
70
+ * Arguments: #{args.join(" ")}
71
+ * Started at #{start_time} (running #{elapsed_time.to_i} sec)
72
+
73
+ EOS
74
+ rescue Errno::ESRCH
75
+ puts "[ERROR] No perfmonger-recorder is running."
76
+ end
77
+
78
+ return true
79
+ end
80
+
81
+ # run perfmonger-recorder (normal path)
82
+ begin
83
+ if session_pid && Process.getpgid(session_pid)
84
+ $stderr.puts("[ERROR] another perfmonger is already running.")
85
+ return false
86
+ end
87
+ rescue Errno::ESRCH
88
+ # Actually there is no perfmonger running. go through.
89
+ end
90
+
91
+ exec_record_cmd()
92
+
93
+ true
27
94
  end
28
95
 
29
96
  private
@@ -11,6 +11,7 @@ class RecordOption
11
11
  attr_reader :logfile
12
12
  attr_reader :background
13
13
  attr_reader :kill
14
+ attr_reader :status
14
15
 
15
16
  attr_reader :parser
16
17
  attr_accessor :record_bin
@@ -132,6 +133,10 @@ class RecordOption
132
133
  @kill = true
133
134
  end
134
135
 
136
+ @parser.on('--status', 'Show currently running perfmonger-record status') do
137
+ @status = true
138
+ end
139
+
135
140
  @parser.on('-v', '--verbose') do
136
141
  @verbose = true
137
142
  end
@@ -1,3 +1,3 @@
1
1
  module PerfMonger
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfmonger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuto HAYAMIZU