OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1723 return; | 1723 return; |
1724 } | 1724 } |
1725 // Otherwise, if the sliding state window computation has not been | 1725 // Otherwise, if the sliding state window computation has not been |
1726 // started we do it now. | 1726 // started we do it now. |
1727 if (sliding_state_window_ == NULL) { | 1727 if (sliding_state_window_ == NULL) { |
1728 sliding_state_window_ = new SlidingStateWindow(Isolate::Current()); | 1728 sliding_state_window_ = new SlidingStateWindow(Isolate::Current()); |
1729 } | 1729 } |
1730 } | 1730 } |
1731 | 1731 |
1732 // Protects the state below. | 1732 // Protects the state below. |
1733 static LazyMutex active_samplers_mutex = LAZY_MUTEX_INITIALIZER; | 1733 static Mutex* active_samplers_mutex = NULL; |
1734 | 1734 |
1735 List<Sampler*>* SamplerRegistry::active_samplers_ = NULL; | 1735 List<Sampler*>* SamplerRegistry::active_samplers_ = NULL; |
1736 | 1736 |
1737 | 1737 |
| 1738 void SamplerRegistry::SetUp() { |
| 1739 if (!active_samplers_mutex) { |
| 1740 active_samplers_mutex = OS::CreateMutex(); |
| 1741 } |
| 1742 } |
| 1743 |
| 1744 |
1738 bool SamplerRegistry::IterateActiveSamplers(VisitSampler func, void* param) { | 1745 bool SamplerRegistry::IterateActiveSamplers(VisitSampler func, void* param) { |
1739 ScopedLock lock(active_samplers_mutex.Pointer()); | 1746 ScopedLock lock(active_samplers_mutex); |
1740 for (int i = 0; | 1747 for (int i = 0; |
1741 ActiveSamplersExist() && i < active_samplers_->length(); | 1748 ActiveSamplersExist() && i < active_samplers_->length(); |
1742 ++i) { | 1749 ++i) { |
1743 func(active_samplers_->at(i), param); | 1750 func(active_samplers_->at(i), param); |
1744 } | 1751 } |
1745 return ActiveSamplersExist(); | 1752 return ActiveSamplersExist(); |
1746 } | 1753 } |
1747 | 1754 |
1748 | 1755 |
1749 static void ComputeCpuProfiling(Sampler* sampler, void* flag_ptr) { | 1756 static void ComputeCpuProfiling(Sampler* sampler, void* flag_ptr) { |
1750 bool* flag = reinterpret_cast<bool*>(flag_ptr); | 1757 bool* flag = reinterpret_cast<bool*>(flag_ptr); |
1751 *flag |= sampler->IsProfiling(); | 1758 *flag |= sampler->IsProfiling(); |
1752 } | 1759 } |
1753 | 1760 |
1754 | 1761 |
1755 SamplerRegistry::State SamplerRegistry::GetState() { | 1762 SamplerRegistry::State SamplerRegistry::GetState() { |
1756 bool flag = false; | 1763 bool flag = false; |
1757 if (!IterateActiveSamplers(&ComputeCpuProfiling, &flag)) { | 1764 if (!IterateActiveSamplers(&ComputeCpuProfiling, &flag)) { |
1758 return HAS_NO_SAMPLERS; | 1765 return HAS_NO_SAMPLERS; |
1759 } | 1766 } |
1760 return flag ? HAS_CPU_PROFILING_SAMPLERS : HAS_SAMPLERS; | 1767 return flag ? HAS_CPU_PROFILING_SAMPLERS : HAS_SAMPLERS; |
1761 } | 1768 } |
1762 | 1769 |
1763 | 1770 |
1764 void SamplerRegistry::AddActiveSampler(Sampler* sampler) { | 1771 void SamplerRegistry::AddActiveSampler(Sampler* sampler) { |
1765 ASSERT(sampler->IsActive()); | 1772 ASSERT(sampler->IsActive()); |
1766 ScopedLock lock(active_samplers_mutex.Pointer()); | 1773 ScopedLock lock(active_samplers_mutex); |
1767 if (active_samplers_ == NULL) { | 1774 if (active_samplers_ == NULL) { |
1768 active_samplers_ = new List<Sampler*>; | 1775 active_samplers_ = new List<Sampler*>; |
1769 } else { | 1776 } else { |
1770 ASSERT(!active_samplers_->Contains(sampler)); | 1777 ASSERT(!active_samplers_->Contains(sampler)); |
1771 } | 1778 } |
1772 active_samplers_->Add(sampler); | 1779 active_samplers_->Add(sampler); |
1773 } | 1780 } |
1774 | 1781 |
1775 | 1782 |
1776 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) { | 1783 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) { |
1777 ASSERT(sampler->IsActive()); | 1784 ASSERT(sampler->IsActive()); |
1778 ScopedLock lock(active_samplers_mutex.Pointer()); | 1785 ScopedLock lock(active_samplers_mutex); |
1779 ASSERT(active_samplers_ != NULL); | 1786 ASSERT(active_samplers_ != NULL); |
1780 bool removed = active_samplers_->RemoveElement(sampler); | 1787 bool removed = active_samplers_->RemoveElement(sampler); |
1781 ASSERT(removed); | 1788 ASSERT(removed); |
1782 USE(removed); | 1789 USE(removed); |
1783 } | 1790 } |
1784 | 1791 |
1785 } } // namespace v8::internal | 1792 } } // namespace v8::internal |
OLD | NEW |