httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1591622 [24/33] - in /httpd/mod_spdy/trunk: ./ base/ base/base.xcodeproj/ base/metrics/ build/ build/all.xcodeproj/ build/build_util.xcodeproj/ build/install.xcodeproj/ build/internal/ build/linux/ build/mac/ build/util/ build/win/ install...
Date Thu, 01 May 2014 11:43:45 GMT
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics.h Thu May  1 11:43:36 2014
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jhoch@google.com (Jason Hoch)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_H_
+
+#include <cstddef>
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class AbstractSharedMem;
+class GoogleUrl;
+class MessageHandler;
+class SharedDynamicStringMap;
+class Writer;
+
+// This class handles persistent memory of referer statistics by wrapping a
+// SharedDynamicStringMap by encoding references into string map entries and
+// parsing these entries later.
+//   GetEntryStringForUrl and GetDivLocationEntryStringForUrl can be overridden
+// to tweak encodings of strings (say, if you want information to be hashed).
+class SharedMemRefererStatistics {
+ public:
+  // All inputs are passed to SharedDynamicStringMap constructor.
+  SharedMemRefererStatistics(size_t number_of_strings,
+                             size_t average_string_length,
+                             AbstractSharedMem* shm_runtime,
+                             const GoogleString& filename_prefix,
+                             const GoogleString& filename_suffix);
+  virtual ~SharedMemRefererStatistics();
+
+  // All inputs are passed to SharedDynamicStringMap method.
+  bool InitSegment(bool parent, MessageHandler* message_handler);
+
+  // The first LogPageRequest method is to be used when there is no referer,
+  // and logs only the page visit.  The second logs the visit and the referral.
+  //   LogResourceRequest logs only the referral.
+  void LogPageRequestWithoutReferer(const GoogleUrl& target);
+  void LogPageRequestWithReferer(const GoogleUrl& target,
+                                 const GoogleUrl& referer);
+  void LogResourceRequestWithReferer(const GoogleUrl& target,
+                                     const GoogleUrl& referer);
+
+  int GetNumberOfVisitsForUrl(const GoogleUrl& url);
+  int GetNumberOfReferencesFromUrlToPage(const GoogleUrl& from_url,
+                                         const GoogleUrl& to_url);
+  int GetNumberOfReferencesFromUrlToDivLocation(
+      const GoogleUrl& from_url, const GoogleString& div_location);
+  int GetNumberOfReferencesFromUrlToResource(const GoogleUrl& from_url,
+                                             const GoogleUrl& resource_url);
+
+  // Extracts the div_location from the Url.
+  static GoogleString GetDivLocationFromUrl(const GoogleUrl& url);
+
+  // Calls shared_dynamic_string_map_->GlobalCleanup(message_handler)
+  void GlobalCleanup(MessageHandler* message_handler);
+
+  // Various methods of dumping information, that go from hard to understand and
+  // cheap to well-organized and expensive:
+  //   1. DumpFast writes SharedDynamicStringMap information in the order it
+  //      was provided without parsing or decoding string entries (see Dump
+  //      method of SharedDynamicStringMap)
+  //
+  //        Example:
+  //          http://www.example.com/news: 1
+  //          http://www.example.com/news/us: 1
+  //          http://www.example.com/news/us phttp://www.example.com/news: 1
+  //          1.1.2.0 dhttp://www.example.com/news: 1
+  //          http://img.ex.com/news_us.jpg rhttp://www.example.com/news/us: 1
+  //
+  //   2. DumpSimple writes SharedDynamicStringMap information in the order it
+  //      was provided, but it parses and decodes string entries into a more
+  //      readable format (see DecodeEntry method below)
+  //
+  //        Example:
+  //          http://www.example.com/news refered div location 1.1.2.0 : 1
+  //          http://www.example.com/news/us refered resource
+  //              http://img.ex.com/news_us.jpg : 1
+  //          http://www.example.com/news visits: 1
+  //          http://www.example.com/news/us visits: 1
+  //          http://www.example.com/news refered page
+  //              http://www.example.com/news/us : 1
+  //
+  //   3. DumpOrganized writes SharedDynamicStringMap information, grouped by
+  //      referers, in alphabetical order.
+  //
+  //        Example:
+  //          http://www.example.com/news visits: 1
+  //          http://www.example.com/news refered:
+  //            div location 1.1.2.0 : 1
+  //            page http://ww.example.com/news/us : 1
+  //          http://www.example.com/news/us visits: 1
+  //          http://www.example.com/news/us refered:
+  //            resource http://img.ex.com/news_us.jpg
+  //
+  void DumpFast(Writer* writer, MessageHandler* message_handler);
+  void DumpSimple(Writer* writer, MessageHandler* message_handler);
+  void DumpOrganized(Writer* writer, MessageHandler* message_handler);
+
+  // The name for special div location query parameter
+  static const char kParamName[];
+
+ protected:
+  // Given a Url string, produces the corresponding ready-for-storage string
+  virtual GoogleString GetEntryStringForUrlString(
+      const StringPiece& url_string) const;
+  // Given a div location (string), produces the corresponding ready-for-storage
+  // string
+  virtual GoogleString GetEntryStringForDivLocation(
+      const StringPiece& div_location) const;
+
+ private:
+  // Given a Url, extracts the div location and returns ready-for-storage string
+  GoogleString GetUrlEntryStringForUrl(const GoogleUrl& url) const;
+  // Given a Url, extracts the div location and returns ready-for-storage string
+  GoogleString GetDivLocationEntryStringForUrl(const GoogleUrl& url) const;
+  // These methods combine ready-for-storage strings into the final entry string
+  static GoogleString GetEntryForReferedPage(const StringPiece& target,
+                                             const StringPiece& referer);
+  static GoogleString GetEntryForReferedDivLocation(const StringPiece& target,
+                                                    const StringPiece& referer);
+  static GoogleString GetEntryForVisitedPage(const StringPiece& target);
+  static GoogleString GetEntryForReferedResource(const StringPiece& target,
+                                                 const StringPiece& referer);
+  // These methods extract the information encoded in the methods above and
+  // return a more readable string.  The second method is a convenience method
+  // for when we don't care about target, referer
+  GoogleString DecodeEntry(const StringPiece& entry,
+                           GoogleString* target,
+                           GoogleString* referer) const;
+  GoogleString DecodeEntry(const StringPiece& entry) const;
+
+  // These helper methods cut down on duplicate code in the public Log methods
+  void LogPageRequest(const GoogleUrl& target, GoogleString* target_string);
+
+  scoped_ptr<SharedDynamicStringMap> shared_dynamic_string_map_;
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics_test_base.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics_test_base.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics_test_base.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics_test_base.h Thu May  1 11:43:36 2014
@@ -0,0 +1,183 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: jhoch@google.com (Jason Hoch)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_TEST_BASE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_TEST_BASE_H_
+
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/abstract_shared_mem.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/google_url.h"
+#include "net/instaweb/util/public/gtest.h"
+#include "net/instaweb/util/public/mock_message_handler.h"
+#include "net/instaweb/util/public/shared_mem_test_base.h"
+#include "net/instaweb/util/public/string.h"
+
+namespace net_instaweb {
+
+class SharedMemRefererStatistics;
+
+
+struct TestUrl {
+ public:
+  TestUrl(GoogleString input_string,
+          GoogleString input_div_location,
+          GoogleString query_params = GoogleString(""))
+      : url(FormUrl(input_string, input_div_location, query_params)),
+        div_location(input_div_location),
+        string(input_string) {
+  }
+  const GoogleUrl url;
+  const GoogleString div_location;
+  const GoogleString string;
+
+ private:
+  // Helper function that puts together Url string from constructor inputs
+  static GoogleString FormUrl(GoogleString input_string,
+                              GoogleString input_div_location,
+                              GoogleString query_params);
+};
+
+class SharedMemRefererStatisticsTestBase : public testing::Test {
+ protected:
+  typedef void (SharedMemRefererStatisticsTestBase::*TestMethod)();
+
+  static const int kNumberOfStrings;
+  static const int kStringSize;
+  static const char kPrefix[];
+  static const char kSuffix[];
+
+  explicit SharedMemRefererStatisticsTestBase(SharedMemTestEnv* test_env);
+
+  bool CreateChild(TestMethod method);
+
+  // Tests that query parameter value corresponding to query parameter name
+  // SharedMemRefererStatistics::kParamName is extracted properly
+  void TestGetDivLocationFromUrl();
+  // Tests simple functionality of referer statistics, namely logging a
+  // sequence of two page requests
+  void TestSimple();
+  // Tests logging of a resource request
+  void TestResource();
+  // Tests that Urls that are identical but for query parameters are still
+  // logged as the same Url
+  void TestIgnoreQueryParams();
+  // Tests that different Urls with the same div location and vice versa are
+  // logged properly
+  void TestDivLocation();
+  // Tests DumpFast method
+  void TestDumpFast();
+  // Tests DumpSimple method
+  void TestDumpSimple();
+  // Tests DumpOrganized method
+  void TestDumpOrganized();
+  // Tests accumulation of statistics simultaneously across multiple processes
+  void TestMultiProcess();
+
+  void AddChild();
+
+  // Convience method that, for sequence url1, url2, url3, ..., performs
+  //   LogPageRequest(url1, "");
+  //   LogPageRequest(url2, url1.uncheckedSpec());
+  //   LogPageRequest(url3, url2.uncheckedSpec());
+  //        ... and so on
+  //
+  // If GoogleUrl("") is passed as a sequence entry, for example if the sequence
+  // is url1, url2, "", url3, url4, ..., the following behavior occurs:
+  //   LogPageRequest(url1, "");
+  //   LogPageRequest(url2, url1.uncheckedSpec());
+  //   LogPageRequest(url3, "");
+  //   LogPageRequest(url4, url3.uncheckedSpec());
+  //       ... and so on
+  void LogSequenceOfPageRequests(SharedMemRefererStatistics* stats,
+                                 const GoogleUrl* urls[],
+                                 int number_of_urls);
+
+  // Create child process
+  SharedMemRefererStatistics* ChildInit();
+  // Create parent process
+  SharedMemRefererStatistics* ParentInit();
+
+  scoped_ptr<SharedMemTestEnv> test_env_;
+  scoped_ptr<AbstractSharedMem> shmem_runtime_;
+  MockMessageHandler message_handler_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(SharedMemRefererStatisticsTestBase);
+};
+
+template<typename ConcreteTestEnv>
+class SharedMemRefererStatisticsTestTemplate
+    : public SharedMemRefererStatisticsTestBase {
+ public:
+  SharedMemRefererStatisticsTestTemplate()
+      : SharedMemRefererStatisticsTestBase(new ConcreteTestEnv) {
+  }
+};
+
+TYPED_TEST_CASE_P(SharedMemRefererStatisticsTestTemplate);
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate,
+             TestGetDivLocationFromUrl) {
+  SharedMemRefererStatisticsTestBase::TestGetDivLocationFromUrl();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestSimple) {
+  SharedMemRefererStatisticsTestBase::TestSimple();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestResource) {
+  SharedMemRefererStatisticsTestBase::TestResource();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestIgnoreQueryParams) {
+  SharedMemRefererStatisticsTestBase::TestIgnoreQueryParams();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDivLocation) {
+  SharedMemRefererStatisticsTestBase::TestDivLocation();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDumpFast) {
+  SharedMemRefererStatisticsTestBase::TestDumpFast();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDumpSimple) {
+  SharedMemRefererStatisticsTestBase::TestDumpSimple();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDumpOrganized) {
+  SharedMemRefererStatisticsTestBase::TestDumpOrganized();
+}
+
+TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestMultiProcess) {
+  SharedMemRefererStatisticsTestBase::TestMultiProcess();
+}
+
+REGISTER_TYPED_TEST_CASE_P(SharedMemRefererStatisticsTestTemplate,
+                           TestGetDivLocationFromUrl,
+                           TestSimple,
+                           TestResource,
+                           TestIgnoreQueryParams,
+                           TestDivLocation,
+                           TestDumpFast,
+                           TestDumpSimple,
+                           TestDumpOrganized,
+                           TestMultiProcess);
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_TEST_BASE_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_referer_statistics_test_base.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics.h Thu May  1 11:43:36 2014
@@ -0,0 +1,201 @@
+// Copyright 2010 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_H_
+
+#include <cstddef>
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/abstract_mutex.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/statistics.h"
+#include "net/instaweb/util/public/statistics_template.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class MessageHandler;
+class AbstractSharedMem;
+class AbstractSharedMemSegment;
+
+// An implementation of Statistics using our shared memory infrastructure.
+// These statistics will be shared amongst all processes and threads
+// spawned by our host.  Note that we will be obtaining a per-variable mutex for
+// every read and write to these variables.  Since this may be expensive,
+// we may need each thread to keep a local cache and infrequently write
+// through to this Statistics object.  TODO(abliss): actually do this.
+//
+// Because we must allocate shared memory segments and mutexes before any child
+// processes and threads are created, all AddVariable calls must be done in
+// the host before it starts forking/threading. Once all variables are added,
+// you must call InitVariables(true), and then InitVariables(false) in every
+// kid.
+//
+// If a variable fails to initialize (due to either its mutex or the shared
+// memory segment not working), it will not increment in that process (and a
+// warning message will be logged).  If the variable fails to initialize in the
+// process that happens to serve a statistics page, then the variable will show
+// up with value -1.
+class SharedMemVariable : public Variable {
+ public:
+  int64 Get64() const;
+  virtual int Get() const;
+  virtual void Set(int newValue);
+  virtual void Add(int delta);
+
+ private:
+  friend class SharedMemTimedVariable;
+  friend class SharedMemStatistics;
+
+  explicit SharedMemVariable(const StringPiece& name);
+
+  void AttachTo(AbstractSharedMemSegment* segment_, size_t offset,
+                MessageHandler* message_handler);
+
+  // Called on initialization failure, to make sure it's clear if we
+  // share some state with parent.
+  void Reset();
+
+  // The name of this variable.
+  const GoogleString name_;
+
+  // Lock protecting us. NULL if for some reason initialization failed.
+  scoped_ptr<AbstractMutex> mutex_;
+
+  // The data...
+  volatile int64* value_ptr_;
+
+  DISALLOW_COPY_AND_ASSIGN(SharedMemVariable);
+};
+
+class SharedMemHistogram : public Histogram {
+ public:
+  virtual ~SharedMemHistogram();
+  virtual void Add(double value);
+  virtual void Clear();
+  virtual int MaxBuckets();
+  // Call the following functions after statistics->Init and before add values.
+  // EnableNegativeBuckets, SetMinValue and SetMaxValue will
+  // cause resetting Histogram.
+  virtual void EnableNegativeBuckets();
+  // Set the minimum value allowed in histogram.
+  virtual void SetMinValue(double value);
+  // Set the upper-bound of value in histogram,
+  // The value range in histogram is [MinValue, MaxValue) or
+  // (-MaxValue, MaxValue) if negative buckets are enabled.
+  virtual void SetMaxValue(double value);
+  // We rely on MaxBuckets to allocate memory segment for histogram. If we want
+  // to call SetMaxBuckets(), we should call it right after AddHistogram().
+  virtual void SetMaxBuckets(int i);
+  // Return the allocation size for this Histogram object except Mutex size.
+  // Shared memory space should include a mutex, HistogramBody and
+  // sizeof(double) * MaxBuckets(). Here we do not know mutex size.
+  size_t AllocationSize() {
+    size_t total = sizeof(HistogramBody) + sizeof(double) * MaxBuckets();
+    return total;
+  }
+
+ protected:
+  virtual AbstractMutex* lock() {
+    return mutex_.get();
+  }
+  virtual double AverageInternal();
+  virtual double PercentileInternal(const double perc);
+  virtual double StandardDeviationInternal();
+  virtual double CountInternal();
+  virtual double MaximumInternal();
+  virtual double MinimumInternal();
+  virtual double BucketStart(int index);
+  virtual double BucketCount(int index);
+
+ private:
+  friend class SharedMemStatistics;
+  SharedMemHistogram();
+  void AttachTo(AbstractSharedMemSegment* segment_, size_t offset,
+                MessageHandler* message_handler);
+  double BucketWidth();
+  int FindBucket(double value);
+  void Init();
+  void Reset();
+  const GoogleString name_;
+  scoped_ptr<AbstractMutex> mutex_;
+  // TODO(fangfei): implement a non-shared-mem histogram.
+  struct HistogramBody {
+    // Enable negative values in histogram, false by default.
+    bool enable_negative_;
+    // Minimum value allowed in Histogram, 0 by default.
+    double min_value_;
+    // Maximum value allowed in Histogram,
+    // numeric_limits<double>::max() by default.
+    double max_value_;
+    // Real minimum value.
+    double min_;
+    // Real maximum value.
+    double max_;
+    double count_;
+    double sum_;
+    double sum_of_squares_;
+    // Histogram buckets data.
+    double values_[1];
+  };
+  // Maximum number of buckets in Histogram.
+  int max_buckets_;
+  HistogramBody *buffer_;
+  DISALLOW_COPY_AND_ASSIGN(SharedMemHistogram);
+};
+
+// NullStatisticsHistogram is for temporary util we have a shared memory
+// histogram implemented.
+class SharedMemStatistics : public StatisticsTemplate<SharedMemVariable,
+    SharedMemHistogram, FakeTimedVariable> {
+ public:
+  SharedMemStatistics(AbstractSharedMem* shm_runtime,
+                      const GoogleString& filename_prefix);
+  virtual ~SharedMemStatistics();
+
+  // This method initializes or attaches to shared memory. You should call this
+  // exactly once in each process/thread, after all calls to AddVariables,
+  // AddHistograms and SetMaxBuckets have been done.
+  // The root process (the one that starts all the other child
+  // threads and processes) must be the first one to make the call, with
+  // parent = true, with all other calling it with = false.
+  void Init(bool parent, MessageHandler* message_handler);
+
+  // This should be called from the root process as it is about to exit, when
+  // no further children are expected to start.
+  void GlobalCleanup(MessageHandler* message_handler);
+
+ protected:
+  virtual SharedMemVariable* NewVariable(const StringPiece& name, int index);
+  virtual SharedMemHistogram* NewHistogram(const StringPiece& name);
+
+ private:
+  GoogleString SegmentName() const;
+
+  // Create mutexes in the segment, with per_var bytes being used,
+  // counting the mutex, for each variable.
+  bool InitMutexes(size_t per_var, MessageHandler* message_handler);
+
+  AbstractSharedMem* shm_runtime_;
+  GoogleString filename_prefix_;
+  scoped_ptr<AbstractSharedMemSegment> segment_;
+  bool frozen_;
+
+  DISALLOW_COPY_AND_ASSIGN(SharedMemStatistics);
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics_test_base.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics_test_base.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics_test_base.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics_test_base.h Thu May  1 11:43:36 2014
@@ -0,0 +1,117 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: morlovich@google.com (Maksim Orlovich)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_TEST_BASE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_TEST_BASE_H_
+
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/abstract_shared_mem.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/gtest.h"
+#include "net/instaweb/util/public/mock_message_handler.h"
+#include "net/instaweb/util/public/shared_mem_statistics.h"
+#include "net/instaweb/util/public/shared_mem_test_base.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+class SharedMemStatisticsTestBase : public testing::Test {
+ protected:
+  typedef void (SharedMemStatisticsTestBase::*TestMethod)();
+
+  explicit SharedMemStatisticsTestBase(SharedMemTestEnv* test_env);
+
+  virtual void SetUp();
+  virtual void TearDown();
+
+  bool CreateChild(TestMethod method);
+
+  void TestCreate();
+  void TestSet();
+  void TestClear();
+  void TestAdd();
+  void TestHistogram();
+  void TestHistogramRender();
+  void TestTimedVariableEmulation();
+
+ private:
+  void TestCreateChild();
+  void TestSetChild();
+  void TestClearChild();
+
+  // Adds 10x +1 to variable 1, and 10x +2 to variable 2.
+  void TestAddChild();
+  bool AddVars(SharedMemStatistics* stats);
+  bool AddHistograms(SharedMemStatistics* stats);
+  // Helper function for TestHistogramRender().
+  // Check if string html contains the pattern.
+  bool Contains(const StringPiece& html, const StringPiece& pattern);
+
+  SharedMemStatistics* ChildInit();
+  void ParentInit();
+
+  scoped_ptr<SharedMemTestEnv> test_env_;
+  scoped_ptr<AbstractSharedMem> shmem_runtime_;
+  scoped_ptr<SharedMemStatistics> stats_;  // (the parent process version)
+  MockMessageHandler handler_;
+
+  DISALLOW_COPY_AND_ASSIGN(SharedMemStatisticsTestBase);
+};
+
+template<typename ConcreteTestEnv>
+class SharedMemStatisticsTestTemplate : public SharedMemStatisticsTestBase {
+ public:
+  SharedMemStatisticsTestTemplate()
+      : SharedMemStatisticsTestBase(new ConcreteTestEnv) {
+  }
+};
+
+TYPED_TEST_CASE_P(SharedMemStatisticsTestTemplate);
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestCreate) {
+  SharedMemStatisticsTestBase::TestCreate();
+}
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestSet) {
+  SharedMemStatisticsTestBase::TestSet();
+}
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestClear) {
+  SharedMemStatisticsTestBase::TestClear();
+}
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestAdd) {
+  SharedMemStatisticsTestBase::TestAdd();
+}
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestHistogram) {
+  SharedMemStatisticsTestBase::TestHistogram();
+}
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestHistogramRender) {
+  SharedMemStatisticsTestBase::TestHistogramRender();
+}
+
+TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestTimedVariableEmulation) {
+  SharedMemStatisticsTestBase::TestTimedVariableEmulation();
+}
+
+REGISTER_TYPED_TEST_CASE_P(SharedMemStatisticsTestTemplate, TestCreate,
+                           TestSet, TestClear, TestAdd, TestHistogram,
+                           TestHistogramRender, TestTimedVariableEmulation);
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_TEST_BASE_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_statistics_test_base.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_test_base.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_test_base.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_test_base.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_test_base.h Thu May  1 11:43:36 2014
@@ -0,0 +1,174 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: morlovich@google.com (Maksim Orlovich)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_TEST_BASE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_TEST_BASE_H_
+
+#include <cstddef>
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/abstract_shared_mem.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/gtest.h"
+#include "net/instaweb/util/public/mock_message_handler.h"
+
+namespace net_instaweb {
+
+class Function;
+
+class SharedMemTestEnv {
+ public:
+  virtual ~SharedMemTestEnv();
+  SharedMemTestEnv() {}
+
+  virtual AbstractSharedMem* CreateSharedMemRuntime() = 0;
+
+  // This method must be overridden to start a new process and invoke the
+  // callback object in it. The runtime is responsible for deleting the callback
+  // object properly.
+  //
+  // Returns whether started OK or not.
+  virtual bool CreateChild(Function* callback) = 0;
+
+  // This method must be overridden to block until all processes/threads started
+  // by CreateChild exit.
+  virtual void WaitForChildren() = 0;
+
+  // Runtime-specific short sleep.
+  virtual void ShortSleep() = 0;
+
+  // Called in a child to denote it exiting with failure
+  virtual void ChildFailed() = 0;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(SharedMemTestEnv);
+};
+
+class SharedMemTestBase : public testing::Test {
+ protected:
+  typedef void (SharedMemTestBase::*TestMethod)();
+
+  explicit SharedMemTestBase(SharedMemTestEnv* test_env);
+
+  bool CreateChild(TestMethod method);
+
+  // Basic read/write operation test.
+  void TestReadWrite(bool reattach);
+
+  // Test with large data; also test initialization.
+  void TestLarge();
+
+  // Make sure that 2 segments don't interfere.
+  void TestDistinct();
+
+  // Make sure destruction destroys things properly...
+  void TestDestroy();
+
+  // Make sure that re-creating a segment without a Destroy is safe and
+  // produces a distinct segment.
+  void TestCreateTwice();
+
+  // Make sure between two kids see the SHM as well.
+  void TestTwoKids();
+
+  // Test for mutex operation.
+  void TestMutex();
+
+ private:
+  static const int kLarge = 0x1000 - 4;  // not a multiple of any page size, but
+                                         // a multiple of 4.
+  static const int kNumIncrements = 0xFFFFF;
+
+  volatile int* IntPtr(AbstractSharedMemSegment* seg, int offset) {
+    return reinterpret_cast<volatile int*>(&seg->Base()[offset]);
+  }
+
+  AbstractSharedMemSegment* CreateDefault();
+  AbstractSharedMemSegment* AttachDefault();
+  void DestroyDefault();
+
+  // writes '1' to the default segment's base location.
+  void WriteSeg1Child();
+
+  // writes '2' to the other segment's base location.
+  void WriteSeg2Child();
+
+  void TestReadWriteChild();
+  void TestLargeChild();
+  void TwoKidsChild1();
+  void TwoKidsChild2();
+
+  bool IncrementStorm(AbstractSharedMemSegment* seg, size_t mutex_size);
+
+  void MutexChild();
+
+  scoped_ptr<SharedMemTestEnv> test_env_;
+  scoped_ptr<AbstractSharedMem> shmem_runtime_;
+  MockMessageHandler handler_;
+
+  DISALLOW_COPY_AND_ASSIGN(SharedMemTestBase);
+};
+
+// Passes in the SharedMemTestEnv to SharedMemTestBase via a template param
+// to help glue us to the test framework
+template<typename ConcreteTestEnv>
+class SharedMemTestTemplate : public SharedMemTestBase {
+ public:
+  SharedMemTestTemplate() : SharedMemTestBase(new ConcreteTestEnv) {
+  }
+};
+
+TYPED_TEST_CASE_P(SharedMemTestTemplate);
+
+TYPED_TEST_P(SharedMemTestTemplate, TestRewrite) {
+  SharedMemTestBase::TestReadWrite(false);
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestRewriteReattach) {
+  SharedMemTestBase::TestReadWrite(true);
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestLarge) {
+  SharedMemTestBase::TestLarge();
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestDistinct) {
+  SharedMemTestBase::TestDistinct();
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestDestroy) {
+  SharedMemTestBase::TestDestroy();
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestCreateTwice) {
+  SharedMemTestBase::TestCreateTwice();
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestTwoKids) {
+  SharedMemTestBase::TestTwoKids();
+}
+
+TYPED_TEST_P(SharedMemTestTemplate, TestMutex) {
+  SharedMemTestBase::TestMutex();
+}
+
+REGISTER_TYPED_TEST_CASE_P(SharedMemTestTemplate, TestRewrite,
+                           TestRewriteReattach, TestLarge, TestDistinct,
+                           TestDestroy, TestCreateTwice, TestTwoKids,
+                           TestMutex);
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_TEST_BASE_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_mem_test_base.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_string.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/shared_string.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/shared_string.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/shared_string.h Thu May  1 11:43:36 2014
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+//
+// Implements a ref-counted string class, with full sharing.  This
+// class does *not* implement copy-on-write semantics, however, it
+// does support a unique() method for determining, prior to writing,
+// whether other references exist.  Thus it is feasible to implement
+// copy-on-write as a layer over this class.
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_STRING_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SHARED_STRING_H_
+
+#include "net/instaweb/util/public/ref_counted_ptr.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+// Reference-counted string.  This class just adds the StringPiece constructor.
+class SharedString : public RefCountedObj<GoogleString> {
+ public:
+  SharedString() {}
+  explicit SharedString(const StringPiece& str) {
+    str.CopyToString(get());
+  }
+
+  // When constructing with a GoogleString, we going through the StringPiece
+  // ctor above causes an extra copy compared with string implementations that
+  // use copy-on-write.
+  explicit SharedString(const GoogleString& str)
+      : RefCountedObj<GoogleString>(str) {}
+
+  // Given the two constructors above, it is ambiguous which one gets
+  // called when passed a string-literal, so making an explicit const char*
+  // constructor eliminates the ambiguity.  This is likely beneficial mostly
+  // for tests.
+  explicit SharedString(const char* str) {
+    *get() = str;
+  }
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SHARED_STRING_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/shared_string.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/simple_stats.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/simple_stats.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/simple_stats.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/simple_stats.h Thu May  1 11:43:36 2014
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SIMPLE_STATS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SIMPLE_STATS_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/statistics.h"
+#include "net/instaweb/util/public/statistics_template.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class SimpleStatsVariable : public Variable {
+ public:
+  SimpleStatsVariable() : value_(0) {}
+  virtual ~SimpleStatsVariable();
+  virtual int Get() const { return value_; }
+  virtual int64 Get64() const { return value_; }
+  virtual void Set(int value) { value_ = value; }
+
+ private:
+  int value_;
+
+  DISALLOW_COPY_AND_ASSIGN(SimpleStatsVariable);
+};
+
+// Simple name/value pair statistics implementation.
+class SimpleStats : public StatisticsTemplate<SimpleStatsVariable,
+                                              NullHistogram,
+                                              FakeTimedVariable> {
+ public:
+  static const int kNotFound;
+
+  SimpleStats() { }
+  virtual ~SimpleStats();
+
+ protected:
+  virtual SimpleStatsVariable* NewVariable(const StringPiece& name, int index);
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(SimpleStats);
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SIMPLE_STATS_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/simple_stats.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/slow_worker.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/slow_worker.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/slow_worker.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/slow_worker.h Thu May  1 11:43:36 2014
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: morlovich@google.com (Maksim Orlovich)
+//
+// This contains SlowWorker, which runs (expensive) tasks in a background thread
+// when it's not otherwise busy.
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_SLOW_WORKER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_SLOW_WORKER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/worker.h"
+
+namespace net_instaweb {
+
+class Function;
+class ThreadSystem;
+
+// See file comment.
+class SlowWorker : public Worker {
+ public:
+  // Initializes the worker. You still need to call ->Start to actually
+  // start the thread, however. (Note: start can return false on failure).
+  explicit SlowWorker(ThreadSystem* runtime);
+
+  // This waits for the running task to terminate.
+  virtual ~SlowWorker();
+
+  // If this SlowWorker's thread is currently idle, it will run the closure.
+  // Otherwise, the closure will simply be deleted.
+  //
+  // Takes ownership of the closure.
+  void RunIfNotBusy(Function* closure);
+
+ private:
+  virtual bool IsPermitted(Function* closure);
+
+  DISALLOW_COPY_AND_ASSIGN(SlowWorker);
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_SLOW_WORKER_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/slow_worker.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/statistics.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/statistics.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/statistics.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/statistics.h Thu May  1 11:43:36 2014
@@ -0,0 +1,293 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_H_
+
+#include <map>
+#include "base/logging.h"
+#include "net/instaweb/util/public/abstract_mutex.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/null_mutex.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class MessageHandler;
+class Writer;
+
+class Variable {
+ public:
+  virtual ~Variable();
+  // TODO(sligocki): int -> int64
+  virtual int Get() const = 0;
+  virtual void Set(int delta) = 0;
+  virtual int64 Get64() const = 0;
+
+  virtual void Add(int delta) { Set(delta + Get()); }
+  void Clear() { Set(0); }
+};
+
+class Histogram {
+ public:
+  virtual ~Histogram();
+  // Record a value in its bucket.
+  virtual void Add(double value) = 0;
+  // Throw away all data.
+  virtual void Clear() = 0;
+  // True if the histogram is empty.
+  virtual bool Empty() {
+   ScopedMutex hold(lock());
+   return CountInternal() == 0;
+  }
+  // Write Histogram Data to the writer.
+  // Default implementation does not include histogram graph, but only raw
+  // histogram data table. It looks like:
+  // ________________________________________
+  // |  TITLE String                         |
+  // |  Avg: StdDev: Median: 90%: 95%: 99%   |
+  // |  Raw Histogram Data:                  |
+  // |  [0,1] 1 25% 25%  |||||               |
+  // |  [2,3] 1 25% 50%  |||||               |
+  // |  [4,5] 2 50% 100% ||||||||||          |
+  // |_______________________________________|
+  virtual void Render(const StringPiece& title, Writer* writer,
+                      MessageHandler* handler);
+  // Maxmum number of buckets. This number can be used to allocate a buffer for
+  // Histogram.
+  virtual int MaxBuckets() = 0;
+  // Allow histogram have negative values.
+  virtual void EnableNegativeBuckets() = 0;
+  // Set the minimum value allowed in histogram.
+  virtual void SetMinValue(double value) = 0;
+  // Set the value upper-bound of a histogram,
+  // the value range in histogram is [MinValue, MaxValue) or
+  // (-MaxValue, MaxValue) if enabled negative buckets.
+  virtual void SetMaxValue(double value) = 0;
+  // Set the maximum number of buckets.
+  virtual void SetMaxBuckets(int i) = 0;
+  // Record a value in its bucket.
+  virtual double Average() {
+    ScopedMutex hold(lock());
+    return AverageInternal();
+  }
+  // Return estimated value that is greater than perc% of all data.
+  // e.g. Percentile(20) returns the value which is greater than
+  // 20% of data.
+  virtual double Percentile(const double perc) {
+    ScopedMutex hold(lock());
+    return PercentileInternal(perc);
+  }
+  virtual double StandardDeviation() {
+    ScopedMutex hold(lock());
+    return StandardDeviationInternal();
+  }
+  virtual double Count() {
+    ScopedMutex hold(lock());
+    return CountInternal();
+  }
+  virtual double Maximum() {
+    ScopedMutex hold(lock());
+    return MaximumInternal();
+  }
+  virtual double Minimum() {
+    ScopedMutex hold(lock());
+    return MinimumInternal();
+  }
+  virtual double Median() {
+    return Percentile(50);
+  }
+
+ protected:
+  virtual AbstractMutex* lock() = 0;
+  virtual double AverageInternal() = 0;
+  virtual double PercentileInternal(const double perc) = 0;
+  virtual double StandardDeviationInternal() = 0;
+  virtual double CountInternal() = 0;
+  virtual double MaximumInternal() = 0;
+  virtual double MinimumInternal() = 0;
+  // Lower bound of a bucket. If index == MaxBuckets() + 1, returns the
+  // upper bound of the histogram. DCHECK if index is in the range of
+  // [0, MaxBuckets()+1].
+  virtual double BucketStart(int index) = 0;
+  // Upper bound of a bucket.
+  virtual double BucketLimit(int index) {
+    return BucketStart(index + 1);
+  }
+  // Value of a bucket.
+  virtual double BucketCount(int index) = 0;
+  // Helper function of Render(), write entries of histogram raw data table.
+  // Each entry includes bucket range, bucket count, percentage,
+  // cumulative percentage, bar. It looks like:
+  // [0,1] 1 5%  5%  ||||
+  // [2,3] 2 10% 15% ||||||||
+  virtual void WriteRawHistogramData(Writer* writer, MessageHandler* handler);
+};
+
+class NullHistogram : public Histogram {
+ public:
+  NullHistogram() {}
+  virtual ~NullHistogram();
+  virtual void Add(const double value) { }
+  virtual void Clear() { }
+  virtual bool Empty() { return true; }
+  virtual int MaxBuckets() { return 0; }
+  virtual void EnableNegativeBuckets() { }
+  virtual void SetMinValue(double value) { }
+  virtual void SetMaxValue(double value) { }
+  virtual void SetMaxBuckets(int i) { }
+
+ protected:
+  virtual AbstractMutex* lock() { return &mutex_; }
+  virtual double AverageInternal() { return 0.0; }
+  virtual double PercentileInternal(const double perc) { return 0.0; }
+  virtual double StandardDeviationInternal() { return 0.0; }
+  virtual double CountInternal() { return 0.0; }
+  virtual double MaximumInternal() { return 0.0; }
+  virtual double MinimumInternal() { return 0.0; }
+  virtual double BucketStart(int index) { return 0.0; }
+  virtual double BucketCount(int index) { return 0.0; }
+
+ private:
+  NullMutex mutex_;
+
+  DISALLOW_COPY_AND_ASSIGN(NullHistogram);
+};
+
+// TimedVariable is a statistic class returns the amount added in the
+// last interval, which could be last 10 seconds, last minute
+// last one hour and total.
+class TimedVariable {
+ public:
+  // The intervals for which we keep stats.
+  enum Levels { TENSEC, MINUTE, HOUR, START };
+  virtual ~TimedVariable();
+  // Update the stat value. delta is in milliseconds.
+  virtual void IncBy(int64 delta) = 0;
+  // Get the amount added over the last time interval
+  // specified by "level".
+  virtual int64 Get(int level) = 0;
+  // Throw away all data.
+  virtual void Clear() = 0;
+};
+
+// TimedVariable implementation that only updates a basic Variable.
+class FakeTimedVariable : public TimedVariable {
+ public:
+  explicit FakeTimedVariable(Variable* var) : var_(var) {
+  }
+  virtual ~FakeTimedVariable();
+  // Update the stat value. delta is in milliseconds.
+  virtual void IncBy(int64 delta) {
+    var_->Add(delta);
+  }
+  // Get the amount added over the last time interval
+  // specified by "level".
+  virtual int64 Get(int level) {
+    // This is a default implementation. Variable can only return the
+    // total value. This should be override in subclass if we want the
+    // values for different levels.
+    if (level == START) {
+      return var_->Get64();
+    }
+    return 0;
+  }
+  // Throw away all data.
+  virtual void Clear() {
+    return var_->Clear();
+  }
+
+ protected:
+  Variable* var_;
+};
+
+// Helps build a statistics that can be exported as a CSV file.
+class Statistics {
+ public:
+  virtual ~Statistics();
+
+  // Add a new variable, or returns an existing one of that name.
+  // The Variable* is owned by the Statistics class -- it should
+  // not be deleted by the caller.
+  virtual Variable* AddVariable(const StringPiece& name) = 0;
+
+  // Find a variable from a name, returning NULL if not found.
+  virtual Variable* FindVariable(const StringPiece& name) const = 0;
+
+  // Find a variable from a name, aborting if not found.
+  virtual Variable* GetVariable(const StringPiece& name) const {
+    Variable* var = FindVariable(name);
+    CHECK(var != NULL) << "Variable not found: " << name;
+    return var;
+  }
+
+  // Add a new histogram, or returns an existing one of that name.
+  // The Histogram* is owned by the Statistics class -- it should not
+  // be deleted by the caller.
+  virtual Histogram* AddHistogram(const StringPiece& name) = 0;
+  // Find a histogram from a name, returning NULL if not found.
+  virtual Histogram* FindHistogram(const StringPiece& name) const = 0;
+  // Find a histogram from a name, aborting if not found.
+  virtual Histogram* GetHistogram(const StringPiece& name) const {
+    Histogram* hist = FindHistogram(name);
+    CHECK(hist != NULL) << "Histogram not found: " << name;
+    return hist;
+  }
+
+  // Add a new TimedVariable, or returns an existing one of that name.
+  // The TimedVariable* is owned by the Statistics class -- it should
+  // not be deleted by the caller. Each stat belongs to a group, such as
+  // "Statistics", "Disk Statistics", etc.
+  virtual TimedVariable* AddTimedVariable(
+      const StringPiece& name, const StringPiece& group) = 0;
+  // Find a TimedVariable from a name, returning NULL if not found.
+  virtual TimedVariable* FindTimedVariable(
+      const StringPiece& name) const = 0;
+  // Find a TimedVariable from a name, aborting if not found.
+  virtual TimedVariable* GetTimedVariable(
+      const StringPiece& name) const {
+    TimedVariable* stat = FindTimedVariable(name);
+    CHECK(stat != NULL) << "TimedVariable not found: " << name;
+    return stat;
+  }
+  // Return the names of all the histograms for render.
+  virtual StringVector& HistogramNames() = 0;
+  // Return the map of groupnames and names of all timedvariables for render.
+  virtual std::map<GoogleString, StringVector>& TimedVariableMap() = 0;
+  // Dump the variable-values to a writer.
+  virtual void Dump(Writer* writer, MessageHandler* handler) = 0;
+  // Export statistics to a writer. Statistics in a group are exported in one
+  // table.
+  virtual void RenderTimedVariables(Writer* writer,
+                                    MessageHandler* handler);
+  // Write all the histograms in this Statistic object to a writer.
+  virtual void RenderHistograms(Writer* writer, MessageHandler* handler);
+  // Set all variables to 0.
+  // Throw away all data in histograms and stats.
+  virtual void Clear() = 0;
+
+ protected:
+  virtual Histogram* NewHistogram(const StringPiece& name);
+  virtual TimedVariable* NewTimedVariable(const StringPiece& name, int index);
+  virtual Variable* NewVariable(const StringPiece& name, int index) = 0;
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/statistics.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_template.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_template.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_template.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_template.h Thu May  1 11:43:36 2014
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_TEMPLATE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_TEMPLATE_H_
+
+#include <map>
+#include <vector>
+#include <utility>                      // for pair
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/statistics.h"
+#include "net/instaweb/util/public/stl_util.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+#include "net/instaweb/util/public/writer.h"
+
+namespace net_instaweb {
+class MessageHandler;
+
+// This class makes it easier to define new Statistics implementations
+// by providing a templatized implementation of variable registration and
+// management.
+template<class Var, class Hist, class TimedVar> class StatisticsTemplate
+    : public Statistics {
+ public:
+  StatisticsTemplate() {}
+  virtual ~StatisticsTemplate() {
+    STLDeleteContainerPointers(variables_.begin(), variables_.end());
+    STLDeleteContainerPointers(histograms_.begin(), histograms_.end());
+    STLDeleteContainerPointers(timed_vars_.begin(), timed_vars_.end());
+  }
+
+  // Add a new variable, or returns an existing one of that name.
+  // The Variable* is owned by the Statistics class -- it should
+  // not be deleted by the caller.
+  virtual Variable* AddVariable(const StringPiece& name) {
+    return AddVariableInternal(name);
+  }
+
+  // Find a variable from a name, returning NULL if not found.
+  virtual Variable* FindVariable(const StringPiece& name) const {
+    return FindVariableInternal(name);
+  }
+
+  // Add a new histogram, or returns an exisiting one of that name.
+  // The Histogram* is owned by the Statistics class -- it should
+  // not be deleted by the caller.
+  virtual Histogram* AddHistogram(const StringPiece& name) {
+    return AddHistogramInternal(name);
+  }
+
+  // Find a histogram from a name, returning NULL if not found.
+  virtual Histogram* FindHistogram(const StringPiece& name) const {
+    return FindHistogramInternal(name);
+  }
+
+  virtual TimedVariable* AddTimedVariable(
+      const StringPiece& name, const StringPiece& group) {
+    return AddTimedVariableInternal(name, group);
+  }
+
+  virtual TimedVariable* FindTimedVariable(
+      const StringPiece& name) const {
+    return FindTimedVariableInternal(name);
+  }
+
+  virtual StringVector& HistogramNames() {
+    return histogram_names_;
+  }
+
+  virtual std::map<GoogleString, StringVector>& TimedVariableMap() {
+    return timed_var_group_map_;
+  }
+
+  virtual void Dump(Writer* writer, MessageHandler* message_handler) {
+    for (int i = 0, n = variables_.size(); i < n; ++i) {
+      Var* var = variables_[i];
+      writer->Write(variable_names_[i], message_handler);
+      writer->Write(": ", message_handler);
+      writer->Write(Integer64ToString(var->Get64()), message_handler);
+      writer->Write("\n", message_handler);
+    }
+  }
+
+  virtual void Clear() {
+    for (int i = 0, n = variables_.size(); i < n; ++i) {
+      Var* var = variables_[i];
+      var->Clear();
+    }
+    for (int i = 0, n = histograms_.size(); i < n; ++i) {
+      Histogram* hist = histograms_[i];
+      hist->Clear();
+    }
+    for (int i = 0, n = timed_vars_.size(); i < n; ++i) {
+      TimedVariable* timedvar = timed_vars_[i];
+      timedvar->Clear();
+    }
+  }
+
+
+ protected:
+  // Adds a variable, returning as the template class Var type, rather
+  // than its base class, as AddVariable does.
+  virtual Var* AddVariableInternal(const StringPiece& name) {
+    Var* var = FindVariableInternal(name);
+    if (var == NULL) {
+      var = NewVariable(name, variables_.size());
+      variables_.push_back(var);
+      variable_names_.push_back(name.as_string());
+      variable_map_[GoogleString(name.data(), name.size())] = var;
+    }
+    return var;
+  }
+
+  // Finds a variable, returning as the template class Var type, rather
+  // than its base class, as FindVariable does.
+  virtual Var* FindVariableInternal(const StringPiece& name) const {
+    typename VarMap::const_iterator p = variable_map_.find(name.as_string());
+    Var* var = NULL;
+    if (p != variable_map_.end()) {
+      var = p->second;
+    }
+    return var;
+  }
+
+  virtual Var* NewVariable(const StringPiece& name, int index) = 0;
+
+  virtual Histogram* AddHistogramInternal(const StringPiece& name) {
+    Histogram* hist = FindHistogramInternal(name);
+    if (hist == NULL) {
+      hist = NewHistogram(name);
+      histograms_.push_back(hist);
+      histogram_names_.push_back(name.as_string());
+      histogram_map_[GoogleString(name.data(), name.size())] = hist;
+    }
+    return hist;
+  }
+  // Finds a histogram, returning as the template class Hist type, rather
+  // than its base class, as FindHistogram does.
+  virtual Histogram* FindHistogramInternal(const StringPiece& name) const {
+    typename HistMap::const_iterator p = histogram_map_.find(name.as_string());
+    Histogram* hist = NULL;
+    if (p != histogram_map_.end()) {
+      hist = p->second;
+    }
+    return hist;
+  }
+
+  virtual TimedVariable* AddTimedVariableInternal(const StringPiece& name,
+                                                  const StringPiece& group) {
+    TimedVariable* timedvar = FindTimedVariableInternal(name);
+    if (timedvar == NULL) {
+      timedvar = NewTimedVariable(name, timed_vars_.size());
+      timed_vars_.push_back(timedvar);
+      timed_var_map_[GoogleString(name.data(), name.size())] = timedvar;
+      timed_var_group_map_[GoogleString(group.data(), group.size())].push_back(
+          name.as_string());
+    }
+    return timedvar;
+  }
+
+  virtual TimedVariable* FindTimedVariableInternal(
+      const StringPiece& name) const {
+    typename TimedVarMap::const_iterator p =
+        timed_var_map_.find(name.as_string());
+    TimedVariable* timedvar = NULL;
+    if (p != timed_var_map_.end()) {
+      timedvar = p->second;
+    }
+    return timedvar;
+  }
+
+  typedef std::vector<Var*> VarVector;
+  typedef std::map<GoogleString, Var*> VarMap;
+  typedef std::vector<Histogram*> HistVector;
+  typedef std::map<GoogleString, Histogram*> HistMap;
+
+  typedef std::vector<TimedVariable*> TimedVarVector;
+  typedef std::map<GoogleString, TimedVariable*> TimedVarMap;
+  VarVector variables_;
+  VarMap variable_map_;
+  HistVector histograms_;
+  HistMap histogram_map_;
+  TimedVarVector timed_vars_;
+  TimedVarMap timed_var_map_;
+  // map between group and names of stats.
+  std::map<GoogleString, StringVector> timed_var_group_map_;
+  StringVector variable_names_;
+  StringVector histogram_names_;
+
+  DISALLOW_COPY_AND_ASSIGN(StatisticsTemplate);
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_TEMPLATE_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_template.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_work_bound.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_work_bound.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_work_bound.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_work_bound.h Thu May  1 11:43:36 2014
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmaessen@google.com (Jan Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_WORK_BOUND_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_WORK_BOUND_H_
+
+#include "net/instaweb/util/public/work_bound.h"
+
+namespace net_instaweb {
+
+class Variable;
+
+// A WorkBound implementation in terms of statistics.  This is a bit of a hack
+// that gets things implemented quickly (especially given the complexity of
+// multiprocess shared-memory infrastructure, which we only want to roll once).
+// Note in particular that we handle a NULL variable gracefully by imposing no
+// bound at all.
+class StatisticsWorkBound : public WorkBound {
+ public:
+  // Note that ownership of variable remains with the creating Statistics
+  // object.  If the bound is 0, the bound is actually infinite.
+  StatisticsWorkBound(Variable* variable, int bound);
+  virtual ~StatisticsWorkBound();
+
+  virtual bool TryToWork();
+  virtual void WorkComplete();
+ private:
+  Variable* variable_;
+  int bound_;
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STATISTICS_WORK_BOUND_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/statistics_work_bound.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/stdio_file_system.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/stdio_file_system.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/stdio_file_system.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/stdio_file_system.h Thu May  1 11:43:36 2014
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STDIO_FILE_SYSTEM_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STDIO_FILE_SYSTEM_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/file_system.h"
+#include "net/instaweb/util/public/string_util.h"
+
+struct stat;
+
+namespace net_instaweb {
+
+class MessageHandler;
+
+class StdioFileSystem : public FileSystem {
+ public:
+  StdioFileSystem() {}
+  virtual ~StdioFileSystem();
+
+  virtual int MaxPathLength(const StringPiece& base) const;
+
+  virtual InputFile* OpenInputFile(const char* filename,
+                                   MessageHandler* message_handler);
+  virtual OutputFile* OpenOutputFileHelper(const char* filename,
+                                           MessageHandler* message_handler);
+  virtual OutputFile* OpenTempFileHelper(const StringPiece& prefix_name,
+                                         MessageHandler* message_handle);
+
+  virtual bool ListContents(const StringPiece& dir, StringVector* files,
+                            MessageHandler* handler);
+  virtual bool MakeDir(const char* directory_path, MessageHandler* handler);
+  virtual bool RemoveFile(const char* filename, MessageHandler* handler);
+  virtual bool RenameFileHelper(const char* old_file, const char* new_file,
+                                MessageHandler* handler);
+
+  virtual bool Atime(const StringPiece& path, int64* timestamp_sec,
+                     MessageHandler* handler);
+  virtual bool Mtime(const StringPiece& path, int64* timestamp_sec,
+                     MessageHandler* handler);
+  virtual bool Size(const StringPiece& path, int64* size,
+                    MessageHandler* handler);
+  virtual BoolOrError Exists(const char* path, MessageHandler* handler);
+  virtual BoolOrError IsDir(const char* path, MessageHandler* handler);
+
+  virtual BoolOrError TryLock(const StringPiece& lock_name,
+                              MessageHandler* handler);
+  virtual bool Unlock(const StringPiece& lock_name, MessageHandler* handler);
+
+  InputFile* Stdin();
+  OutputFile* Stdout();
+  OutputFile* Stderr();
+
+ private:
+  // Used by *time and Size methods to get file info.
+  bool Stat(const StringPiece& path, struct stat* statbuf,
+            MessageHandler* handler);
+
+  DISALLOW_COPY_AND_ASSIGN(StdioFileSystem);
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STDIO_FILE_SYSTEM_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/stdio_file_system.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/stl_util.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/stl_util.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/stl_util.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/stl_util.h Thu May  1 11:43:36 2014
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STL_UTIL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STL_UTIL_H_
+
+#include "base/stl_util-inl.h"
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STL_UTIL_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/stl_util.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/string.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/string.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/string.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/string.h Thu May  1 11:43:36 2014
@@ -0,0 +1,12 @@
+// Copyright 2010 and onwards Google Inc.
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STRING_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STRING_H_
+
+#include <string.h>
+#include <string>
+
+typedef std::string GoogleString;
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STRING_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/string.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/string_hash.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/string_hash.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/string_hash.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/string_hash.h Thu May  1 11:43:36 2014
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STRING_HASH_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STRING_HASH_H_
+
+#include <cstddef>
+
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+// A hash function for strings that can be used both in a case-sensitive
+// and case-insensitive way
+template<class CharTransform, typename IntType>
+inline IntType HashString(const char* s, size_t len) {
+  // This implemention is based on code in
+  // third_party/chromium/src/base/hash_tables.h.
+  IntType result = 0;
+  for (size_t i = 0; i < len; ++i, ++s) {
+    result = (result * 131) + CharTransform::Normalize(*s);
+  }
+  return result;
+}
+
+// Combine two hash values in a reasonable way.  Here to avoid
+// excessive mysticism in the remainder of the code.
+inline size_t JoinHash(size_t a, size_t b) {
+  return (a + 56) * 137 + b * 151;  // Uses different prime multipliers.
+}
+
+// A helper for case-sensitive hashing
+struct CasePreserve {
+  // We want to use unsigned characters for the return value of Normalize
+  // here and in CaseFold::Normalize.  This is so that we get the same
+  // hash-value arithmetic regardless of whether the c++ compiler treats
+  // chars as signed or unsigned by default.  We want to get the same
+  // hash-values independent of machine so that we get consistent domain
+  // sharding and therefore better caching behavior in a multi-server setup
+  // that contains heterogeneous machines.
+  static unsigned char Normalize(char c) {
+    return c;
+  }
+
+  static bool Compare(const StringPiece& a, const StringPiece& b) {
+    return a < b;
+  }
+};
+
+// A helper for case-insensitive hashing, which folds to lowercase
+struct CaseFold {
+  static unsigned char Normalize(char c) {
+    return LowerChar(c);
+  }
+
+  static bool Compare(const StringPiece& a, const StringPiece& b) {
+    return StringCaseCompare(a, b) < 0;
+  }
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STRING_HASH_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/string_hash.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/string_multi_map.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/string_multi_map.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/string_multi_map.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/string_multi_map.h Thu May  1 11:43:36 2014
@@ -0,0 +1,150 @@
+// Copyright 2010 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STRING_MULTI_MAP_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STRING_MULTI_MAP_H_
+
+#include <map>
+#include <utility>
+#include <vector>
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+// Implements an ordered string map, providing case-sensitive and case
+// insensitive versions.  The order of insertion is retained and
+// names/value pairs can be accessed by index or looked up by name.
+template<class StringCompare> class StringMultiMap {
+ public:
+  StringMultiMap() { }
+  ~StringMultiMap() {
+    Clear();
+  }
+
+  void Clear() {
+    for (int i = 0, n = vector_.size(); i < n; ++i) {
+      delete vector_[i].second;
+    }
+    map_.clear();
+    vector_.clear();
+  }
+
+  // Returns the number of distinct names
+  int num_names() const { return map_.size(); }
+
+  // Returns the number of distinct values, which can be larger than num_names
+  // if Add is called twice with the same name.
+  int num_values() const { return vector_.size(); }
+
+  // Find the value(s) associated with a variable.  Note that you may
+  // specify a variable multiple times by calling Add multiple times
+  // with the same variable, and each of these values will be returned
+  // in the vector.
+  bool Lookup(const StringPiece& name, ConstStringStarVector* values) const {
+    typename Map::const_iterator p = map_.find(name.as_string());
+    bool ret = false;
+    if (p != map_.end()) {
+      ret = true;
+      *values = p->second;
+    }
+    return ret;
+  }
+
+  // Remove all variables by name.  Returns true if anything was removed.
+  bool RemoveAll(const StringPiece& var_name) {
+    GoogleString var_string(var_name.data(), var_name.size());
+    typename Map::iterator p = map_.find(var_string);
+    bool removed = (p != map_.end());
+    if (removed) {
+      StringPairVector temp_vector;  // Temp variable for new vector.
+      temp_vector.reserve(vector_.size());
+      for (int i = 0; i < num_values(); ++i) {
+        if (!StringCaseEqual(name(i),  var_string)) {
+          temp_vector.push_back(vector_[i]);
+        } else {
+          removed = true;
+          delete vector_[i].second;
+        }
+      }
+
+      vector_.swap(temp_vector);
+
+      // Note: we have to erase from the map second, because map owns the name.
+      map_.erase(p);
+    }
+    return removed;
+  }
+
+  const char* name(int index) const { return vector_[index].first; }
+
+  // Note that the value can be NULL.
+  const GoogleString* value(int index) const { return vector_[index].second; }
+
+  // Add a new variable.  The value can be null.
+  void Add(const StringPiece& var_name, const StringPiece& value) {
+    ConstStringStarVector dummy_values;
+    GoogleString name_buf(var_name.data(), var_name.size());
+    std::pair<typename Map::iterator, bool> iter_inserted = map_.insert(
+        typename Map::value_type(name_buf, dummy_values));
+    typename Map::iterator iter = iter_inserted.first;
+    ConstStringStarVector& values = iter->second;
+    GoogleString* value_copy = NULL;
+    if (value.data() != NULL) {
+      value_copy = new GoogleString(value.as_string());
+    }
+    values.push_back(value_copy);
+    vector_.push_back(StringPair(iter->first.c_str(), value_copy));
+  }
+
+ private:
+  // We are keeping two structures, conceptually map<String,vector<String>> and
+  // vector<pair<String,String>>, so we can do associative lookups and
+  // also order-preserving iteration and easy indexed access.
+  //
+  // To avoid duplicating the strings, we will have the map own the
+  // Names (keys) in a GoogleString, and the string-pair-vector own the
+  // value as an explicitly newed char*.  The risk of using a GoogleString
+  // to hold the value is that the pointers will not survive a resize.
+  typedef std::pair<const char*, GoogleString*> StringPair;  // owns the value
+  typedef std::map<GoogleString, ConstStringStarVector, StringCompare> Map;
+  typedef std::vector<StringPair> StringPairVector;
+
+  Map map_;
+  StringPairVector vector_;
+
+  DISALLOW_COPY_AND_ASSIGN(StringMultiMap);
+};
+
+class StringMultiMapInsensitive
+    : public StringMultiMap<StringCompareInsensitive> {
+ public:
+  StringMultiMapInsensitive() { }
+ private:
+  DISALLOW_COPY_AND_ASSIGN(StringMultiMapInsensitive);
+};
+
+class StringMultiMapSensitive : public StringMultiMap<StringCompareSensitive> {
+ public:
+  StringMultiMapSensitive() { }
+ private:
+  DISALLOW_COPY_AND_ASSIGN(StringMultiMapSensitive);
+};
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STRING_MULTI_MAP_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/string_multi_map.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpd/mod_spdy/trunk/net/instaweb/util/public/string_util.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/string_util.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/string_util.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/string_util.h Thu May  1 11:43:36 2014
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_STRING_UTIL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_STRING_UTIL_H_
+
+
+#include <map>
+#include <set>
+#include <vector>
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string.h"
+
+#include <cstdlib>
+#include <string>
+#include "base/string_number_conversions.h"
+#include "base/string_piece.h"
+#include "base/string_util.h"
+
+using base::StringAppendF;
+using base::StringAppendV;
+using base::SStringPrintf;
+using base::StringPiece;
+
+// Quick macro to get the size of a static char[] without trailing '\0'.
+// Note: Cannot be used for char*, std::string, etc.
+#define STATIC_STRLEN(static_string) (arraysize(static_string) - 1)
+
+namespace net_instaweb {
+
+struct StringCompareInsensitive;
+
+typedef std::map<GoogleString, GoogleString> StringStringMap;
+typedef std::set<GoogleString> StringSet;
+typedef std::set<GoogleString, StringCompareInsensitive> StringSetInsensitive;
+typedef std::vector<GoogleString> StringVector;
+typedef std::vector<StringPiece> StringPieceVector;
+typedef std::vector<const GoogleString*> ConstStringStarVector;
+typedef std::vector<GoogleString*> StringStarVector;
+typedef std::vector<const char*> CharStarVector;
+
+inline GoogleString IntegerToString(int i) {
+  return base::IntToString(i);
+}
+
+inline GoogleString Integer64ToString(int64 i) {
+  return base::Int64ToString(i);
+}
+
+inline bool StringToInt(const char* in, int* out) {
+  // TODO(bmcquade): Use char*-based StringToInt once we sync the
+  // Chromium repository.
+  std::string str(in);
+  return base::StringToInt(str, out);
+}
+
+inline bool StringToInt64(const char* in, int64* out) {
+  // TODO(bmcquade): Use char*-based StringToInt64 once we sync the
+  // Chromium repository.
+  std::string str(in);
+  return base::StringToInt64(str, out);
+}
+
+inline bool StringToInt(const GoogleString& in, int* out) {
+  return base::StringToInt(in, out);
+}
+
+inline bool StringToInt64(const GoogleString& in, int64* out) {
+  return base::StringToInt64(in, out);
+}
+
+class EmptyString {
+ public:
+  static const StringPiece kEmptyString;
+};
+
+// TODO(jmarantz): use overloading instead of default args and get
+// rid of this statically constructed global object.
+GoogleString StrCat(const StringPiece& a, const StringPiece& b,
+                    const StringPiece& c = EmptyString::kEmptyString,
+                    const StringPiece& d = EmptyString::kEmptyString,
+                    const StringPiece& e = EmptyString::kEmptyString,
+                    const StringPiece& f = EmptyString::kEmptyString,
+                    const StringPiece& g = EmptyString::kEmptyString,
+                    const StringPiece& h = EmptyString::kEmptyString);
+
+void StrAppend(GoogleString* target,
+               const StringPiece& a,
+               const StringPiece& b = EmptyString::kEmptyString,
+               const StringPiece& c = EmptyString::kEmptyString,
+               const StringPiece& d = EmptyString::kEmptyString,
+               const StringPiece& e = EmptyString::kEmptyString,
+               const StringPiece& f = EmptyString::kEmptyString,
+               const StringPiece& g = EmptyString::kEmptyString,
+               const StringPiece& h = EmptyString::kEmptyString);
+
+void SplitStringPieceToVector(const StringPiece& sp, const char* separator,
+                              StringPieceVector* components,
+                              bool omit_empty_strings);
+
+void BackslashEscape(const StringPiece& src,
+                     const StringPiece& to_escape,
+                     GoogleString* dest);
+
+// TODO(jmarantz): Eliminate these definitions of HasPrefixString,
+// UpperString, and LowerString, and re-add dependency on protobufs
+// which also provide definitions for these.
+
+bool HasPrefixString(const StringPiece& str, const StringPiece& prefix);
+
+void UpperString(GoogleString* str);
+
+void LowerString(GoogleString* str);
+
+inline bool OnlyWhitespace(const GoogleString& str) {
+  return ContainsOnlyWhitespaceASCII(str);
+}
+
+int GlobalReplaceSubstring(const StringPiece& substring,
+                           const StringPiece& replacement,
+                           GoogleString* s);
+
+
+// See also: ./src/third_party/css_parser/src/strings/ascii_ctype.h
+// We probably don't want our core string header file to have a
+// dependecy on the Google CSS parser, so for now we'll write this here:
+
+// upper-case a single character and return it.
+// toupper() changes based on locale.  We don't want this!
+inline char UpperChar(char c) {
+  if ((c >= 'a') && (c <= 'z')) {
+    c += 'A' - 'a';
+  }
+  return c;
+}
+
+// lower-case a single character and return it.
+// tolower() changes based on locale.  We don't want this!
+inline char LowerChar(char c) {
+  if ((c >= 'A') && (c <= 'Z')) {
+    c += 'a' - 'A';
+  }
+  return c;
+}
+
+inline char* strdup(const char* str) {
+  return base::strdup(str);
+}
+
+// Case-insensitive string comparison that is locale-independent.
+int StringCaseCompare(const StringPiece& s1, const StringPiece& s2);
+
+inline void TrimWhitespace(const StringPiece& in, GoogleString* output) {
+  static const char whitespace[] = " \r\n\t";
+  TrimString(GoogleString(in.data(), in.size()), whitespace, output);
+}
+
+void TrimWhitespace(StringPiece* str);
+
+// Trims only whitespace at the beginning of the string.
+void TrimLeadingWhitespace(StringPiece* str);
+
+// Accumulates a decimal value from 'c' into *value.
+// Returns false and leaves *value unchanged if c is not a decimal digit.
+bool AccumulateDecimalValue(char c, int* value);
+
+// Accumulates a hex value from 'c' into *value
+// Returns false and leaves *value unchanged if c is not a hex digit.
+bool AccumulateHexValue(char c, int* value);
+
+// Return true iff the two strings are equal, ignoring case.
+bool StringCaseEqual(const StringPiece& s1, const StringPiece& s2);
+// Return true iff str starts with prefix, ignoring case.
+bool StringCaseStartsWith(const StringPiece& str, const StringPiece& prefix);
+// Return true iff str ends with suffix, ignoring case.
+bool StringCaseEndsWith(const StringPiece& str, const StringPiece& suffix);
+
+struct CharStarCompareInsensitive {
+  bool operator()(const char* s1, const char* s2) const {
+    return (StringCaseCompare(s1, s2) < 0);
+  };
+};
+
+struct CharStarCompareSensitive {
+  bool operator()(const char* s1, const char* s2) const {
+    return (strcmp(s1, s2) < 0);
+  }
+};
+
+struct StringCompareSensitive {
+  bool operator()(const GoogleString& s1, const GoogleString& s2) const {
+    return (strcmp(s1.c_str(), s2.c_str()) < 0);
+  };
+};
+
+struct StringCompareInsensitive {
+  bool operator()(const GoogleString& s1, const GoogleString& s2) const {
+    return (StringCaseCompare(s1, s2) < 0);
+  };
+};
+
+// Does a path end in slash?
+inline bool EndsInSlash(const StringPiece& path) {
+  return path.ends_with("/");
+}
+
+// Make sure directory's path ends in '/'.
+inline void EnsureEndsInSlash(GoogleString* dir) {
+  if (!EndsInSlash(*dir)) {
+    dir->append("/");
+  }
+}
+
+// Given a string such as:  a b "c d" e 'f g'
+// Parse it into a vector:  ["a", "b", "c d", "e", "f g"]
+void ParseShellLikeString(const StringPiece& input,
+                          std::vector<GoogleString>* output);
+
+// Counts the number of times that substring appears in text
+// Note: for a substring that can overlap itself, it counts not necessarily
+// disjoint occurrences of the substring.
+// For example: "aaa" appears in "aaaaa" 3 times, not once
+int CountSubstring(const StringPiece& text, const StringPiece& substring);
+
+// Returns true if the string contains a character that is not legal
+// in an http header.
+bool HasIllicitTokenCharacter(const StringPiece& str);
+
+}  // namespace net_instaweb
+
+#endif  // NET_INSTAWEB_UTIL_PUBLIC_STRING_UTIL_H_

Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/string_util.h
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message