LCOV - code coverage report
Current view: top level - toolkit/components/telemetry - TelemetryCommon.h (source / functions) Hit Total Coverage
Test: output.info Lines: 4 10 40.0 %
Date: 2017-07-14 16:53:18 Functions: 7 17 41.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef TelemetryCommon_h__
       7             : #define TelemetryCommon_h__
       8             : 
       9             : #include "nsTHashtable.h"
      10             : #include "jsapi.h"
      11             : #include "nsIScriptError.h"
      12             : #include "nsXULAppAPI.h"
      13             : #include "mozilla/TypedEnumBits.h"
      14             : #include "mozilla/TelemetryProcessEnums.h"
      15             : 
      16             : namespace mozilla {
      17             : namespace Telemetry {
      18             : namespace Common {
      19             : 
      20             : enum class RecordedProcessType : uint32_t {
      21             :   Main       = (1 << GeckoProcessType_Default),  // Also known as "parent process"
      22             :   Content    = (1 << GeckoProcessType_Content),
      23             :   Gpu        = (1 << GeckoProcessType_GPU),
      24             :   AllChilds  = 0xFFFFFFFF - 1,  // All the children processes (i.e. content, gpu, ...)
      25             :   All        = 0xFFFFFFFF       // All the processes
      26             : };
      27       10386 : MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(RecordedProcessType);
      28             : 
      29             : template<class EntryType>
      30           0 : class AutoHashtable : public nsTHashtable<EntryType>
      31             : {
      32             : public:
      33             :   explicit AutoHashtable(uint32_t initLength =
      34             :                          PLDHashTable::kDefaultInitialLength);
      35             :   typedef bool (*ReflectEntryFunc)(EntryType *entry, JSContext *cx, JS::Handle<JSObject*> obj);
      36             :   bool ReflectIntoJS(ReflectEntryFunc entryFunc, JSContext *cx, JS::Handle<JSObject*> obj);
      37             : };
      38             : 
      39             : template<class EntryType>
      40        1540 : AutoHashtable<EntryType>::AutoHashtable(uint32_t initLength)
      41        1540 :   : nsTHashtable<EntryType>(initLength)
      42             : {
      43        1540 : }
      44             : 
      45             : /**
      46             :  * Reflect the individual entries of table into JS, usually by defining
      47             :  * some property and value of obj.  entryFunc is called for each entry.
      48             :  */
      49             : template<typename EntryType>
      50             : bool
      51           0 : AutoHashtable<EntryType>::ReflectIntoJS(ReflectEntryFunc entryFunc,
      52             :                                         JSContext *cx, JS::Handle<JSObject*> obj)
      53             : {
      54           0 :   for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
      55           0 :     if (!entryFunc(iter.Get(), cx, obj)) {
      56           0 :       return false;
      57             :     }
      58             :   }
      59           0 :   return true;
      60             : }
      61             : 
      62             : bool IsExpiredVersion(const char* aExpiration);
      63             : bool IsInDataset(uint32_t aDataset, uint32_t aContainingDataset);
      64             : bool CanRecordDataset(uint32_t aDataset, bool aCanRecordBase, bool aCanRecordExtended);
      65             : bool CanRecordInProcess(RecordedProcessType aProcesses, GeckoProcessType aProcess);
      66             : bool CanRecordInProcess(RecordedProcessType aProcesses, ProcessID aProcess);
      67             : 
      68             : /**
      69             :  * Return the number of milliseconds since process start using monotonic
      70             :  * timestamps (unaffected by system clock changes).
      71             :  *
      72             :  * @return NS_OK on success, NS_ERROR_NOT_AVAILABLE if TimeStamp doesn't have the data.
      73             :  */
      74             : nsresult MsSinceProcessStart(double* aResult);
      75             : 
      76             : /**
      77             :  * Dumps a log message to the Browser Console using the provided level.
      78             :  *
      79             :  * @param aLogLevel The level to use when displaying the message in the browser console
      80             :  *        (e.g. nsIScriptError::warningFlag, ...).
      81             :  * @param aMsg The text message to print to the console.
      82             :  */
      83             : void LogToBrowserConsole(uint32_t aLogLevel, const nsAString& aMsg);
      84             : 
      85             : /**
      86             :  * Get the name string for a ProcessID.
      87             :  * This is the name we use for the Telemetry payloads.
      88             :  */
      89             : const char* GetNameForProcessID(ProcessID process);
      90             : 
      91             : /**
      92             :  * Get the GeckoProcessType for a ProcessID.
      93             :  * Telemetry distinguishes between more process types than the GeckoProcessType,
      94             :  * so the mapping is not direct.
      95             :  */
      96             : GeckoProcessType GetGeckoProcessType(ProcessID process);
      97             : 
      98             : } // namespace Common
      99             : } // namespace Telemetry
     100             : } // namespace mozilla
     101             : 
     102             : #endif // TelemetryCommon_h__

Generated by: LCOV version 1.13