Coverage for /Syzygy/trace/client/rpc_session.h

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%10100.C++source

Line-by-line coverage:

   1    :  // Copyright 2012 Google Inc.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  //
  15    :  // A utility class to manage the RPC session and the associated memory mappings.
  16    :  
  17    :  #ifndef SYZYGY_TRACE_CLIENT_RPC_SESSION_H_
  18    :  #define SYZYGY_TRACE_CLIENT_RPC_SESSION_H_
  19    :  
  20    :  #include <map>
  21    :  
  22    :  #include "base/logging.h"
  23    :  #include "base/synchronization/lock.h"
  24    :  #include "syzygy/trace/client/client_utils.h"
  25    :  #include "syzygy/trace/protocol/call_trace_defs.h"
  26    :  
  27    :  namespace trace {
  28    :  namespace client {
  29    :  
  30    :  class RpcSession {
  31    :   public:
  32    :    RpcSession();
  33    :    ~RpcSession();
  34    :  
  35    :    // Set the instance identifier for this session.
  36  E :    void set_instance_id(const base::StringPiece16& instance_id) {
  37  E :      DCHECK(!IsTracing());
  38  E :      instance_id_.assign(instance_id.begin(), instance_id.end());
  39  E :    }
  40    :  
  41    :    // Wrapper and helper functions for the RPC and shared memory calls made
  42    :    // by the call-trace client.
  43    :    bool CreateSession(TraceFileSegment* segment);
  44    :    bool AllocateBuffer(TraceFileSegment* segment);
  45    :    bool AllocateBuffer(size_t min_size, TraceFileSegment* segment);
  46    :    bool ExchangeBuffer(TraceFileSegment* segment);
  47    :    bool ReturnBuffer(TraceFileSegment* segment);
  48    :    bool CloseSession();
  49    :    void FreeSharedMemory();
  50    :  
  51    :    inline bool IsEnabled(unsigned long bit_mask) const {
  52    :      return (flags_ & bit_mask) != 0;
  53    :    }
  54    :  
  55  E :    bool IsTracing() const {
  56  E :      return session_handle_ != NULL;
  57  E :    }
  58    :  
  59  E :    bool IsDisabled() const {
  60  E :      return is_disabled_;
  61  E :    }
  62    :  
  63    :    unsigned long flags() const { return flags_; }
  64    :  
  65    :   private:
  66    :    // Map a tracefile segment buffer into local memory.
  67    :    bool MapSegmentBuffer(TraceFileSegment* segment);
  68    :  
  69    :    // The call trace RPC binding.
  70    :    handle_t rpc_binding_;
  71    :  
  72    :    // The handle to the call trace session. Initialization of the session
  73    :    // is protected by a lock. This is a separate lock since we don't seem
  74    :    // to have recursive locks in base.
  75    :    SessionHandle session_handle_;
  76    :  
  77    :    // The set of trace flags returned by the call trace server. These instruct
  78    :    // the client as to which types of events to capture.
  79    :    unsigned long flags_;
  80    :  
  81    :    // We track the set of shared memory handles we've mapped into the
  82    :    // process. This allows us to avoid mapping a handle twice, as well
  83    :    // as letting us know what to clean up on exit. Access to the set
  84    :    // of handles must be serialized with a lock.
  85    :    typedef std::map<HANDLE, uint8*> SharedMemoryHandleMap;
  86    :    base::Lock shared_memory_lock_;
  87    :    SharedMemoryHandleMap shared_memory_handles_;
  88    :  
  89    :    // This becomes true if the client fails to attach to a call trace service.
  90    :    // This is used to allow the application to run even if no call trace
  91    :    // service is available.
  92    :    bool is_disabled_;
  93    :  
  94    :    // The (optional) unique id used to differentiate concurrent instances of the
  95    :    // RPC call-trace logging service.
  96    :    std::wstring instance_id_;
  97    :  };
  98    :  
  99    :  }  // namespace trace::client
 100    :  }  // namespace trace
 101    :  
 102    :  #endif  // SYZYGY_TRACE_CLIENT_RPC_SESSION_H_

Coverage information generated Thu Sep 06 11:30:46 2012.