Please review pull request #490: Ticket/2.7.x/12310 remove process name listener opened by (pcarlisle)
Description:
This was causing a performance regression in 2.7.10. Removing it for now, to
be added back later when the issue is fixed.
- Opened: Mon Feb 13 18:24:16 UTC 2012
- Based on: puppetlabs:2.7.x (7c300f268a58a6def2c03dc9d7d9acdfa4c322ba)
- Requested merge: pcarlisle:ticket/2.7.x/12310-remove-process_name-listener (25bbecf90ed8a69661052159ff27d9bc07dc8e19)
Diff follows:
diff --git a/lib/puppet/util/instrumentation/listeners/process_name.rb b/lib/puppet/util/instrumentation/listeners/process_name.rb
deleted file mode 100644
index 40bb44d..0000000
--- a/lib/puppet/util/instrumentation/listeners/process_name.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-require 'monitor'
-
-# Unlike the other instrumentation plugins, this one doesn't give back
-# data. Instead it changes the process name of the currently running process
-# with the last labels and data.
-Puppet::Util::Instrumentation.new_listener(:process_name) do
- include Sync_m
-
- # start scrolling when process name is longer than
- SCROLL_LENGTH = 50
-
- attr_accessor :active, :reason
-
- def notify(label, event, data)
- start(label) if event == :start
- stop if event == :stop
- end
-
- def start(activity)
- push_activity(Thread.current, activity)
- end
-
- def stop()
- pop_activity(Thread.current)
- end
-
- def subscribed
- synchronize do
- @oldname = $0
- @scroller ||= Thread.new do
- loop do
- scroll
- sleep 1
- end
- end
- end
- end
-
- def unsubscribed
- synchronize do
- $0 = @oldname if @oldname
- Thread.kill(@scroller)
- @scroller = nil
- end
- end
-
- def setproctitle
- $0 = "#{base}: " + rotate(process_name,@x)
- end
-
- def push_activity(thread, activity)
- synchronize do
- @reason ||= {}
- @reason[thread] ||= []
- @reason[thread].push(activity)
- setproctitle
- end
- end
-
- def pop_activity(thread)
- synchronize do
- @reason[thread].pop
- if @reason[thread].empty?
- @reason.delete(thread)
- end
- setproctitle
- end
- end
-
- def process_name
- out = (@reason || {}).inject([]) do |out, reason|
- out << "#{thread_id(reason[0])} #{reason[1].join(',')}"
- end
- out.join(' | ')
- end
-
- # Getting the ruby thread id might not be portable to other ruby
- # interpreters than MRI, because Thread#inspect might not return the same
- # information on a different runtime.
- def thread_id(thread)
- thread.inspect.gsub(/^#<.*:0x([a-f0-9]+) .*>$/, '\1')
- end
-
- def rotate(string, steps)
- steps ||= 0
- if string.length > 0 && steps > 0
- steps = steps % string.length
- return string[steps..-1].concat( " -- #{string[0..(steps-1)]}" )
- end
- string
- end
-
- def base
- basename = case Puppet.run_mode.name
- when :master
- "master"
- when :agent
- "agent"
- else
- "puppet"
- end
- end
-
- def scroll
- @x ||= 1
- return if process_name.length < SCROLL_LENGTH
- synchronize do
- setproctitle
- @x += 1
- end
- end
-end
diff --git a/spec/unit/util/instrumentation/listeners/process_name_spec.rb b/spec/unit/util/instrumentation/listeners/process_name_spec.rb
deleted file mode 100755
index 5212572..0000000
--- a/spec/unit/util/instrumentation/listeners/process_name_spec.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-require 'puppet/util/instrumentation'
-
-Puppet::Util::Instrumentation.init
-process_name = Puppet::Util::Instrumentation.listener(:process_name)
-
-describe process_name do
- before(:each) do
- @process_name = process_name.new
- end
-
- it "should have a notify method" do
- @process_name.should respond_to(:notify)
- end
-
- it "should not have a data method" do
- @process_name.should_not respond_to(:data)
- end
-
- describe "when managing thread activity" do
- before(:each) do
- @process_name.stubs(:setproctitle)
- @process_name.stubs(:base).returns("base")
- end
-
- it "should be able to append activity" do
- thread1 = stub 'thread1'
- @process_name.push_activity(:thread1,"activity1")
- @process_name.push_activity(:thread1,"activity2")
-
- @process_name.reason[:thread1].should == ["activity1", "activity2"]
- end
-
- it "should be able to remove activity" do
- @process_name.push_activity(:thread1,"activity1")
- @process_name.push_activity(:thread1,"activity1")
- @process_name.pop_activity(:thread1)
-
- @process_name.reason[:thread1].should == ["activity1"]
- end
-
- it "should maintain activity thread by thread" do
- @process_name.push_activity(:thread1,"activity1")
- @process_name.push_activity(:thread2,"activity2")
-
- @process_name.reason[:thread1].should == ["activity1"]
- @process_name.reason[:thread2].should == ["activity2"]
- end
-
- it "should set process title" do
- @process_name.expects(:setproctitle)
-
- @process_name.push_activity("thread1","activity1")
- end
- end
-
- describe "when computing the current process name" do
- before(:each) do
- @process_name.stubs(:setproctitle)
- @process_name.stubs(:base).returns("base")
- end
-
- it "should include every running thread activity" do
- thread1 = stub 'thread1', :inspect => "\#<Thread:0xdeadbeef run>", :hash => 1
- thread2 = stub 'thread2', :inspect => "\#<Thread:0x12344321 run>", :hash => 0
-
- @process_name.push_activity(thread1,"Compiling node1.domain.com")
- @process_name.push_activity(thread2,"Compiling node4.domain.com")
- @process_name.push_activity(thread1,"Parsing file site.pp")
- @process_name.push_activity(thread2,"Parsing file node.pp")
-
- @process_name.process_name.should =~ /12344321 Compiling node4.domain.com,Parsing file node.pp/
- @process_name.process_name.should =~ /deadbeef Compiling node1.domain.com,Parsing file site.pp/
- end
- end
-
- describe "when finding base process name" do
- {:master => "master", :agent => "agent", :user => "puppet"}.each do |program,base|
- it "should return #{base} for #{program}" do
- Puppet.run_mode.stubs(:name).returns(program)
- @process_name.base.should == base
- end
- end
- end
-
- describe "when finding a thread id" do
- it "should return the id from the thread inspect string" do
- thread = stub 'thread', :inspect => "\#<Thread:0x1234abdc run>"
- @process_name.thread_id(thread).should == "1234abdc"
- end
- end
-
- describe "when scrolling the instrumentation string" do
- it "should rotate the string of various step" do
- @process_name.rotate("this is a rotation", 10).should == "rotation -- this is a "
- end
-
- it "should not rotate the string for the 0 offset" do
- @process_name.rotate("this is a rotation", 0).should == "this is a rotation"
- end
- end
-
- describe "when setting process name" do
- before(:each) do
- @process_name.stubs(:process_name).returns("12345 activity")
- @process_name.stubs(:base).returns("base")
- @oldname = $0
- end
-
- after(:each) do
- $0 = @oldname
- end
-
- it "should do it if the feature is enabled" do
- @process_name.setproctitle
-
- $0.should == "base: 12345 activity"
- end
- end
-
- describe "when subscribed" do
- before(:each) do
- thread = stub 'thread', :inspect => "\#<Thread:0x1234abdc run>"
- Thread.stubs(:current).returns(thread)
- end
-
- it "should start the scroller" do
- Thread.expects(:new)
- @process_name.subscribed
- end
- end
-
- describe "when unsubscribed" do
- before(:each) do
- @thread = stub 'scroller', :inspect => "\#<Thread:0x1234abdc run>"
- Thread.stubs(:new).returns(@thread)
- Thread.stubs(:kill)
- @oldname = $0
- @process_name.subscribed
- end
-
- after(:each) do
- $0 = @oldname
- end
-
- it "should stop the scroller" do
- Thread.expects(:kill).with(@thread)
- @process_name.unsubscribed
- end
-
- it "should reset the process name" do
- $0 = "let's see what happens"
- @process_name.unsubscribed
- $0.should == @oldname
- end
- end
-
- describe "when setting a probe" do
- before(:each) do
- thread = stub 'thread', :inspect => "\#<Thread:0x1234abdc run>"
- Thread.stubs(:current).returns(thread)
- Thread.stubs(:new)
- @process_name.active = true
- end
-
- it "should push current thread activity and execute the block" do
- @process_name.notify(:instrumentation, :start, {})
- $0.should == "puppet: 1234abdc instrumentation"
- @process_name.notify(:instrumentation, :stop, {})
- end
-
- it "should finally pop the activity" do
- @process_name.notify(:instrumentation, :start, {})
- @process_name.notify(:instrumentation, :stop, {})
- $0.should == "puppet: "
- end
- end
-
- describe "when scrolling" do
- it "should do nothing for shorter process names" do
- @process_name.expects(:setproctitle).never
- @process_name.scroll
- end
-
- it "should call setproctitle" do
- @process_name.stubs(:process_name).returns("x" * 60)
- @process_name.expects(:setproctitle)
- @process_name.scroll
- end
-
- it "should increment rotation offset" do
- name = "x" * 60
- @process_name.stubs(:process_name).returns(name)
- @process_name.expects(:rotate).once.with(name,1).returns("")
- @process_name.expects(:rotate).once.with(name,2).returns("")
- @process_name.scroll
- @process_name.scroll
- end
- end
-end
\ No newline at end of file
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
