Code Monkey home page Code Monkey logo

bctrackingclass's People

Contributors

bertrand-caron avatar

Watchers

 avatar

bctrackingclass's Issues

Dealing with methods taking arguments

Carl Veazey's Idea

Having a finite, static list of IMP dealing with a given number of arguments :

void myIMP0Args(id self, SEL _cmd);

void myIMP0Args(id self, SEL _cmd)
{
    //NSLog(@"_cmd : %@",NSStringFromSelector(_cmd));
    [BCTrackingClass logCallForMethod:NSStringFromSelector(_cmd)];
    objc_msgSend(self,
                 NSSelectorFromString([NSString stringWithFormat:@"tracked%@",NSStringFromSelector(_cmd)]));
}

void myIMP1Args(id self, SEL _cmd, id object);

void myIMP1Args(id self, SEL _cmd, id object)
{
    //NSLog(@"_cmd : %@",NSStringFromSelector(_cmd));
    [BCTrackingClass logCallForMethod:NSStringFromSelector(_cmd)];
    objc_msgSend(self,
                 NSSelectorFromString([NSString stringWithFormat:@"tracked%@",NSStringFromSelector(_cmd)]),
                 object);
}

and dispatched based on method_getEncoding():

    if ( //0 Args))
        {   class_addMethod(aClass,
                        trackedSelector,
                        (IMP) myMethodIMP, "v@:");
        }
        else if (//1 Args)
        {
            class_addMethod(aClass,
                         trackedSelector,
                         (IMP) myMethodIMP1Arg, "v@:@");
        }
    //...
``

Deal with untracking a method.

Done

Supported natively by the swizzling design : swizzling swizzled methods restores the state of the method (and leaves behind a selector, don't thing it matters too much but could look into it later on).

Switching to an instance-based model

Context

I finally come up with a working version of the code (cf Github repo, or just above). My next problem is : I want my class to be instance based (currently, all my methods are class methods), so that I can assign a property @property NSMutableDictionnary* to instances of the class for call logging.
I'm not sure how to achieve that. Any ideas ?

Problem

Right now, I'm settinp up swizzing by calling [NCTrackingClass setUpTrackingForClass: myClass andMethodArray:anArray]; Since all my methods are class methods, I don't have any memory and have to 'output' everything.

What I would like to do is spawn an instance of a tracker and have it receive the tracking events :

BCTrackingClass* tracker = [[BCTrackingClass alloc] init];
[tracker registerTrackingForClass : myClass andMethodArray:anArray];

Then give an @property NSMutableDictionnary* trackingDict that would be queried by :

[tracker getTrackingDict];

The IMP Problem

In my IMP, I want self to be both my BSTrackerClass instance to be able to send back the message to its owner, and BCTrackingClass to be able to log information in self.

void myMethodIMP(id self, SEL _cmd)
{
    //NSLog(@"_cmd : %@",NSStringFromSelector(_cmd));
    [BCTrackingClass logCallForMethod:NSStringFromSelector(_cmd)];
    objc_msgSend(self,
                 NSSelectorFromString([NSString stringWithFormat:@"tracked%@",NSStringFromSelector(_cmd)]));
}

Would adding an ivar cut it ?

Using class_addIvar(), we could imagine adding a @property BCTrackingClass instance programmatically to classes of objects being tracked, so that we can refer to them in the IMP.

Solution

Using a Singleton Pattern :Singleton Pattern on Wikipedia

Actual logging of the calls

Context

Now that we are actually able to catch calls to every functions we want to track, what should we do with it ?

Idea

Logging them in a NSMutableDictionary
=>

Changing representation of methods in trackerDict

Problem

Different class with same methods will have their calls logged together.

Solution

  • Embedding the class name in the call key ?
    @"doA": ->@"TrackedClass doA:"
  • Changing :
    -(void)logCallForMethod:(NSString*)aSelectorString->-(void)logCallForMethod:(NSString*)aSelectorString andClass:(NSString*)aClass

Design a framework for an app to analyze it's running and act upon it

Context

  • Tutorial is often not enough to get an user to discover a feature
  • The problem is finding the time when a user is "ripe" to discover a feature (i.e. he now needs it).

Situation of the Problem

Example 1 : Finding Underused Features

Given a method doAwesomeFeature, we can define a duration t after which the user should be reminded that this feature might help him.
If the method is not used enough, we might define a threshold.
Framework method : [BCTrackedClass trackMethod:aMethod withTrackingMask:trackingMasj]

What about a NSMutableDictionnary-based approach ?

NSDictionary* trackingMask =
    @{
      @"trackingType"       :   [NSNumber numberWithInt:BCUnderusedMethod],
      @"reminderTime"       :   @60, //In s
      @"reminderThreshold"  :   @4
      };

Spamming of a given control - Finding inefficiencies

A method used too often in a given time is symptomatic os something wrong.

Example :

  • A poorly designed control (ex :scrolling size : if a control has to be called twice every time, why not double its effect ?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.